-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add configs for reusing specs from environments and enable reuse from included concrete environments by default #45139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
becker33
merged 8 commits into
spack:develop
from
kwryankrattiger:concretize_reuse_include_concrete
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a1eae1
Concretizer configs to reuse concrete environments
kwryankrattiger c8a77f3
Addressing review comments
kwryankrattiger f4d0da3
Add test for environment helper function environment_from_name_or_dir
kwryankrattiger 7c93ac0
Add test for non-included environment. Fix included env behavior
kwryankrattiger 6f625ad
bugfix: unify settings for included environments
becker33 5179fef
Update reuse concrete tests to work with properly implemented unify
kwryankrattiger 77ff236
Fix style checks
kwryankrattiger b273dec
Drop redundant part of test
kwryankrattiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2616,6 +2616,7 @@ def setup( | |
| ) | ||
| for name, info in env.dev_specs.items() | ||
| ) | ||
|
|
||
| specs = tuple(specs) # ensure compatible types to add | ||
|
|
||
| self.gen.h1("Reusable concrete specs") | ||
|
|
@@ -3966,22 +3967,45 @@ def selected_specs(self) -> List[spack.spec.Spec]: | |
| return [s for s in self.factory() if self.is_selected(s)] | ||
|
|
||
| @staticmethod | ||
| def from_store(configuration, include, exclude) -> "SpecFilter": | ||
| def from_store(configuration, *, include, exclude) -> "SpecFilter": | ||
| """Constructs a filter that takes the specs from the current store.""" | ||
| packages = _external_config_with_implicit_externals(configuration) | ||
| is_reusable = functools.partial(_is_reusable, packages=packages, local=True) | ||
| factory = functools.partial(_specs_from_store, configuration=configuration) | ||
| return SpecFilter(factory=factory, is_usable=is_reusable, include=include, exclude=exclude) | ||
|
|
||
| @staticmethod | ||
| def from_buildcache(configuration, include, exclude) -> "SpecFilter": | ||
| def from_buildcache(configuration, *, include, exclude) -> "SpecFilter": | ||
| """Constructs a filter that takes the specs from the configured buildcaches.""" | ||
| packages = _external_config_with_implicit_externals(configuration) | ||
| is_reusable = functools.partial(_is_reusable, packages=packages, local=False) | ||
| return SpecFilter( | ||
| factory=_specs_from_mirror, is_usable=is_reusable, include=include, exclude=exclude | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def from_environment(configuration, *, include, exclude, env) -> "SpecFilter": | ||
| packages = _external_config_with_implicit_externals(configuration) | ||
| is_reusable = functools.partial(_is_reusable, packages=packages, local=True) | ||
| factory = functools.partial(_specs_from_environment, env=env) | ||
| return SpecFilter(factory=factory, is_usable=is_reusable, include=include, exclude=exclude) | ||
|
|
||
| @staticmethod | ||
| def from_environment_included_concrete( | ||
| configuration, | ||
| *, | ||
| include: List[str], | ||
| exclude: List[str], | ||
| env: ev.Environment, | ||
| included_concrete: str, | ||
| ) -> "SpecFilter": | ||
| packages = _external_config_with_implicit_externals(configuration) | ||
| is_reusable = functools.partial(_is_reusable, packages=packages, local=True) | ||
| factory = functools.partial( | ||
| _specs_from_environment_included_concrete, env=env, included_concrete=included_concrete | ||
| ) | ||
| return SpecFilter(factory=factory, is_usable=is_reusable, include=include, exclude=exclude) | ||
|
|
||
|
|
||
| def _specs_from_store(configuration): | ||
| store = spack.store.create(configuration) | ||
|
|
@@ -3999,6 +4023,23 @@ def _specs_from_mirror(): | |
| return [] | ||
|
|
||
|
|
||
| def _specs_from_environment(env): | ||
| """Return all concrete specs from the environment. This includes all included concrete""" | ||
| if env: | ||
| return [concrete for _, concrete in env.concretized_specs()] | ||
| else: | ||
| return [] | ||
|
|
||
|
|
||
| def _specs_from_environment_included_concrete(env, included_concrete): | ||
| """Return only concrete specs from the environment included from the included_concrete""" | ||
| if env: | ||
| assert included_concrete in env.included_concrete_envs | ||
| return [concrete for concrete in env.included_specs_by_hash[included_concrete].values()] | ||
| else: | ||
| return [] | ||
|
|
||
|
|
||
| class ReuseStrategy(enum.Enum): | ||
| ROOTS = enum.auto() | ||
| DEPENDENCIES = enum.auto() | ||
|
|
@@ -4028,6 +4069,12 @@ def __init__(self, configuration: spack.config.Configuration) -> None: | |
| SpecFilter.from_buildcache( | ||
| configuration=self.configuration, include=[], exclude=[] | ||
| ), | ||
| SpecFilter.from_environment( | ||
| configuration=self.configuration, | ||
| include=[], | ||
| exclude=[], | ||
| env=ev.active_environment(), # includes all concrete includes | ||
| ), | ||
| ] | ||
| ) | ||
| else: | ||
|
|
@@ -4042,7 +4089,46 @@ def __init__(self, configuration: spack.config.Configuration) -> None: | |
| for source in reuse_yaml.get("from", default_sources): | ||
| include = source.get("include", default_include) | ||
| exclude = source.get("exclude", default_exclude) | ||
| if source["type"] == "local": | ||
| if isinstance(source["type"], dict): | ||
| env_dir = ev.as_env_dir(source["type"].get("environment")) | ||
| active_env = ev.active_environment() | ||
| if active_env and env_dir in active_env.included_concrete_envs: | ||
| # If environment is included as a concrete environment, use the local copy | ||
| # of specs in the active environment. | ||
| # note: included concrete environments are only updated at concretization | ||
| # time, and reuse needs to matchthe included specs. | ||
| self.reuse_sources.append( | ||
| SpecFilter.from_environment_included_concrete( | ||
| self.configuration, | ||
| include=include, | ||
| exclude=exclude, | ||
| env=active_env, | ||
| included_concrete=env_dir, | ||
| ) | ||
| ) | ||
|
Comment on lines
+4096
to
+4108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kwryankrattiger I have two questions on this PR as I'm trying to implement #49707
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| else: | ||
|
kwryankrattiger marked this conversation as resolved.
|
||
| # If the environment is not included as a concrete environment, use the | ||
| # current specs from its lockfile. | ||
| self.reuse_sources.append( | ||
| SpecFilter.from_environment( | ||
| self.configuration, | ||
| include=include, | ||
| exclude=exclude, | ||
| env=ev.environment_from_name_or_dir(env_dir), | ||
| ) | ||
| ) | ||
| elif source["type"] == "environment": | ||
| # reusing from the current environment implicitly reuses from all of the | ||
| # included concrete environments | ||
| self.reuse_sources.append( | ||
|
kwryankrattiger marked this conversation as resolved.
|
||
| SpecFilter.from_environment( | ||
| self.configuration, | ||
| include=include, | ||
| exclude=exclude, | ||
| env=ev.active_environment(), | ||
|
kwryankrattiger marked this conversation as resolved.
|
||
| ) | ||
| ) | ||
| elif source["type"] == "local": | ||
| self.reuse_sources.append( | ||
| SpecFilter.from_store(self.configuration, include=include, exclude=exclude) | ||
| ) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.