-
Notifications
You must be signed in to change notification settings - Fork 331
Open
Labels
A-toolArea: toolingArea: toolingC-bugCategory: this is a bug, deviation, or other problem.Category: this is a bug, deviation, or other problem.P-low
Description
What was wrong?
The Hardfork
class allows specifying a base path to search for modules:
def discover(cls: Type[H], base: Optional[PurePath] = None) -> List[H]: |
It also provides methods for importing submodules of discovered forks:
execution-specs/src/ethereum_spec_tools/forks.py
Lines 274 to 303 in ea802a0
def import_module(self) -> ModuleType: | |
""" | |
Return the module containing this specification. | |
""" | |
return self.mod | |
def module(self, name: str) -> Any: | |
""" | |
Import if necessary, and return the given module belonging to this hard | |
fork. | |
""" | |
return importlib.import_module(self.mod.__name__ + "." + name) | |
def iter_modules(self) -> Iterator[ModuleInfo]: | |
""" | |
Iterate through the (sub-)modules describing this hardfork. | |
""" | |
if self.path is None: | |
raise ValueError(f"cannot walk {self.name}, path is None") | |
return pkgutil.iter_modules(self.path, self.name + ".") | |
def walk_packages(self) -> Iterator[ModuleInfo]: | |
""" | |
Iterate recursively through the (sub-)modules describing this hardfork. | |
""" | |
if self.path is None: | |
raise ValueError(f"cannot walk {self.name}, path is None") | |
return pkgutil.walk_packages([self.path], self.name + ".") |
Unfortunately, Hardfork
doesn't consider base
when importing those submodules. It just relies on the default import machinery.
How can it be fixed?
Use spec_from_file_location
and module_from_spec
when loading submodules.
Metadata
Metadata
Assignees
Labels
A-toolArea: toolingArea: toolingC-bugCategory: this is a bug, deviation, or other problem.Category: this is a bug, deviation, or other problem.P-low