Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- 2025-11-05:
Make the `pkg_resources.declare_namespace` patch work even if there's no longer a real `pkg_resources` module.
- 2025-11-05:
Fix handling of namespaces that have an `__init__.py` installed.
Now we read the namespaces from `*.dist-info/namespace_packages.txt` instead of looking for modules that were loaded with NamespaceLoader.
Expand Down
2 changes: 1 addition & 1 deletion src/horse_with_no_namespace/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 David Glick <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "20251105.0"
__version__ = "20251105.1"
19 changes: 15 additions & 4 deletions src/horse_with_no_namespace/pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,21 @@ def _lazy_load_pkg_resources():
# This is called when something from pkg_resources is accessed.
# We import it here to avoid importing it at the top of the file,
# which would cause a circular import.
del sys.modules["pkg_resources"]
import pkg_resources

pkg_resources.declare_namespace = declare_namespace
# But let's be careful in case the real pkg_resources isn't available...
existing_pkg_resources = sys.modules["pkg_resources"]
try:
del sys.modules["pkg_resources"]
import pkg_resources
except ModuleNotFoundError:
# There is no actual pkg_resources module
# (maybe it's a new version of setuptools that removed it).
# So keep this stub and stop trying to replace it.
pkg_resources = sys.modules["pkg_resources"] = existing_pkg_resources
del globals()["__getattr__"]
del globals()["__dir__"]
else:
# Patch the real pkg_resources to use our declare_namespace function.
pkg_resources.declare_namespace = declare_namespace
_pkg_resources = pkg_resources


Expand Down