diff options
Diffstat (limited to 'lib/spack/spack/environment.py')
-rw-r--r-- | lib/spack/spack/environment.py | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index fbdcb67761..a37cad8633 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -19,6 +19,7 @@ from llnl.util.tty.color import colorize import spack.concretize import spack.error import spack.hash_types as ht +import spack.hooks import spack.repo import spack.schema.env import spack.spec @@ -458,12 +459,15 @@ class ViewDescriptor(object): self.root = spack.util.path.canonicalize_path(root) self.projections = projections self.select = select - self.select_fn = lambda x: any(x.satisfies(s) for s in self.select) self.exclude = exclude - self.exclude_fn = lambda x: not any(x.satisfies(e) - for e in self.exclude) self.link = link + def select_fn(self, spec): + return any(spec.satisfies(s) for s in self.select) + + def exclude_fn(self, spec): + return not any(spec.satisfies(e) for e in self.exclude) + def __eq__(self, other): return all([self.root == other.root, self.projections == other.projections, @@ -741,7 +745,7 @@ class Environment(object): if not os.path.exists(self.manifest_path): return - self.clear() + self.clear(re_read=True) self._read() def _read(self): @@ -839,15 +843,26 @@ class Environment(object): ) } - def clear(self): + def clear(self, re_read=False): + """Clear the contents of the environment + + Arguments: + re_read (boolean): If True, do not clear ``new_specs`` nor + ``new_installs`` values. These values cannot be read from + yaml, and need to be maintained when re-reading an existing + environment. + """ self.spec_lists = {user_speclist_name: SpecList()} # specs from yaml self.dev_specs = {} # dev-build specs from yaml self.concretized_user_specs = [] # user specs from last concretize self.concretized_order = [] # roots of last concretize, in order self.specs_by_hash = {} # concretized specs by hash - self.new_specs = [] # write packages for these on write() self._repo = None # RepoPath for this env (memoized) self._previous_active = None # previously active environment + if not re_read: + # things that cannot be recreated from file + self.new_specs = [] # write packages for these on write() + self.new_installs = [] # write modules for these on write() @property def internal(self): @@ -1584,6 +1599,7 @@ class Environment(object): # Ensure links are set appropriately for spec in specs_to_install: if spec.package.installed: + self.new_installs.append(spec) try: self._install_log_links(spec) except OSError as e: @@ -1812,17 +1828,16 @@ class Environment(object): self.concretized_order = [ old_hash_to_new.get(h, h) for h in self.concretized_order] - def write(self, regenerate_views=True): + def write(self, regenerate=True): """Writes an in-memory environment to its location on disk. Write out package files for each newly concretized spec. Also - regenerate any views associated with the environment, if - regenerate_views is True. + regenerate any views associated with the environment and run post-write + hooks, if regenerate is True. Arguments: - regenerate_views (bool): regenerate views as well as - writing if True. - + regenerate (bool): regenerate views and run post-write hooks as + well as writing if True. """ # Intercept environment not using the latest schema format and prevent # them from being modified @@ -1858,7 +1873,6 @@ class Environment(object): fs.mkdirp(pkg_dir) spack.repo.path.dump_provenance(dep, pkg_dir) - self.new_specs = [] # write the lock file last with fs.write_tmp_and_move(self.lock_path) as f: @@ -1874,9 +1888,16 @@ class Environment(object): # call. But, having it here makes the views consistent witht the # concretized environment for most operations. Which is the # special case? - if regenerate_views: + if regenerate: self.regenerate_views() + # Run post_env_hooks + spack.hooks.post_env_write(self) + + # new specs and new installs reset at write time + self.new_specs = [] + self.new_installs = [] + def _update_and_write_manifest(self, raw_yaml_dict, yaml_dict): """Update YAML manifest for this environment based on changes to spec lists and views and write it. |