Skip to content

Commit

Permalink
Add a dynamic declaration of spec function that does not rely on inspect
Browse files Browse the repository at this point in the history
This faster function will be available once "from e3.anod.loader import
spec" statements are removed. Keep the former version for backward
compatibility.
  • Loading branch information
Nikokrock committed Jan 10, 2024
1 parent 98de370 commit ff78513
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/e3/anod/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def __init__(

# Declare spec prolog
prolog_file = os.path.join(spec_dir, "prolog.py")
self.prolog_dict = {"spec_config": spec_config, "__spec_repository": self}
self.prolog_dict = {
"spec_config": spec_config,
"__spec_repository": self,
"spec": self.load,
}

if os.path.exists(prolog_file):
with open(prolog_file) as f:
exec(compile(f.read(), prolog_file, "exec"), self.prolog_dict)
Expand Down Expand Up @@ -271,6 +276,9 @@ def load(self, repository: AnodSpecRepository) -> Callable[..., Anod]:
def spec(name: str) -> Callable[..., Anod]:
"""Load an Anod spec class.
Obsolete: keep until all from e3.anod.loader import spec are removed from the
specs.
Note that two spec having the same name cannot be loaded in the same
process as e3 keeps a cache of loaded spec using the spec basename as a
key.
Expand Down

0 comments on commit ff78513

Please sign in to comment.