Skip to content

Conversation

@shivasurya
Copy link
Owner

The stdlib registry generation was failing for Python 3.9 because
sys.stdlib_module_names is only available in Python 3.10+.

This commit adds a fallback mechanism that uses pkgutil and sysconfig
to discover stdlib modules for Python 3.9. The fallback:

  • Collects built-in modules from sys.builtin_module_names
  • Discovers modules in stdlib path using pkgutil.iter_modules()
  • Discovers modules in platstdlib path for platform-specific modules

This allows the stdlib-r2-upload workflow to successfully generate
registries for all Python versions 3.9-3.14.

Fixes the RuntimeError: "sys.stdlib_module_names not available
(Python 3.10+ required)" that was blocking the R2 upload workflow.

The stdlib registry generation was failing for Python 3.9 because
sys.stdlib_module_names is only available in Python 3.10+.

This commit adds a fallback mechanism that uses pkgutil and sysconfig
to discover stdlib modules for Python 3.9. The fallback:
- Collects built-in modules from sys.builtin_module_names
- Discovers modules in stdlib path using pkgutil.iter_modules()
- Discovers modules in platstdlib path for platform-specific modules

This allows the stdlib-r2-upload workflow to successfully generate
registries for all Python versions 3.9-3.14.

Fixes the RuntimeError: "sys.stdlib_module_names not available
(Python 3.10+ required)" that was blocking the R2 upload workflow.
…d support

Enhanced the Python 3.9 fallback mechanism to be more comprehensive:

1. **lib-dynload / DLLs support**: Now discovers compiled extension modules
   from lib-dynload (Unix/Linux) and DLLs (Windows) directories. This fixes
   missing modules like sqlite3, ssl, _asyncio, etc.

2. **Error handling**: Added try-except blocks around pkgutil.iter_modules()
   calls to handle edge cases gracefully with warning messages.

3. **Documentation**: Added comprehensive docstring explaining the discovery
   strategy for both Python 3.10+ and 3.9 fallback.

4. **Cross-platform**: Works on Windows, Linux, and macOS by checking both
   lib-dynload and DLLs directories.

Before: 261 modules discovered (missing compiled extensions)
After: 306 modules discovered (includes all compiled extensions)

This ensures feature parity between Python 3.9 and 3.10+ for stdlib
registry generation.
…ibility

Code quality and maintainability improvements:

1. **Moved imports to module level**: pkgutil, sysconfig, and os are now
   imported at the top instead of inside functions, following PEP 8.

2. **Added Python version check**: Script now validates it's running on
   Python 3.9+ at startup and provides a clear error message if not.

3. **Enhanced documentation**: Added "Minimum Python version: 3.9" note
   in module docstring for clarity.

4. **Verbose detection method logging**: When --verbose is used with --all,
   the script now logs whether it's using sys.stdlib_module_names (3.10+)
   or the pkgutil fallback (3.9).

5. **Expanded platform-specific module list**: Added comprehensive list of
   Unix-specific (grp, pwd, resource, syslog, termios, tty), macOS-specific
   (_scproxy), and optional modules (readline, dbm, gdbm, ossaudiodev, spwd)
   to prevent false positives in unexpected failure detection.

These changes improve code maintainability and provide better debugging
information when the script runs across different Python versions (3.9-3.14)
and platforms (Windows, Linux, macOS).

No functional changes to the core module discovery logic.
@safedep
Copy link

safedep bot commented Jan 10, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.64%. Comparing base (f1e536c) to head (5a324bc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #464   +/-   ##
=======================================
  Coverage   81.64%   81.64%           
=======================================
  Files          94       94           
  Lines       10513    10513           
=======================================
  Hits         8583     8583           
  Misses       1615     1615           
  Partials      315      315           

☔ 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.

@shivasurya shivasurya merged commit 225bb8d into main Jan 10, 2026
5 checks passed
@shivasurya shivasurya deleted the claude/fix-stdlib-registry-python39-UlCSU branch January 10, 2026 15:29
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.

3 participants