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

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

Merged
merged 14 commits into from
Nov 26, 2024

Conversation

FFY00
Copy link
Member

@FFY00 FFY00 commented Nov 18, 2024

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

zooba commented Nov 18, 2024

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>
@FFY00 FFY00 requested a review from vsajip as a code owner November 19, 2024 00:07
Signed-off-by: Filipe Laíns <lains@riseup.net>
…initializations"

Signed-off-by: Filipe Laíns <lains@riseup.net>
@FFY00 FFY00 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 19, 2024
@bedevere-bot
Copy link

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

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 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
Member Author

FFY00 commented Nov 19, 2024

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

@FFY00 FFY00 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 19, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @FFY00 for commit 3c1fb29 🤖

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 19, 2024
@FFY00 FFY00 changed the title GH-126985: move pyconf.cfg detection from site to getpath GH-126985: move pyvenv.cfg detection from site to getpath Nov 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>
@FFY00 FFY00 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 19, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @FFY00 for commit 3c24f44 🤖

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 19, 2024
@FFY00
Copy link
Member Author

FFY00 commented Nov 22, 2024

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.995s
OK (skipped=3)
X
test_import leaked [52, 3, 51] references, sum=106
test_import leaked [33, 2, 32] memory blocks, sum=67
1 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 sec
15 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_wmi
4 tests skipped (resource denied):
    test_peg_generator test_tkinter test_ttk test_zipfile64
1 re-run test:
    test_import
1 test failed:
    test_import
460 tests OK.
Total duration: 21 min 38 sec
Total tests: run=45,618 skipped=1,894
Total test files: run=477/480 failed=1 skipped=15 resource_denied=4 rerun=1
Result: 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
Member Author

FFY00 commented Nov 22, 2024

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
Member Author

FFY00 commented Nov 22, 2024

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

@FFY00 FFY00 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 22, 2024
@bedevere-bot
Copy link

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

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 22, 2024
@FFY00
Copy link
Member Author

FFY00 commented Nov 23, 2024

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

@zooba zooba 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
Member Author

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.

Comment on lines +611 to +614
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)
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
Member Author

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.

Copy link
Member Author

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)
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
Member Author

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.

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 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.

@FFY00 FFY00 merged commit 2b0e2b2 into python:main Nov 26, 2024
115 of 118 checks passed
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.

5 participants