From 9ab7d8f01da281206da5aaf1a619096e90c4fa1e Mon Sep 17 00:00:00 2001 From: Carson Woods Date: Thu, 18 Jul 2019 13:50:25 -0600 Subject: [PATCH] Add config parameter for active upstream to set install location for modules --- lib/spack/spack/cmd/install.py | 2 ++ lib/spack/spack/cmd/uninstall.py | 8 ++++++++ lib/spack/spack/modules/common.py | 14 ++++++++++++-- lib/spack/spack/package.py | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index 0dd7a235865..bcb2dd4b123 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -207,6 +207,8 @@ def install(spec, kwargs): spec.package.do_install(**kwargs) spack.config.set('config:active_tree', '~/.spack/opt/spack', scope='user') + spack.config.set('config:active_upstream', None, + scope='user') try: if cli_args.things_to_install == 'dependencies': diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py index 26cf9e78ebb..eed90305f9d 100644 --- a/lib/spack/spack/cmd/uninstall.py +++ b/lib/spack/spack/cmd/uninstall.py @@ -88,6 +88,8 @@ def find_matching_specs(env, specs, allow_multiple_matches=False, force=False, list of specs """ if global_uninstall: + spack.config.set('config:active_upstream', 'global', + scope='user') global_root = spack.config.get('upstreams') global_root = global_root['global']['install_tree'] global_root = spack.util.path.canonicalize_path(global_root) @@ -96,11 +98,15 @@ def find_matching_specs(env, specs, allow_multiple_matches=False, force=False, elif upstream: if upstream not in spack.config.get('upstreams'): tty.die("specified upstream does not exist") + spack.config.set('config:active_upstream', upstream, + scope='user') root = spack.config.get('upstreams') root = root[upstream]['install_tree'] root = spack.util.path.canonicalize_path(root) spack.config.set('config:active_tree', root, scope='user') else: + spack.config.set('config:active_upstream', None, + scope='user') for spec in specs: if isinstance(spec, spack.spec.Spec): spec_name = str(spec) @@ -276,6 +282,8 @@ def do_uninstall(env, specs, force): '~/.spack/opt/spack', scope='user') + spack.config.set('config:active_upstream', None, + scope='user') def get_uninstall_list(args, specs, env): # Gets the list of installed specs that match the ones give via cli diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py index d5f872badf0..71ea29c1d36 100644 --- a/lib/spack/spack/modules/common.py +++ b/lib/spack/spack/modules/common.py @@ -214,12 +214,21 @@ def root_path(name): """Returns the root folder for module file installation. Args: - name: name of the module system t be used (e.g. 'tcl') + name: name of the module system to be used (e.g. 'tcl') Returns: root folder for module file installation """ - path = roots.get(name, os.path.join(spack.paths.share_path, name)) + + # Determine where to install modules too + active_upstream = spack.config.get('config:active_upstream') + + if active_upstream: + root_name = 'upstreams:' + active_upstream + ":modules:" + name + path = spack.config.get(root_name, os.path.join(spack.paths.share_path, name)) + else: + path = roots.get(name, os.path.join(spack.paths.share_path, name)) + return spack.util.path.canonicalize_path(path) @@ -284,6 +293,7 @@ def read_module_indices(): module_type_to_index = {} module_type_to_root = install_properties.get('modules', {}) for module_type, root in module_type_to_root.items(): + root = spack.util.path.canonicalize_path(root) module_type_to_index[module_type] = read_module_index(root) module_indices.append(module_type_to_index) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index aab80d14107..1b23f0cf16c 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1496,6 +1496,8 @@ def do_install(self, **kwargs): # Install Package to Global Upstream for multi-user use if install_global: + spack.config.set('config:active_upstream', 'global', + scope='user') global_root = spack.config.get('upstreams') global_root = global_root['global']['install_tree'] global_root = spack.util.path.canonicalize_path(global_root) @@ -1504,11 +1506,15 @@ def do_install(self, **kwargs): elif upstream: if upstream not in spack.config.get('upstreams'): tty.die("specified upstream does not exist") + spack.config.set('config:active_upstream', upstream, + scope='user') root = spack.config.get('upstreams') root = root[upstream]['install_tree'] root = spack.util.path.canonicalize_path(root) spack.config.set('config:active_tree', root, scope='user') else: + spack.config.set('config:active_upstream', None, + scope='user') spack.config.set('config:active_tree', spack.config.get('config:install_tree'), scope='user')