python: Implement (and require) PEP 668#38601
Conversation
|
@spackbot fix style |
|
Let me see if I can fix that for you! |
|
I was able to run spack style --fix==> Running style checks on spack
selected: isort, black, flake8, mypy
==> Modified files
var/spack/repos/builtin/packages/py-pip/package.py
var/spack/repos/builtin/packages/python/package.py
==> Running isort checks
isort checks were clean
==> Running black checks
reformatted var/spack/repos/builtin/packages/python/package.py
All done! ✨ 🍰 ✨
1 file reformatted, 1 file left unchanged.
black checks were clean
==> Running flake8 checks
flake8 checks were clean
==> Running mypy checks
Success: no issues found in 577 source files
mypy checks were clean
==> spack style checks were clean
I've updated the branch with style fixes. |
|
Really like the idea, but don't want to deprecate any versions (I'm going to deprecate 3.7 tomorrow though). |
|
Is there any reason why not? I don't think there are any packages that would break or fail to concretize by updating a patch version... |
|
@tgamblin is concerned about environment reproducibility. We want people to be able to reproduce an installation years later. Of course, we're still deprecating and removing EOL versions, but that's only after 5 years since the release date, so that's not as bad. |
|
I could add a few choice words for @tgamblin about Spack and (lack of) reproducibility, but I'll hold off here to stay on topic. My understanding from the official packaging guide is that marking version(s) as
I'm not suggesting that these versions be removed in later versions and break reproducibility (4), but they should be discouraged in any new work due to the risks (1,2) and |
I mean, you didn’t — what are the choice words? Maybe start a separate issue? Happy to add more things to enable reproducibility, but as I think you know, we have many pans in the fire. You are always welcome to help improve stuff and we appreciate PRs like this one. |
|
FWIW, I’m fine with deprecating versions here, the real issue is whether this conflicts with @adamjstewart’s work. I leave that part up to him. |
There was a problem hiding this comment.
High-level: this looks fine to me and we should be supporting PEP 668.
However, there is a reason we allow you to install pip: so you can actually manage things with pip, both:
- in a
venv, and - in Spack environments, which are effectively
virtualenvs (for Python purposes, anyway), at least based on the way we copy thepythonexecutable into them.
This is particularly relevant if there is a package that's not yet in Spack. This PR effectively breaks support for that use case, and people do this -- especially b/c they usually own their Spack.
So I have some requests:
-
Add a note that you can create a spack environment to do this as well (you don't have to do this in a
venv). -
I am not sure how best to do this since we removed the
ignore=kwarg toprovides(), butEXTERNALLY-MANAGEDshould likely not be symlinked into a Spack environment, as the user could perfectly well usepipthere. Maybe we could add a post-link hook for envs to do that. -
Make a
+externally-managedvariant that defaults totruebut can be disabled by the user if they really wantpipto work. It would skip the creation of this file. -
Add some kind of note or link to your warning that at least points to guidance about the other solutions (as mentioned here):
- using
~externally-managed - using
--break-system-packagesor equivalentpipconfig - removing
EXTERNALLY-MANAGED
I don't think we should make this too prominent, as I think the preferred solutions are a
spackenv orvenv, but I think it's good to point to this stuff. - using
This PR is going to break a lot of users when first enabled, unless (I think) we do (2).
If it helps (not sure it really helps one way or another), we could make spack envs into proper venv's by adding a pyvenv.cfg (another newer python thing that eliminates the need for the interpreter copy trick we stole from virtualenv). I have played with this locally but have not committed a PR.
Thoughts?
|
Spack environments do not provide the same experience as a # spack env activate --temp && spack install --add python
# python -m ensurepip && pip3 install pre-commit
# pre-commit --version
pre-commit 3.3.3
# spack install --add cmake
# pre-commit --version
bash: /tmp/spack-d977jsnc/.spack-env/view/bin/pre-commit: No such file or directory
# python -m ensurepip && pip3 install pre-commit
# spack env view disable && spack env view enable
# pre-commit --version
bash: /tmp/spack-d977jsnc/.spack-env/view/bin/pre-commit: No such file or directoryBecause of this external and significant influence, Spack environments also need to be marked as I'm not super keen on I will extend the warning by referring to a more verbose description stored in a separate file, I'll |
|
Sounds mostly good, but:
They should not be marked this way. We can fix the issue but currently I even occasionally use
Please add the variant and default to |
@pradyunsg would be curious to hear what your thoughts are on this part -- what's the "right" way to implement PEP 668 for environments that do support Note that the |
|
While we're on the topic, PEP 668 defines a way to prevent pip from installing packages. But is there a way to prevent pip from uninstalling packages? Oftentimes when using pip I find that it uninstalls a Spack-installed package. The resulting environment works, but other Spack installs now break. This came up recently in #28282. |
|
Working backwards:
PEP 668 handles both,
There's not much helping that one. From Python's perspective the Spack install or environment is the system installation. So the name accurate in principle but not in Spack's larger context. 😞 The silver lining is that the
I'm pretty certain the answer here is "you don't." PEP 668 is for installations/environments that
👍
For full clarity, this change will make it so you you have to explicitly Spack does not interoperate with I believe breaking the current "silently works" semantics of |
Having an Honestly, I don't quite understand what the nuances/intent/goals are with the interoperability needs of Spack/Conda etc with pip, and what exactly the intended behaviours are. 😅 If you don't want people to use pip to uninstall files installed by Spack, you can remove the |
|
If I'm following along, it sounds like we want to add |
|
This pull request has been automatically marked as stale because it has not had |
|
This pull request was closed because it had no activity for 30 days after being marked stale. |
Even
--without-ensurepip, an insufficiently careful user can stillpython -m ensurepipand make the Python installation unusable for Spack purposes. Or at least give themselves a headache.This PR marks the installation as externally-managed using PEP 668, which prevents
pipfrom installing any packages in the base installation with the error (based loosely on the Debian sample text):The post-install
--testcode is extended to triple-check that thevenvandensurepipmodules are available, and thatpython -m ensurepipfails outside of a virtual environment as it should.PEP 668 support only appeared in Pip 23.0, so this PR also:
pythonversions 3.7.17, 3.8.17, 3.9.17, 3.10.11, 3.10.12, 3.11.3, 3.11.4,pythonversions not listed above (but including 3.11.3) since they ship Pip 22.x or older,py-pipversions before 23.0, andpythonto 3.10.12.