File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed
src/horse_with_no_namespace Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3+ - 2025-11-05:
4+ Make the ` pkg_resources.declare_namespace ` patch work even if there's no longer a real ` pkg_resources ` module.
35- 2025-11-05:
46 Fix handling of namespaces that have an ` __init__.py ` installed.
57 Now we read the namespaces from ` *.dist-info/namespace_packages.txt ` instead of looking for modules that were loaded with NamespaceLoader.
Original file line number Diff line number Diff line change 11# SPDX-FileCopyrightText: 2025 David Glick <[email protected] > 22#
33# SPDX-License-Identifier: MIT
4- __version__ = "20251105.0 "
4+ __version__ = "20251105.1 "
Original file line number Diff line number Diff line change @@ -47,10 +47,21 @@ def _lazy_load_pkg_resources():
4747 # This is called when something from pkg_resources is accessed.
4848 # We import it here to avoid importing it at the top of the file,
4949 # which would cause a circular import.
50- del sys .modules ["pkg_resources" ]
51- import pkg_resources
52-
53- pkg_resources .declare_namespace = declare_namespace
50+ # But let's be careful in case the real pkg_resources isn't available...
51+ existing_pkg_resources = sys .modules ["pkg_resources" ]
52+ try :
53+ del sys .modules ["pkg_resources" ]
54+ import pkg_resources
55+ except ModuleNotFoundError :
56+ # There is no actual pkg_resources module
57+ # (maybe it's a new version of setuptools that removed it).
58+ # So keep this stub and stop trying to replace it.
59+ pkg_resources = sys .modules ["pkg_resources" ] = existing_pkg_resources
60+ del globals ()["__getattr__" ]
61+ del globals ()["__dir__" ]
62+ else :
63+ # Patch the real pkg_resources to use our declare_namespace function.
64+ pkg_resources .declare_namespace = declare_namespace
5465 _pkg_resources = pkg_resources
5566
5667
You can’t perform that action at this time.
0 commit comments