Skip to content

Udpate ensurepip from CPython 3.13.2 #5740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Apr 24, 2025

Summary by CodeRabbit

  • Refactor

    • Simplified the pip bootstrapping process by focusing solely on pip, removing support for multiple packages.
    • Updated internal logic to use modern path handling and context managers for locating the pip wheel file.
    • Increased the bundled pip version to 25.1.1.
  • Tests

    • Updated tests to use new path handling and context manager logic.
    • Improved test coverage for wheel file selection and version extraction.

@arihant2math
Copy link
Collaborator

Need #5590 first from what it seems

@fanninpm
Copy link
Contributor

fanninpm commented May 1, 2025

Need #5590 first from what it seems

Now that #5590 is merged, is it possible to move forward with this?

@arihant2math
Copy link
Collaborator

Well typing is now broken in new and interesting ways :)
The contents of typing_extensions should be a extra test at this rate to prevent regressions.

@arihant2math
Copy link
Collaborator

arihant2math commented May 1, 2025

The error is a typing_extensions bug:
python/typing_extensions#404

Copy link

coderabbitai bot commented Jun 15, 2025

Walkthrough

The ensurepip module was refactored to streamline pip bootstrapping by focusing exclusively on pip, removing multi-package support and simplifying wheel discovery. The new implementation uses pathlib.Path for wheel directory handling, introduces context managers for locating the pip wheel, and updates tests to match the new logic and data structures.

Changes

File(s) Change Summary
Lib/ensurepip/init.py Refactored to remove multi-package logic, added context managers for pip wheel discovery, updated pip version, and simplified bootstrapping and uninstall logic.
Lib/test/test_ensurepip.py Updated tests to use pathlib.Path, replaced removed logic with tests for new context managers, and corrected comments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ensurepip
    participant SystemWheelDir
    participant BundledResource

    User->>ensurepip: _bootstrap()
    ensurepip->>SystemWheelDir: _find_wheel_pkg_dir_pip()
    alt pip wheel found in system dir
        SystemWheelDir-->>ensurepip: Return pip wheel path context
    else pip wheel not found
        ensurepip->>BundledResource: Use bundled pip wheel path context
    end
    ensurepip->>ensurepip: Copy pip wheel to temp dir
    ensurepip->>ensurepip: _run_pip("pip", [copied_wheel_path])
Loading

Poem

In the warren of wheels, one pip stands tall,
No more searching for packages, just one to install.
With pathlib and context, the code is now neat,
Simpler and swifter, a bunny’s small feat.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
Lib/test/test_ensurepip.py (1)

9-9: Remove unused import.

The Traversable import is not used anywhere in this test file.

-from importlib.resources.abc import Traversable
 from pathlib import Path
Lib/ensurepip/__init__.py (1)

53-61: Consider more robust version extraction.

While the current string manipulation works for the standard wheel naming convention, consider using a more robust approach to handle edge cases.

 def _get_pip_version():
     with _get_pip_whl_path_ctx() as bundled_wheel_path:
         wheel_name = bundled_wheel_path.name
-        return (
-            # Extract '21.2.4' from 'pip-21.2.4-py3-none-any.whl'
-            wheel_name.
-            removeprefix('pip-').
-            partition('-')[0]
-        )
+        # Extract version from wheel filename: pip-{version}-py3-none-any.whl
+        if wheel_name.startswith('pip-') and wheel_name.endswith('.whl'):
+            # Remove prefix and suffix, then split on '-'
+            name_parts = wheel_name[4:-4].split('-', 1)
+            if name_parts:
+                return name_parts[0]
+        # Fallback to the bundled version if parsing fails
+        return _PIP_VERSION
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e094ea and a542757.

📒 Files selected for processing (2)
  • Lib/ensurepip/__init__.py (5 hunks)
  • Lib/test/test_ensurepip.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Lib/test/test_ensurepip.py (2)
Lib/importlib/resources/abc.py (1)
  • Traversable (63-150)
Lib/ensurepip/__init__.py (2)
  • version (90-94)
  • _get_pip_whl_path_ctx (41-50)
Lib/ensurepip/__init__.py (3)
Lib/contextlib.py (1)
  • nullcontext (761-785)
Lib/shutil.py (1)
  • copy2 (441-479)
Lib/importlib/resources/_common.py (1)
  • as_file (162-167)
🪛 Pylint (3.3.7)
Lib/ensurepip/__init__.py

[error] 19-19: Module 'sysconfig' has no 'get_config_var' member

(E1101)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Run tests under miri
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Ensure compilation on various targets
🔇 Additional comments (9)
Lib/test/test_ensurepip.py (4)

25-25: LGTM!

Correctly updated to patch with a Path object, aligning with the main module's type change.


28-38: Good test coverage for the no-directory case.

These new tests properly verify the fallback behavior when _WHEEL_PKG_DIR is None, ensuring the bundled pip wheel is used.


40-53: Well-structured test for wheel selection.

The test properly verifies that _get_pip_whl_path_ctx() selects only the pip wheel file from the directory, correctly ignoring other wheels and non-wheel files.


68-69: Comment accurately updated.

The comment now correctly references _find_wheel_pkg_dir_pip() instead of the old function name.

Lib/ensurepip/__init__.py (5)

6-9: LGTM!

All new imports are appropriately used in the refactored code.


13-13: Pip version updated as intended.

The update to pip 25.1.1 aligns with the PR objective of updating from CPython 3.13.2.


19-22: Clean handling of optional wheel directory.

The code properly converts the config variable to a resolved Path object when present, or None otherwise. The static analysis warning about get_config_var is a false positive.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 19-19: Module 'sysconfig' has no 'get_config_var' member

(E1101)


156-172: Clean refactoring of the bootstrap logic.

The simplified approach focusing solely on pip makes the code more maintainable. Good use of context managers and proper file copying with metadata preservation.


203-203: Consistent with single-package approach.

The change correctly reflects the module's focus on pip only.

@youknowone
Copy link
Member Author

pypa/pip#13428

@youknowone
Copy link
Member Author

  File "/tmp/tmp3a6kinnx/pip-25.1.1-py3-none-any.whl/pip/_vendor/typing_extensions.py", line 1768, in __new__

This is weird. We have typing.ParamSpec but it hits the else block

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