Skip to content

Commit 817d98f

Browse files
authored
Merge pull request #3 from davisagli/fix-missing-path
Handle case where there is no __path__ to update
2 parents aec69f8 + 4376c80 commit 817d98f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/horse_with_no_namespace/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def apply():
3333
logged = True
3434

3535
# Only patch pkg_resources if it is installed...
36+
# (To do: at some point pkg_resources will be removed from setuptools.
37+
# Then we might have to add our own fake module.)
3638
try:
3739
import pkg_resources
3840
except ImportError:
@@ -42,9 +44,12 @@ def apply():
4244
# to update __path__ using pkgutil.extend_path instead
4345
def declare_namespace(packageName):
4446
parent_locals = sys._getframe(1).f_locals
45-
parent_locals["__path__"] = pkgutil.extend_path(
46-
parent_locals["__path__"], packageName
47-
)
47+
# Sometimes declare_namespace is called from pkg_resources itself;
48+
# then there is no __path__ which needs to be updated.
49+
if "__path__" in parent_locals:
50+
parent_locals["__path__"] = pkgutil.extend_path(
51+
parent_locals["__path__"], packageName
52+
)
4853

4954
pkg_resources.declare_namespace = declare_namespace
5055

0 commit comments

Comments
 (0)