def environment_modifications_for_spec(spec, view=None): """List of environment (shell) modifications to be processed for spec. This list is specific to the location of the spec or its projection in the view.""" spec = spec.copy() if view and not spec.external: spec.prefix = prefix.Prefix(view.view().get_projection_for_spec(spec)) # generic environment modifications determined by inspecting the spec # prefix env = environment.inspect_path( spec.prefix, prefix_inspections(spec.platform), exclude=environment.is_system_path ) # Let the extendee/dependency modify their extensions/dependents # before asking for package-specific modifications env.extend( build_env.modifications_from_dependencies( spec, context='run' ) ) # Package specific modifications build_env.set_module_variables_for_package(spec.package) spec.package.setup_run_environment(env) return env
def environment_modifications(self): """List of environment modifications to be processed.""" # Modifications guessed inspecting the spec prefix env = spack.util.environment.inspect_path( self.spec.prefix, spack.config.get('modules:prefix_inspections', {}), exclude=spack.util.environment.is_system_path ) # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications env.extend( build_environment.modifications_from_dependencies( self.spec, context='run' ) ) # Package specific modifications build_environment.set_module_variables_for_package(self.spec.package) self.spec.package.setup_run_environment(env) # Modifications required from modules.yaml env.extend(self.conf.env) # List of variables that are blacklisted in modules.yaml blacklist = self.conf.environment_blacklist # We may have tokens to substitute in environment commands # Prepare a suitable transformation dictionary for the names # of the environment variables. This means turn the valid # tokens uppercase. transform = {} for token in _valid_tokens: transform[token] = lambda spec, string: str.upper(string) for x in env: # Ensure all the tokens are valid in this context msg = 'some tokens cannot be expanded in an environment variable name' # noqa: E501 _check_tokens_are_valid(x.name, message=msg) # Transform them x.name = self.spec.format(x.name, transform=transform) try: # Not every command has a value x.value = self.spec.format(x.value) except AttributeError: pass x.name = str(x.name).replace('-', '_') return [(type(x).__name__, x) for x in env if x.name not in blacklist]
def environment_modifications(self): """List of environment modifications to be processed.""" # Modifications guessed by inspecting the spec prefix std_prefix_inspections = spack.config.get('modules:prefix_inspections', {}) set_prefix_inspections = spack.config.get( 'modules:%s:prefix_inspections' % self.conf.name, {}) prefix_inspections = spack.config.merge_yaml(std_prefix_inspections, set_prefix_inspections) use_view = spack.config.get('modules:%s:use_view' % self.conf.name, False) spec = self.spec.copy() # defensive copy before setting prefix if use_view: if use_view is True: use_view = spack.environment.default_view_name env = spack.environment.active_environment() if not env: raise spack.environment.SpackEnvironmentViewError( "Module generation with views requires active environment") view = env.views[use_view] spec.prefix = view.get_projection_for_spec(spec) env = spack.util.environment.inspect_path( spec.prefix, prefix_inspections, exclude=spack.util.environment.is_system_path) # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications env.extend( build_environment.modifications_from_dependencies(spec, context='run')) # Package specific modifications build_environment.set_module_variables_for_package(spec.package) spec.package.setup_run_environment(env) # Modifications required from modules.yaml env.extend(self.conf.env) # List of variables that are blacklisted in modules.yaml blacklist = self.conf.environment_blacklist # We may have tokens to substitute in environment commands # Prepare a suitable transformation dictionary for the names # of the environment variables. This means turn the valid # tokens uppercase. transform = {} for token in _valid_tokens: transform[token] = lambda s, string: str.upper(string) for x in env: # Ensure all the tokens are valid in this context msg = 'some tokens cannot be expanded in an environment variable name' # noqa: E501 _check_tokens_are_valid(x.name, message=msg) # Transform them x.name = spec.format(x.name, transform=transform) try: # Not every command has a value x.value = spec.format(x.value) except AttributeError: pass x.name = str(x.name).replace('-', '_') return [(type(x).__name__, x) for x in env if x.name not in blacklist]