gh-148641: Implement PEP 829 - startup configuration files#149109
Merged
Conversation
It's okay to be missing, but if it's given it must be an expected version (i.e. currently, 1).
* Add _print_error() helper function for printing exceptions to sys.stderr. These are not hidden behind -v * `warnings` can be lazy imported. * Since the site.toml file is no longer proposed, rewrite how .pth and .start files are parsed and processed. * addpackage() -- which was never documented -- is deprecated; there are a few usages in the wild so we can't get rid of it, but it's generally unnecessary now, has different semantics. * Update tests
Documentation build overview
54 files changed ·
|
|
When you're done making the requested changes, leave the comment: |
* flush_pth_start() -> process_startup_files() * Move around some versionchanged and deprecated-removed sections * Add: kw-only arg `defer_processing_start_files` in several places to ensure that the reverse-engineered semantics of the undocumented functions are preserved.
Member
Author
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @brettcannon, @ncoghlan: please review the changes made to this pull request. |
Member
Author
|
I just saw this after resolving all the previous comments.
Please take a look at the updates I just pushed. I see what you’re suggesting, although that does seem like a larger change to make. See what you think of the current PR branch.
… On May 2, 2026, at 18:38, Alyssa Coghlan ***@***.***> wrote:
@ncoghlan commented on this pull request.
In Lib/site.py:
> if reset:
+ flush_pth_start()
Yeah, I didn't see a way to reliably infer the intent from the existing args, hence suggesting a new keyword arg.
That has the benefit of letting sitecustomize and usercustomize authors invoke similar batch processing behaviour.
The other way we could do it is instead of passing in a keyword boolean and updating global variables, we could instead define a StartupFiles helper class with the pending sets on each instance, and accept a pending_startup: StartupFiles | None parameter on each of the functions that modify the pending sets. Then actually running the startup files would be a StartupFiles.process instance method rather than a new module level function. (I only thought of that approach just now, otherwise I would have suggested it in my review comments)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Member
Author
|
Argh! Sorry for the typo in the review dismissal. GH doesn't actually autocomplete in that dialog and it can't be edited. Approval was received from @ncoghlan |
This was referenced May 10, 2026
gaborbernat
added a commit
to tox-dev/tox
that referenced
this pull request
May 12, 2026
Six tests in the local subprocess and parallel suites fail on the weekly Python 3.15 check (run [25667044284](https://github.com/tox-dev/tox/actions/runs/25667044284)) because every spawned interpreter prints a `KeyError` to stderr before user code runs, and the assertions compare stderr byte-for-byte. The noise originates in the legacy `*-nspkg.pth` files shipped by `PasteDeploy 3.1.0` and `repoze.lru 0.7`, both pulled in transitively by `devpi-server` → `pyramid`. Those pth files call `sys._getframe(1).f_locals['sitedir']`, which worked when `site.py` walked its own frame. PEP 829 (CPython [#149109](python/cpython#149109)) replaced that machinery with a deferred `_exec_imports()` that has no `sitedir` local, so every interpreter startup raises `KeyError: "local variable ''sitedir'' is not defined"`. The regression is tracked upstream in CPython [#149671](python/cpython#149671). This is genuinely an upstream problem: the proper fix lives either in CPython (restoring compatibility with legacy `.pth` hacks, or providing a migration path) or in `setuptools` (which still generates these pth files for `namespace_packages=` declarations even though `pkg_resources` was removed in 82.0.0). The `paste` and `repoze` namespaces would still resolve via PEP 420 without the `.pth` shim, so the affected packages could also drop `namespace_packages=` upstream. Until any of those land, this patch removes the offending pth files at conftest import — gated by the broken `f_locals['sitedir']` substring so unrelated namespace pth files are untouched, and wrapped in `contextlib.suppress(OSError)` to stay idempotent under `xdist` workers racing on the same file. Revert once the upstream fix is available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Documentation preview 📚: https://cpython-previews--149109.org.readthedocs.build/