Skip to content
5 changes: 4 additions & 1 deletion docs/functionality.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ containing those import statements at ``config.imports``, as a list of
To get the imported objects, these imports must be resolved, which can be done through
the :func:`ymmsl.v0_2.resolve` function. This takes the name of the module corresponding
to a ``Configuration`` (which is the file name without the ``.ymmsl`` extension, wrapped
in a :class:`ymmsl.v0_2.Reference`) and the configuration itself.
in a :class:`ymmsl.v0_2.Reference`), the configuration itself, and an optional
``reuse_cached_imports`` keyword argument. By default, imports are cached between calls to
avoid re-reading previously loaded modules. Set ``reuse_cached_imports=False`` when the
search path is changed (``YMMSL_PATH`` or ``sys.path``) to avoid stale module imports.

It updates that configuration in place, renaming any local models and programs to their
absolute name by prefixing them with the given module name, then imports the
Expand Down
9 changes: 8 additions & 1 deletion ymmsl/v0_2/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def search_paths(self, rel_path: Path, indent_depth: int) -> str:
)


def resolve(module: Reference, config: Configuration) -> None:
def resolve(
module: Reference, config: Configuration, reuse_cached_imports: bool = True
) -> None:
"""Resolve imports for the given configuration.

This updates the given configuration in place, removing all import statements and
Expand All @@ -100,11 +102,16 @@ def resolve(module: Reference, config: Configuration) -> None:
Args:
module: The module corresponding to this configuration
config: The configuration to resolve
reuse_cached_imports: If cached imports should be reused from previous calls of
this method. Disable if YMMSL_PATH or sys.path changes.

Raises:
RuntimeError: if an error occurs due to an invalid configuration. This will
leave config in a broken state, so reload it if you want to try again.
"""
if not reuse_cached_imports:
ymmsl_cache.clear()

overwritten = do_resolve(Path("<main>"), module, config, ResolutionContext())
remove_overwritten_implementations(config, overwritten)

Expand Down
Loading
Loading