Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-126985: move pyvenv.cfg detection from site to getpath#126987

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FFY00 merged 14 commits intopython:mainfromFFY00:gh-126985
Nov 26, 2024

Conversation

@FFY00
Copy link
Member

@FFY00FFY00 commentedNov 18, 2024
edited by bedevere-appbot
Loading

zware reacted with thumbs up emoji
Signed-off-by: Filipe Laíns <lains@riseup.net>
@zooba
Copy link
Member

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.

zware reacted with thumbs up emoji

…izations"This reverts commitacbd5c9.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>
@FFY00FFY00 added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@FFY00 for commitfa3adba 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
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>
@FFY00
Copy link
MemberAuthor

I think the implementation is ready if the tests are passing on other platforms and buildbots. The documentation still needs to be updated though.

@FFY00FFY00 added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@FFY00 for commit3c1fb29 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
@FFY00FFY00 changed the titleGH-126985: move pyconf.cfg detection from site to getpathGH-126985: move pyvenv.cfg detection from site to getpathNov 19, 2024
`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>
@FFY00FFY00 added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@FFY00 for commit3c24f44 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 19, 2024
@FFY00
Copy link
MemberAuthor

Alright, the results from the buildbots seem positive. There are 3 failures, but I think they're unrelated.

  1. test_import leaks

Example:https://buildbot.python.org/#/builders/474/builds/1754/steps/6/logs/stdio

----------------------------------------------------------------------Ran 115 tests in 4.995sOK (skipped=3)Xtest_import leaked [52, 3, 51] references, sum=106test_import leaked [33, 2, 32] memory blocks, sum=671 test failed again:    test_import== Tests result: FAILURE then FAILURE ==10 slowest tests:- test_shelve: 8 min 5 sec- test.test_multiprocessing_spawn.test_processes: 7 min 9 sec- test.test_multiprocessing_forkserver.test_processes: 5 min 44 sec- test_socket: 5 min 24 sec- test.test_concurrent_futures.test_wait: 4 min 56 sec- test_tarfile: 4 min 41 sec- test_io: 4 min 26 sec- test.test_multiprocessing_spawn.test_misc: 4 min 19 sec- test_regrtest: 3 min 53 sec- test_zipfile: 3 min 42 sec15 tests skipped:    test.test_asyncio.test_windows_events    test.test_asyncio.test_windows_utils test_android test_devpoll    test_free_threading test_ioctl test_kqueue test_launcher    test_msvcrt test_startfile test_winapi test_winconsoleio    test_winreg test_winsound test_wmi4 tests skipped (resource denied):    test_peg_generator test_tkinter test_ttk test_zipfile641 re-run test:    test_import1 test failed:    test_import460 tests OK.Total duration: 21 min 38 secTotal tests: run=45,618 skipped=1,894Total test files: run=477/480 failed=1 skipped=15 resource_denied=4 rerun=1Result: FAILURE then FAILURE
  1. test_gc failures on Android and iOS

Android:https://buildbot.python.org/#/builders/1593/builds/71/steps/8/logs/stdio
iOS:https://buildbot.python.org/#/builders/1382/builds/180/steps/10/logs/stdio

  1. PEG Generator failures on Windows 10

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>
@FFY00
Copy link
MemberAuthor

This is now ready for review.@zooba would be able to have a look?

Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00
Copy link
MemberAuthor

I am gonna sync withmain and re-trigger the buildbots to see if any of the failures I saw before went away.

@FFY00FFY00 added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 22, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@FFY00 for commitcaf5984 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 22, 2024
@FFY00
Copy link
MemberAuthor

The 1) and 2) failures seem to be gone, leaving only the PEG Generator failures on Windows 10, which definitely seem unrelated.

Copy link
Member

@zoobazooba left a 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`.
Copy link
Member

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.

Copy link
MemberAuthor

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, asPyConfig already has asite_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.

Comment on lines +611 to +614
ifsys.prefix!=site_prefix:
_warn(f'Unexpected value in sys.prefix, expected{site_prefix}, got{sys.prefix}',RuntimeWarning)
ifsys.exec_prefix!=site_prefix:
_warn(f'Unexpected value in sys.exec_prefix, expected{site_prefix}, got{sys.exec_prefix}',RuntimeWarning)
Copy link
Member

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?

Copy link
MemberAuthor

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?

Copy link
Member

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.

FFY00 reacted with thumbs up emoji
Copy link
MemberAuthor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

This change makeshome a mandatory field inpyvenv.cfg I believe (mandatory in the sense that you will get a warning if it isn't set). There is no such constraint in PEP 405 (https://peps.python.org/pep-0405/).

I found this because I am digging into a different problem related to resolving executable symlinks when creating venvs (#106045).

IMO, the logic for determining what the path should be belongs in one place (getpath now) and this additional check that guarantees that thehome is exactlydirname(executable) is redundant and not necessarily a correct/standardised assumption.

Copy link
Member

Choose a reason for hiding this comment

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

Ifhome is absent, then we just can't launch Python. The PEP may not have realised just how impossible it is to launch Python when nobody will tell you where Python is installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The PEP may not have realised just how impossible it is to launch Python when nobody will tell you where Python is installed.

I guess you are talking about the case where you have a venv based on copy, not on symlinks? Because for the latter, I think we have all we need.

I'm glad that@FFY00 pointed me at#127895, as I findhome inpyvenv.cfg to be a strange choice which forces us to heuristics in order to (hopefully) find theactual executable.

This change makes home a mandatory field in pyvenv.cfg

I think this should be documented, as it may be something that people have designed around. For example, there is a comment ingetpath.py which states:

Currently, we don't consider the presence of a pyvenv.cfg file without a 'home' key to signify the existence of a virtual environment — we quietly ignore them.

This comment is now outdated (it isn't quiet 😂)

Copy link
Contributor

Choose a reason for hiding this comment

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

if home is absent, you can't launch python
venv based on symlinks

Yeah, like@pelson says, pyvenv.cfg having home wasn't actually necessary when symlinks were used. The logic would follow the symlink and treat that as home (or more specifically, use it as a potential candidate).

Dereferencing the symlink to find home seems pretty intentional? There's various calls to realpath() that inform later logic. Similarly the top-of-file comments describe this behavior (i.e. it was intentional prior to this change).

home key is now required; if its missing its not considered a venv

For rules_python, this becomes problematic because it creates a conundrum:

  • We can't write an absolute path and files are read-only after building an application.
  • The home keymust be an absolute path (if it's relative (and empty means ".", iirc), its relative to the current working directory, which could be anywhere)

The net effect is there isn't any content we can write to pyvenv.cfg that allows Python to find its home and recognize the venv.

groodt reacted with thumbs up emoji
ifnotstdlib_dirandbase_prefix:
stdlib_dir=joinpath(base_prefix,STDLIB_SUBDIR)
ifnotplatstdlib_dirandbase_exec_prefix:
platstdlib_dir=joinpath(base_exec_prefix,PLATSTDLIB_LANDMARK)
Copy link
Member

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.

Copy link
MemberAuthor

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 thegetpath, 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 inhttps://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 thegetpath 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.

Copy link
Member

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 executinggetpath (which are easily mocked out for tests).

But other than that, it basically follows the flow of thegetpath.c andgetpathp.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.

FFY00 reacted with heart emoji
@FFY00FFY00 merged commit2b0e2b2 intopython:mainNov 26, 2024
115 of 118 checks passed
Copy link
Contributor

@rickeylevrickeylev left a comment

Choose a reason for hiding this comment

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

Hi,

I'm a maintainer of Bazel's rules_python. I'm pretty sure the changes here broke the way we create venvs that are semi-relocatable (relocatable enough to bootstrap and find site-packages, after which we can fix things up ourselves). The particular behavior we rely on is having a pyvenv.cfgwithout home set, which lets Python find its home on its own.

I haven't figured out which particular part of this commit's changes does it, but from the discussion, its probably the requirement that home be set in pyvenv.cfg (It's not clear to me where the new logic does that, but I'll take the convo's word for it). I have a basic repro that fails at this commit, but works at the previous (to this file) commit. I'll file a bug to discuss further. I left a more descriptive comment in the meantime.

groodt and aignas reacted with thumbs up emoji
Comment on lines +611 to +614
ifsys.prefix!=site_prefix:
_warn(f'Unexpected value in sys.prefix, expected{site_prefix}, got{sys.prefix}',RuntimeWarning)
ifsys.exec_prefix!=site_prefix:
_warn(f'Unexpected value in sys.exec_prefix, expected{site_prefix}, got{sys.exec_prefix}',RuntimeWarning)
Copy link
Contributor

Choose a reason for hiding this comment

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

if home is absent, you can't launch python
venv based on symlinks

Yeah, like@pelson says, pyvenv.cfg having home wasn't actually necessary when symlinks were used. The logic would follow the symlink and treat that as home (or more specifically, use it as a potential candidate).

Dereferencing the symlink to find home seems pretty intentional? There's various calls to realpath() that inform later logic. Similarly the top-of-file comments describe this behavior (i.e. it was intentional prior to this change).

home key is now required; if its missing its not considered a venv

For rules_python, this becomes problematic because it creates a conundrum:

  • We can't write an absolute path and files are read-only after building an application.
  • The home keymust be an absolute path (if it's relative (and empty means ".", iirc), its relative to the current working directory, which could be anywhere)

The net effect is there isn't any content we can write to pyvenv.cfg that allows Python to find its home and recognize the venv.

groodt reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hugovkhugovkhugovk left review comments

@zoobazoobazooba approved these changes

@vsajipvsajipAwaiting requested review from vsajipvsajip is a code owner

+3 more reviewers

@pelsonpelsonpelson left review comments

@rickeylevrickeylevrickeylev left review comments

@pagentlepagentlepagentle approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@FFY00@zooba@bedevere-bot@pelson@hugovk@rickeylev@pagentle

[8]ページ先頭

©2009-2025 Movatter.jp