Skip to content

Optional cached imports - #72

Merged
LourensVeen merged 9 commits into
multiscale:developfrom
kristoffer-gustafsson:optional-cached-imports
Oct 1, 2026
Merged

LourensVeen merged 9 commits into
multiscale:developfrom
kristoffer-gustafsson:optional-cached-imports

Conversation

@kristoffer-gustafsson

Copy link
Copy Markdown
Contributor

The ymmsl_cache assumes that the YMMSL_PATH and sys.path does not change between resolve calls, but in fact it can.
If it does, the cached module imports can become stale.

Therefore I have added this contract explicitly in the doc-string of the resolve method, along with an option to clear the cache before resolving.

This test checks that some warning is logged when multiple entry points are found for one module. However, this part of the code is never reached if on the second call with reuse_cached_imports = True instead of False. That is because the entrypoints are cached in the previous call, which skips  _load_from_entrypoints where the warning is raised.

Therefore ymmsl_cache is cleared before and after each test to ensure a clean slate.

The failed test::
FAILED ymmsl/v0_2/tests/test_resolver.py::test_resolve_entrypoints_duplicate_name[True] - assert 0 == 1
 +  where 0 = len([])
@LourensVeen LourensVeen self-assigned this Sep 25, 2026
@LourensVeen
LourensVeen self-requested a review September 25, 2026 15:41

@LourensVeen LourensVeen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good addition. I'd like to simplify the test a bit, as indicated. And could you fix the formatting so the CI passes?

Comment thread ymmsl/v0_2/tests/test_resolver.py Outdated
Comment thread ymmsl/v0_2/tests/test_resolver.py Outdated

@LourensVeen LourensVeen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, two more nits to pick but then we'll merge it.

Comment thread ymmsl/v0_2/tests/test_resolver.py Outdated
from ymmsl.v0_2.configuration import Configuration
from ymmsl.v0_2.identity import Reference
from ymmsl.v0_2.resolver import resolve as resolve_impl, ymmsl_cache
from ymmsl.v0_2.resolver import resolve as resolve_impl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rename is now no longer necessary, and potentially confusing. Could you remove it?

Comment thread ymmsl/v0_2/tests/test_resolver.py Outdated
resolve_impl(
Reference("test_resolve_imports"),
config,
reuse_cached_imports=reuse_cached_imports,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were setting this to True then passing the argument with its name makes sense because it clarifies what is true, but if we already have the variable then this is just needless duplication.

@LourensVeen LourensVeen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@LourensVeen

Copy link
Copy Markdown
Contributor

The CI failure is unrelated to this PR, I need to remove the Codacy coverage upload since we're not using Codacy anymore. Merging anyway.

@LourensVeen
LourensVeen merged commit efb1930 into multiscale:develop Oct 1, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants