Skip to content

fix: disable use of pip install --python for debundled pip#861

Merged
henryiii merged 5 commits intopypa:mainfrom
mgorny:gentoo-pip
Feb 21, 2025
Merged

fix: disable use of pip install --python for debundled pip#861
henryiii merged 5 commits intopypa:mainfrom
mgorny:gentoo-pip

Conversation

@mgorny
Copy link
Contributor

@mgorny mgorny commented Feb 15, 2025

In the debundled pip version distributed on Gentoo systems, pip install --python is nonfunctional since it expects all of pip's dependencies to be present in the (empty) virtual environment. Detect this case by the removal of pip._vendor package, and use the "no valid outer pip" codepath.

Bug: https://bugs.gentoo.org/934922

@mgorny
Copy link
Contributor Author

mgorny commented Feb 15, 2025

Looks like distutils import hack from setuptools is causing trouble here. Any suggestion how to deal with that?

@henryiii
Copy link
Contributor

I don't think this will fix it, but I'd not do import if you aren't going to use it later; use importlib.util.find_spec("pip._vendor") instead, it's much faster. To me, isn't it a bit broken if pip install --python can't be used? You can target a completely empty environment with pip install --python normally.

@mgorny
Copy link
Contributor Author

mgorny commented Feb 18, 2025

Yes, it is. Unfortunately, I don't see how to fix it — in the end, the --python is a huge hack, and we find unbundling dependencies more important than, well, an option that we didn't even knew existed before build started using it.

@mgorny
Copy link
Contributor Author

mgorny commented Feb 18, 2025

I think the remaining failures are flaky tests.

@henryiii
Copy link
Contributor

What's the warning, out of curiosity?

@mgorny
Copy link
Contributor Author

mgorny commented Feb 18, 2025

What's the warning, out of curiosity?

Basically this:

>>> import distutils
>>> import pip
/usr/lib/python3.10/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml
  warnings.warn(

@henryiii
Copy link
Contributor

henryiii commented Feb 18, 2025

the --python is a huge hack

Pip is full of hacks - the build-isolation support is a mess, for example. IMO using --python instead of installing pip into every single environment is much more reasonable, and the main reason people don't use it is because it's a newer feature and it's not the way we used to work. uv always works this way, and it makes more sense.

Regardless, though, this seems fine.

I'll try to fix the univeral= warning soon.

mgorny and others added 5 commits February 18, 2025 11:23
In the debundled pip version distributed on Gentoo systems, `pip install
--python` is nonfunctional since it expects all of pip's dependencies
to be present in the (empty) virtual environment.  Detect this case
by the removal of `pip._vendor` package, and use the "no valid outer
pip" codepath.

Bug: https://bugs.gentoo.org/934922
@mgorny
Copy link
Contributor Author

mgorny commented Feb 19, 2025

Thanks!

@henryiii henryiii changed the title Disable use of pip install --python on Gentoo debundled pip fix: disable use of pip install --python for debundled pip Feb 19, 2025
@henryiii henryiii merged commit 35d86b8 into pypa:main Feb 21, 2025
64 checks passed
mgorny added a commit to mgorny/build that referenced this pull request May 21, 2025
Fix the exception raised if `pip` is not installed at all:

```
[...]
  File "/usr/lib/python3.14/site-packages/build/env.py", line 168, in _has_valid_outer_pip
    if importlib.util.find_spec('pip._vendor') is None:
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 90, in find_spec
ModuleNotFoundError: No module named 'pip'
```

This is a regression from pypa#861 where I did not predict that
`find_spec()` will actually raise when the parent package
is not available. To fix it, just reorder the conditions to make sure
that `pip` is installed first.
henryiii pushed a commit to mgorny/build that referenced this pull request May 21, 2025
Fix the exception raised if `pip` is not installed at all:

```
[...]
  File "/usr/lib/python3.14/site-packages/build/env.py", line 168, in _has_valid_outer_pip
    if importlib.util.find_spec('pip._vendor') is None:
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 90, in find_spec
ModuleNotFoundError: No module named 'pip'
```

This is a regression from pypa#861 where I did not predict that
`find_spec()` will actually raise when the parent package
is not available. To fix it, just reorder the conditions to make sure
that `pip` is installed first.
henryiii added a commit that referenced this pull request May 21, 2025
* fix: Fix `ModuleNotFoundError` when `pip` is not installed

Fix the exception raised if `pip` is not installed at all:

```
[...]
  File "/usr/lib/python3.14/site-packages/build/env.py", line 168, in _has_valid_outer_pip
    if importlib.util.find_spec('pip._vendor') is None:
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 90, in find_spec
ModuleNotFoundError: No module named 'pip'
```

This is a regression from #861 where I did not predict that
`find_spec()` will actually raise when the parent package
is not available. To fix it, just reorder the conditions to make sure
that `pip` is installed first.

* Update src/build/env.py

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
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.

2 participants