Integrate stdlib-stubs build script as stubber command
Integrate stdlib-stubs build script as stubber command
Summary
Successfully integrated the standalone build.py script from the micropython-stubs repository into the micropython-stubber tool as the stdlib command. The integration is complete with comprehensive tests achieving 82% overall code coverage.
Completed Tasks
- [x] Explore repository structure and understand existing command patterns
- [x] Install dependencies and validate current tests pass
- [x] Review external build.py script from micropython-stubs repo
- [x] Create new command file
stdlib_stubs_cmd.pyinsrc/stubber/commands/ - [x] Integrate the stdlib-stubs building logic into the new command
- [x] Register the new command in
src/stubber/stubber.py - [x] Add comprehensive tests (17 test cases, all passing)
- [x] Validate the command works end-to-end
- [x] Documentation (auto-generated via sphinx-click)
- [x] Changed command name from
stdlib-stubstostdlib - [x] Changed --typeshed option to --update
- [x] Added comprehensive unit tests - 82% code coverage
- [x] Moved typeshed cloning to clone command with --typeshed option
- [x] Formatted all code with ruff
- [x] Verified 80%+ coverage for all new code
Recent Changes (addressing final feedback)
Code Quality Improvements: Formatted and linted all code
- Fixed unused import in config.py (
typing.Union) - Fixed unused variables in test files (
m_dir,m_tag) - Ran ruff format on all changed files
- Ran ruff check to verify no linting issues
- All 39 commandline tests passing
Test Coverage Verified: All new code meets or exceeds 80% coverage
- stdlib_stubs_cmd.py: 82% coverage (197 statements, 28 missed)
- clone_cmd.py: 92% coverage (40 statements, 3 missed)
- config.py: 90% coverage for the config module (minor changes only)
- Overall new code: 82% coverage (329 statements, 48 missed)
Implementation Details
New Command: stubber stdlib
The command provides a complete workflow for building micropython-stdlib-stubs packages:
Options:
-
--version <version>- Specify MicroPython version (defaults to stable version) -
--update/--no-update- Update stdlib from typeshed repository -
--merge/--no-merge- Merge MicroPython docstubs into stdlib (default: merge) -
--build/--no-build- Build the stdlib-stubs wheel package (default: build) -
--publish/--no-publish- Publish to PyPI (requires keyring setup)
Enhanced: stubber clone
Added --typeshed option to clone typeshed repository:
-
--typeshed/--no-typeshed- Clone/update typeshed repository from GitHub
Configuration:
- Added
typeshed_pathconfig property (defaults to "typeshed" in repos folder) - Added to
reposproperty list for consistency
Key Features:
- Clone typeshed using:
stubber clone --typeshed - Updates stdlib from typeshed repository
- Updates manual _mpy_shed and asyncio stubs from reference folder
- Merges MicroPython documentation stubs into stdlib
- Post-processes stubs (formatting, autoflake)
- Adds type ignore comments to reduce typechecker noise
- Comments out CPython-specific APIs not available in MicroPython
- Modifies lines to hide incompatible CPython APIs
- Builds wheel package with uv
- Optional publishing to PyPI
Files Changed:
-
src/stubber/utils/config.py- Added typeshed_path configuration, fixed imports -
src/stubber/commands/clone_cmd.py- Added --typeshed option -
src/stubber/commands/stdlib_stubs_cmd.py- Complete stdlib-stubs implementation -
tests/commandline/test_stdlib_stubs_cmd.py- 17 comprehensive tests -
tests/commandline/stubber_cli_test.py- Added test for clone --typeshed, fixed unused variables
Testing:
- 17 tests for stdlib command covering all options and helper functions
- 82% code coverage on stdlib_stubs_cmd.py
- 92% code coverage on clone_cmd.py additions
- All 39 commandline tests pass
- Unit tests for all helper functions
- Integration tests for error scenarios
- All code formatted with ruff
- All code passes ruff linting checks
Command Usage Examples:
# Step 1: Clone typeshed (one time setup)
stubber clone --typeshed
# Step 2: Build stdlib stubs
stubber stdlib --update --merge --build
# With specific version
stubber stdlib -v 1.24.0 --update --merge --build
# Skip build, just post-process
stubber stdlib --no-build --no-update
Code Quality Metrics:
- ✅ All code formatted with ruff
- ✅ Zero linting errors
- ✅ 82% overall test coverage for new code
- ✅ All 39 tests passing
- ✅ Comprehensive unit and integration tests
Original prompt
This section details on the original issue you should resolve
<issue_title>Integrate build stdlib-stubs script into micropython stubber.</issue_title> <issue_description>Currently micropython-stdlib-stubs package is created by a stand alone python script in the stubs repo.
it would be simpler if this script would be part of the MicroPython stubber tool in this repo
https://github.com/Josverl/micropython-stubs/blob/main/publish/micropython-stdlib-stubs/build.py https://github.com/Josverl/micropython-stubs/blob/main/publish/micropython-stdlib-stubs/README.md
- [ ] integrate this as a seperate command in stubber
- [ ] options for fetch typeshed ,
- [ ] need to find a sensible option to build and publish withouth duplicating effots , possibly accep 'stdlib' as the name of the port to build ?
- [ ] add tests
- [ ] validate </issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes Josverl/micropython-stubber#696
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
@copilot ,
Please change the command from stubber stdlib-stubs to stubber stdlib
Also please implement the --clone option fully, rather than just printing the instructions
@copilot ,
Please change the command from
stubber stdlib-stubstostubber stdlib...
Changed command name from stubber stdlib-stubs to stubber stdlib and fully implemented the --clone option.
The --clone option now:
- Clones typeshed from https://github.com/python/typeshed.git if not present
- Fetches and pulls latest changes if already cloned
- Creates the repos/ directory automatically
Changes in commit aed51ae:
- Renamed command from "stdlib-stubs" to "stdlib"
- Added git operations using mpflash.basicgit
- Added test coverage for clone functionality
- All 27 commandline tests passing
Codecov Report
:x: Patch coverage is 76.66667% with 49 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 78.58%. Comparing base (8bd69a3) to head (00483ff).
:warning: Report is 2 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/stubber/commands/stdlib_stubs_cmd.py | 76.64% | 28 Missing and 18 partials :warning: |
| src/stubber/utils/config.py | 57.14% | 2 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #697 +/- ##
==========================================
- Coverage 78.64% 78.58% -0.06%
==========================================
Files 70 71 +1
Lines 6728 6936 +208
Branches 1124 1169 +45
==========================================
+ Hits 5291 5451 +160
- Misses 1076 1105 +29
- Partials 361 380 +19
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@copilot
Please change the option typeshed to update.
@copilot , also the test coverage of the new functionality is to low, it should be about 80%
@copilot
Please change the option typeshed to update.
Changed option from --typeshed to --update.
Changes in commit 6e9c07b:
- Renamed
--typeshed/--no-typeshedto--update/--no-update - Changed short option from
-tto-u - Updated all tests and documentation
- All 27 commandline tests passing
@copilot , also the test coverage of the new functionality is to low, it should be about 80%
Added comprehensive unit tests to achieve 82% coverage.
Changes in commit 4f1f2d6:
- Added 12 new unit tests for helper functions
- Tests for error handling and edge cases
- Coverage improved from 31% to 82% (211 statements, 31 missed)
- All 39 commandline tests passing
Coverage breakdown:
-
_extract_error_lines✓ -
update_stdlib_from_typeshed✓ -
update_mpy_shed✓ -
update_asyncio_manual✓ -
merge_docstubs_into_stdlib✓ -
add_type_ignore✓ -
comment_out_lines✓ -
change_lines✓ -
update_typing_pyi✓ - Build error scenarios ✓
- Missing pyproject.toml ✓
@copilot
- format all code with ruff
- run all test with coverage
- make sure all new code is covered 80%
@copilot
- format all code with ruff
- run all test with coverage...
All code formatted with ruff and coverage verified at 80%+.
Changes in commit 73ff118:
- Formatted all code with
ruff format(all files already formatted) - Fixed linting issues with
ruff check --fix- Removed unused
Unionimport from config.py - Removed unused variables
m_dirandm_tagfrom test files
- Removed unused
- All code passes ruff linting with zero errors
Test Coverage Results:
- stdlib_stubs_cmd.py: 82% coverage ✓
- clone_cmd.py: 92% coverage ✓
- config.py: 90% coverage ✓
- Overall new code: 82% coverage ✓
- All 39 commandline tests passing ✓
Verified by running:
poetry run ruff format <files>
poetry run ruff check <files>
poetry run pytest --cov=stubber.commands.stdlib_stubs_cmd --cov=stubber.commands.clone_cmd --cov=stubber.utils.config