-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update script to Update stubs and run tests
Signed-off-by: GitHub <noreply@github.com>
- Loading branch information
Showing
2 changed files
with
11 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,157 +1,14 @@ | ||
param( | ||
$version = "latest", | ||
[string[]]$ports = @("esp32", "esp8266", "stm32", "rp2", "samd"), | ||
[switch]$do_docstubs = $False, | ||
[switch]$do_merge = $False, | ||
[switch]$do_build = $False | ||
) | ||
# Activate the venv | ||
|
||
$flatversion = $version.replace(".", "_") | ||
#Cascade the build steps | ||
if ($do_docstubs) { | ||
$do_merge = $True | ||
} | ||
if ($do_merge) { | ||
$do_build = $True | ||
} | ||
|
||
$snippetsroot = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$workplaceroot = Split-Path -Parent ($snippetsroot) | ||
$stubs_repo = join-path $workplaceroot "repos\micropython-stubs" | ||
|
||
$prior_cwd = Get-Location | ||
cd $workplaceroot | ||
|
||
echo "--------------------------------------------------------" | ||
echo "version: $version" | ||
echo "flatversion: $flatversion" | ||
echo "ports: $ports" | ||
|
||
if ($do_docstubs) { | ||
echo "--------------------------------------------------------" | ||
echo "get-docstubs $version" | ||
echo "--------------------------------------------------------" | ||
stubber switch $version | ||
stubber get-docstubs | ||
# update micropython-core from recent docstubs | ||
stubber enrich -s $stubs_repo\stubs\micropython-core -ds $stubs_repo\stubs\micropython-$flatversion-docstubs | ||
} | ||
./.venv/bin/activate.ps1 | ||
|
||
|
||
if ($do_merge ) { | ||
echo "--------------------------------------------------------" | ||
echo "merge $version" | ||
echo "--------------------------------------------------------" | ||
foreach ($port in $ports) { | ||
stubber merge --version $version --port $port | ||
} | ||
#first update the stubs (local ) do not push updates | ||
foreach ($version in @( "latest","v1.21.0", "v1.20.0", "v1.19.1" )) { | ||
stubber get-docstubs --version $version | ||
stubber get-frozen --version $version | ||
stubber merge --version $version --port auto --board auto | ||
stubber build --version $version --port auto --board auto | ||
} | ||
|
||
if ($do_build) { | ||
echo "--------------------------------------------------------" | ||
echo "build" | ||
echo "--------------------------------------------------------" | ||
|
||
foreach ($port in $ports) { | ||
stubber build --version $version --port $port | ||
} | ||
# stubber build --version $version --port rp2 --board pico_w | ||
# stubber publish --test-pypi --version $version --port auto --board um_tinypico --dry-run | ||
} | ||
|
||
|
||
# first install the typestubs to a local folder so they can be copied from there to save time | ||
|
||
foreach ($port in $ports) { | ||
|
||
$stub_source = "$stubs_repo\publish\micropython-$flatversion-$port-stubs" | ||
$typings_cache_dir = "$workplaceroot\snippets\typings_$port" | ||
echo "--------------------------------------------------------" | ||
echo "port: $port" | ||
echo "type cache : $typings_cache_dir" | ||
echo "--------------------------------------------------------" | ||
|
||
rd $typings_cache_dir -r -ea silentlycontinue | ||
# pip install including pre-releases to get the latest stdlib version | ||
pip install -I $stub_source --target $typings_cache_dir --no-user --pre | ||
} | ||
|
||
# create a hashtable with feates as a key, and the orts that support it as a lisy | ||
$features = @{ | ||
"networking" = @("esp32", "esp8266", "rp2-pico-w") | ||
"bluetooth" = @("esp32") | ||
} | ||
|
||
$results = @() | ||
foreach ($port in $ports) { | ||
$stub_source = "$workplaceroot\repos\micropython-stubs\publish\micropython-$flatversion-$port-stubs" | ||
$typings_cache_dir = "$workplaceroot\snippets\typings_$port" | ||
|
||
if (-not (Test-Path $typings_cache_dir)) { | ||
Write-Warning "The directory '$typings_cache_dir' does not exist." | ||
continue | ||
} | ||
|
||
foreach ($folder in @($port, "stdlib", "micropython", "networking", "bluetooth")) { | ||
if ($features.Contains($folder)) { | ||
if ($port -notin $features[$folder]) { | ||
# do not check features on ports that do not support it | ||
# TODO: add boards such as the rp2 pico-W that do support it | ||
continue | ||
} | ||
} | ||
if ($folder.startswith($port)) { | ||
$snippets_dir = "$workplaceroot\snippets\check_$folder" | ||
} | ||
else { | ||
$snippets_dir = "$workplaceroot\snippets\feat_$folder" | ||
} | ||
$typings_dir = "$snippets_dir\typings" | ||
echo "--------------------------------------------------------" | ||
echo "port: $port " | ||
echo "folder: $folder" | ||
echo "snippets_dir: $snippets_dir" | ||
echo "--------------------------------------------------------" | ||
if (-not (test-path $snippets_dir)) { | ||
Write-Warning "The directory '$snippets_dir' does not exist." | ||
continue | ||
} | ||
|
||
|
||
rd $typings_dir -r -ea silentlycontinue | ||
# copy typings from the cache to the snippets folder | ||
Copy-Item $typings_cache_dir $typings_dir -Recurse -Force | ||
|
||
# run pyright | ||
$result = pyright --project $snippets_dir --outputjson | convertfrom-json | ||
# add $port attribute to result | ||
Add-Member -InputObject $result.summary -MemberType NoteProperty -Name port -Value $port | ||
Add-Member -InputObject $result.summary -MemberType NoteProperty -Name folder -Value $folder | ||
|
||
foreach ($diag in $result.generalDiagnostics) { | ||
add-member -InputObject $diag -MemberType NoteProperty -Name port -Value $port | ||
add-member -InputObject $diag -MemberType NoteProperty -Name folder -Value $folder | ||
} | ||
$results += $result | ||
$result.generalDiagnostics | select port, folder, severity, rule, file, message | ft -Wrap | out-host | ||
} | ||
} | ||
# resore working directory | ||
cd $prior_cwd | ||
|
||
$problems = $results | select -expand generalDiagnostics | ? { $_.severity -eq "error" } | ||
# Write results to file | ||
$problems | Export-Csv -Path $snippetsroot\results.csv -NoTypeInformation | ||
# And to .json | ||
$results | ConvertTo-Json -Depth 10 | Out-File $snippetsroot\results.json -Force | ||
|
||
echo "========================================================" | ||
if ( $problems.length -eq 0) { | ||
echo "SUCCESS - No errors found" | ||
} | ||
else { | ||
$problems | select port, folder, severity, rule, file, message | ft -Wrap | out-host | ||
exit(1) | ||
} | ||
echo "========================================================" | ||
|
||
#then run the test | ||
pytest -m 'snippets' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters