Skip to content

Commit 1c7c7ce

Browse files
author
renaud gaudin
committed
Use fullname instead of path in ModuleFinder
Hacking around the path for loading our modules is fragile as there are stuff relying on its value to consider it a package. `help(libzim)` for instance is broken as it can't enumerate it properly. This is simpler, less hacky and fixes the module's docstring which is important for self-discovery.
1 parent c3fcbde commit 1c7c7ce

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

libzim/libzim.pyx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919

2020
# Make our libzim module a package by setting a __path__
2121
# There is no real path here, but it will be passed to our module finder.
22-
__path__ = "___LIBZIM___"
22+
"""openZIM's file format library binding
23+
24+
- libzim.writer to create ZIM file with Creator
25+
- libzim.reader to open ZIM file as Archive
26+
- libzim.search to search on an Archive
27+
- libzim.suggestion to retrieve suggestions on an Archive
28+
29+
https://openzim.org"""
30+
__path__ = []
2331

2432
cimport zim
2533

@@ -1148,10 +1156,10 @@ class ModuleLoader(importlib.abc.Loader):
11481156

11491157
class ModuleFinder(importlib.abc.MetaPathFinder):
11501158
def find_spec(self, fullname, path, target=None):
1151-
if path != __path__:
1152-
# This is not our problem, let import mechanism continue
1153-
return None
1154-
return importlib.machinery.ModuleSpec(fullname, ModuleLoader)
1159+
if fullname.startswith("libzim."):
1160+
return importlib.machinery.ModuleSpec(fullname, ModuleLoader)
1161+
# This is not our problem, let import mechanism continue
1162+
return None
11551163

11561164
# register finder for our submodules
11571165
sys.meta_path.insert(0, ModuleFinder())

0 commit comments

Comments
 (0)