Skip to content
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

Move __pip-runner__ script into a module #11262

Merged
merged 3 commits into from
Jul 16, 2022

Conversation

pradyunsg
Copy link
Member

Follow up to #11257

@pradyunsg pradyunsg added type: enhancement Improvements to functionality skip news Does not need a NEWS file entry (eg: trivial changes) labels Jul 15, 2022
@pradyunsg pradyunsg force-pushed the reuse-environment-runner-sccript branch from a2d22a9 to fbf4bbb Compare July 15, 2022 10:10
This makes it possible to eliminate the need for writing a copy of this
script in a temporary directory for each isolated build environment.
@pradyunsg pradyunsg force-pushed the reuse-environment-runner-sccript branch from fbf4bbb to 5f2a858 Compare July 15, 2022 10:11
This makes it possible to only "replace" `pip` and have the submodules
get correctly located by the regular importlib machinery. This also
asserts that it was able to locate the module, ensuring that failure to
locate the module results in an exception.
@pradyunsg
Copy link
Member Author

pradyunsg commented Jul 15, 2022

Moving this out into a module helped me identify that we weren't correctly replacing the pip module in the runner script, which meant that the script wasn't using the correct pip copy! I'm not quite sure why our tests didn't catch that, and I'm looking at the test suite to figure out how to write a test for this.

I've changed the implementation, in this PR, to ensure that we replace that module correctly.


One nice property of moving this into a module, is that I can run it for testing things manually (and automatically)!

Before:

python -m pip --version
/Users/pradyunsg/Developer/github/pip/.venv/bin/python: No module named pippython src/pip/__pip-runner__.py install .   
Traceback (most recent call last):
  File "/Users/pradyunsg/Developer/github/pip/src/pip/__pip-runner__.py", line 37, in <module>
    runpy.run_module("pip", run_name="__main__")
  File "/Users/pradyunsg/.asdf/installs/python/3.10.1/lib/python3.10/runpy.py", line 205, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/Users/pradyunsg/.asdf/installs/python/3.10.1/lib/python3.10/runpy.py", line 140, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named pip

After:

python -m pip --version
/Users/pradyunsg/Developer/github/pip/.venv/bin/python: No module named pippython src/pip/__pip-runner__.py install .
Processing /Users/pradyunsg/Developer/github/pip
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pip
  Building wheel for pip (pyproject.toml) ... done
  Created wheel for pip: filename=pip-22.2.dev0-py3-none-any.whl size=2145280 sha256=9c06ef8f4a063b041160ed4e843e570c4564549754441d2502ff4c9cb348092f
  Stored in directory: /private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-ephem-wheel-cache-4ofpbybe/wheels/54/9f/74/29320177d01b5bd98b902e57e24b770257a633ca58c02b60f1
Successfully built pip
Installing collected packages: pip
Successfully installed pip-22.2.dev0python -m pip --version
pip 22.2.dev0 from /Users/pradyunsg/Developer/github/pip/.venv/lib/python3.10/site-packages/pip (python 3.10)

This ensures that the runner script can be used in environments where
pip is not installed.
@pradyunsg pradyunsg marked this pull request as ready for review July 15, 2022 11:24
@pradyunsg pradyunsg added this to the 22.2 milestone Jul 15, 2022
@sbidoul sbidoul merged commit 6d02fe2 into pypa:main Jul 16, 2022
@pradyunsg pradyunsg deleted the reuse-environment-runner-sccript branch July 16, 2022 19:53
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip news Does not need a NEWS file entry (eg: trivial changes) type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants