-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
GH-126985: move pyvenv.cfg detection from site to getpath #126987
Conversation
Signed-off-by: Filipe Laíns <lains@riseup.net>
The change looks reasonable to me, but I'm still terrified of changing anything at all in getpath 😆 Better to do it early in the release cycle though. |
…izations" This reverts commit acbd5c9. Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
…initializations" Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
I think the implementation is ready if the tests are passing on other platforms and buildbots. The documentation still needs to be updated though. |
`tmpdir` is a venv, so `prefix` will be set to that value, but `base_prefix` should stay `pyvenv_home`. Signed-off-by: Filipe Laíns <lains@riseup.net>
Alright, the results from the buildbots seem positive. There are 3 failures, but I think they're unrelated.
Example: https://buildbot.python.org/#/builders/474/builds/1754/steps/6/logs/stdio
Android: https://buildbot.python.org/#/builders/1593/builds/71/steps/8/logs/stdio
Example: https://buildbot.python.org/#/builders/577/builds/1691 |
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Filipe Laíns <lains@riseup.net>
This is now ready for review. @zooba would be able to have a look? |
Signed-off-by: Filipe Laíns <lains@riseup.net>
I am gonna sync with |
The 1) and 2) failures seem to be gone, leaving only the PEG Generator failures on Windows 10, which definitely seem unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% confident this will be smooth, but I don't think it can be made any better.
Let's keep an eye on whether the -S
behaviour needs to be brought back. I hope not, but it might be too much trouble.
now done during the :ref:`path initialization <sys-path-init>`. As a result, | ||
under :ref:`sys-path-init-virtual-environments`, :data:`sys.prefix` and | ||
:data:`sys.exec_prefix` no longer depend on the :mod:`site` initialization, | ||
and are therefore unaffected by :option:`-S`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to, we should be able to make them affected by the option again. This seems like the most likely change to impact people, so it's worth being aware of how we might cleanly roll it back without undoing all the work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this should be relatively easy, as PyConfig
already has a site_import
field, which we can use to check to change the behavior.
I think the specifics of a possible rollback would depend on the reported issues. I would like to still keep the new behavior long term, if there are any issues, I think we should consider rolling back with a deprecation period, but depending on how critical and in what way the new behavior is problematic, we may just want to roll back permanently.
if sys.prefix != site_prefix: | ||
_warn(f'Unexpected value in sys.prefix, expected {site_prefix}, got {sys.prefix}', RuntimeWarning) | ||
if sys.exec_prefix != site_prefix: | ||
_warn(f'Unexpected value in sys.exec_prefix, expected {site_prefix}, got {sys.exec_prefix}', RuntimeWarning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These warnings are also worth watching out for, though hopefully they only ever indicate actual problems.
If the values don't match, should we update them anyway like we used to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! We could run this through a deprecation period, setting the value for now and stopping in two versions, though, I think triggering these warnings likely highlights a bug in user code and giving how niche use-cases like these are, I am not sure if that's needed, and it's extra overhead on our part. I'm inclined to keep the code as-is, and if we see any issues during the pre-release phase, change to the deprecation approach before a final release.
@hugovk do you have any preference as the RM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference as RM.
You could have the warnings for one release, then based on feedback (if any!) decide if you want to deprecate/change behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with the warnings and re-evaluate based on feedback, then.
if not stdlib_dir and base_prefix: | ||
stdlib_dir = joinpath(base_prefix, STDLIB_SUBDIR) | ||
if not platstdlib_dir and base_exec_prefix: | ||
platstdlib_dir = joinpath(base_exec_prefix, PLATSTDLIB_LANDMARK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like all these changes! Makes the intent much clearer. The overall change it is worth it for these, IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and from playing with the getpath
, I believe a significant portion of the code could be simplified and better written to show intent by strictly adhering to the defined input/output parameters, as listed in https://docs.python.org/3/c-api/init_config.html#python-path-configuration. I found a lot of the complexity comes from taking into account non-input parameters, which as far as I can tell, is done to make writing the tests easier, by allowing them to overwrite certain parameters, mostly to get around file system checks. This feels wrong, and makes the getpath
extremely difficult to parse and understand what is supposed to be happening. It could be avoided by improving the test suite, maybe by making the helper functions operate on a mocked file system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a lot of the complexity comes from taking into account non-input parameters, which as far as I can tell, is done to make writing the tests easier, by allowing them to overwrite certain parameters, mostly to get around file system checks.
It's certainly intended to be a pure module, I'd hate to see "real" file system checks showing up in too many places. Those should be done first and passed in as data, or at least handled through the functions made available for executing getpath
(which are easily mocked out for tests).
But other than that, it basically follows the flow of the getpath.c
and getpathp.c
files that I translated to get here. So yeah, it's a mess, but only because they were a worse mess! With controlled input/output parameters and very controlled external state, it should be possible to safely refactor the whole thing now.
pyvenv.cfg
-relocation part of the interpreter initialization instead of thesite
module #126985