Skip to content

Drop legacy pkg_resources namespace, use PEP 420#52

Open
gaborbernat wants to merge 1 commit into
Pylons:mainfrom
gaborbernat:drop-legacy-namespace-packages
Open

Drop legacy pkg_resources namespace, use PEP 420#52
gaborbernat wants to merge 1 commit into
Pylons:mainfrom
gaborbernat:drop-legacy-namespace-packages

Conversation

@gaborbernat
Copy link
Copy Markdown

@gaborbernat gaborbernat commented May 11, 2026

PasteDeploy declares the paste namespace with setuptools' namespace_packages= and a pkg_resources.declare_namespace() shim in src/paste/__init__.py. As a side effect, every wheel ships a PasteDeploy-*-nspkg.pth that contains:

p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('paste',))

Python 3.15 implements PEP 829 (CPython #149109) and rewrote site.py so that .pth import lines run inside a deferred _exec_imports() whose frame has no sitedir local. The lookup raises KeyError: "local variable ''sitedir'' is not defined" on every Python startup — tracked in CPython #149671. The error is printed to stderr before user code runs, which breaks downstream tests that compare subprocess stderr byte-for-byte (e.g. tox-dev/tox #3937, which currently strips the broken pth file at conftest time as a workaround).

This PR drops the legacy declaration in favour of PEP 420 implicit namespace packages:

  • Removes namespace_packages = paste from setup.cfg.
  • Deletes src/paste/__init__.py so paste becomes an implicit namespace.
  • Adds a news entry.

Setuptools no longer emits an nspkg.pth when namespace_packages= is absent, sibling distributions in the paste.* namespace continue to resolve via PEP 420, and PasteDeploy already requires Python 3.7+ where PEP 420 has been universally available since 3.3.

The src/paste namespace was declared via setuptools' namespace_packages=
and a pkg_resources.declare_namespace() __init__.py. Setuptools emits a
PasteDeploy-*-nspkg.pth alongside the wheel that calls
sys._getframe(1).f_locals['sitedir']. Python 3.15 implements PEP 829 and
rewrote site.py: pth import lines run in a deferred _exec_imports() that
no longer carries a sitedir local, so every interpreter startup raises
KeyError on this lookup (CPython gh-149671). The stderr noise breaks
downstream test suites that assert on subprocess stderr.

Removing the legacy declaration switches paste to a PEP 420 implicit
namespace package. No nspkg.pth is generated, sibling distributions in
the paste.* namespace still resolve, and the package keeps working on
3.7+ since PEP 420 is available everywhere PasteDeploy supports.
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.

1 participant