Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

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

  • Explore repository structure and understand existing command patterns
  • Install dependencies and validate current tests pass
  • Review external build.py script from micropython-stubs repo
  • Create new command file stdlib_stubs_cmd.py in src/stubber/commands/
  • Integrate the stdlib-stubs building logic into the new command
  • Register the new command in src/stubber/stubber.py
  • Add comprehensive tests (17 test cases, all passing)
  • Validate the command works end-to-end
  • Documentation (auto-generated via sphinx-click)
  • Changed command name from stdlib-stubs to stdlib
  • Changed --typeshed option to --update
  • Added comprehensive unit tests - 82% code coverage
  • Moved typeshed cloning to clone command with --typeshed option
  • Formatted all code with ruff
  • 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_path config property (defaults to "typeshed" in repos folder)
  • Added to repos property list for consistency

Key Features:

  1. Clone typeshed using: stubber clone --typeshed
  2. Updates stdlib from typeshed repository
  3. Updates manual _mpy_shed and asyncio stubs from reference folder
  4. Merges MicroPython documentation stubs into stdlib
  5. Post-processes stubs (formatting, autoflake)
  6. Adds type ignore comments to reduce typechecker noise
  7. Comments out CPython-specific APIs not available in MicroPython
  8. Modifies lines to hide incompatible CPython APIs
  9. Builds wheel package with uv
  10. 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)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate build stdlib-stubs script into micropython stubber. Integrate stdlib-stubs build script as stubber command Nov 3, 2025
Copilot AI requested a review from Josverl November 3, 2025 14:13
Copilot finished work on behalf of Josverl November 3, 2025 14:13
@Josverl
Copy link
Owner

Josverl commented Nov 3, 2025

@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

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 3, 2025

@copilot ,

Please change the command from stubber stdlib-stubs to stubber stdlib...

Changed command name from stubber stdlib-stubs to stubber stdlib and fully implemented the --clone option.

The --clone option now:

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

Copilot finished work on behalf of Josverl November 3, 2025 17:01
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 76.41509% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.07%. Comparing base (145cfab) to head (4f1f2d6).

Files with missing lines Patch % Lines
src/stubber/commands/stdlib_stubs_cmd.py 76.30% 31 Missing and 19 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #697      +/-   ##
==========================================
- Coverage   79.11%   79.07%   -0.04%     
==========================================
  Files          70       71       +1     
  Lines        6656     6868     +212     
  Branches     1111     1157      +46     
==========================================
+ Hits         5266     5431     +165     
- Misses       1031     1060      +29     
- Partials      359      377      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Josverl
Copy link
Owner

Josverl commented Nov 3, 2025

@copilot

Please change the option typeshed to update.

@Josverl
Copy link
Owner

Josverl commented Nov 3, 2025

@copilot , also the test coverage of the new functionality is to low, it should be about 80%

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 3, 2025

@copilot

Please change the option typeshed to update.

Changed option from --typeshed to --update.

Changes in commit 6e9c07b:

  • Renamed --typeshed/--no-typeshed to --update/--no-update
  • Changed short option from -t to -u
  • Updated all tests and documentation
  • All 27 commandline tests passing

Copilot finished work on behalf of Josverl November 3, 2025 17:51
Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 3, 2025

@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 finished work on behalf of Josverl November 3, 2025 17:58
@Josverl Josverl marked this pull request as ready for review November 3, 2025 18:45
if not rootpath.exists():
raise click.ClickException(f"Root path {rootpath} does not exist")

if clone:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the clone option should be moved to the existing clone command with the option --typeshed or similar.
That will make it simpler to discover.
Also the location should be under the repo folder, likely the config needs to be adjusted to include it.
Then the path does not need to be specified separately.
Just a check if the typeshed repo has been cloned to the correct commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved clone functionality to the existing clone command with --typeshed option.

Changes in commit 348678d:

  • Added typeshed_path to CONFIG (defaults to "typeshed" in repos folder)
  • Added --typeshed flag to stubber clone command
  • Removed --clone option from stdlib command
  • Updated stdlib to use CONFIG.repo_path / CONFIG.typeshed_path
  • Error messages now direct users to: stubber clone --typeshed
  • All 39 commandline tests passing
  • Coverage maintained at 82%

Usage:

# Clone typeshed first
stubber clone --typeshed

# Then build stdlib
stubber stdlib --update --build

The typeshed repository is now managed consistently with other repos (micropython, micropython-lib) through the central clone command, making it easier to discover.

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copilot AI requested a review from Josverl November 10, 2025 23:35
Copilot finished work on behalf of Josverl November 10, 2025 23:35
@Josverl
Copy link
Owner

Josverl commented Nov 10, 2025

@copilot

  • format all code with ruff
  • run all test with coverage
  • make sure all new code is covered 80%

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 10, 2025

@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 Union import from config.py
    • Removed unused variables m_dir and m_tag from test files
  • 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

Copilot finished work on behalf of Josverl November 10, 2025 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate build stdlib-stubs script into micropython stubber.

2 participants