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, prefix_inspections, exclude=spack.util.environment.is_system_path ) # Modifications that are coded at package level _ = spack.util.environment.EnvironmentModifications() # TODO : the code down below is quite similar to # TODO : build_environment.setup_package and needs to be factored out # TODO : to a single place # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications for item in dependencies(self.spec, 'all'): package = self.spec[item.name].package build_environment.set_module_variables_for_package(package) package.setup_dependent_package( self.spec.package.module, self.spec ) package.setup_dependent_environment(_, env, self.spec) # Package specific modifications build_environment.set_module_variables_for_package(self.spec.package) self.spec.package.setup_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 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 inspecting the spec prefix env = spack.environment.inspect_path( self.spec.prefix, prefix_inspections, exclude=spack.util.environment.is_system_path) # Modifications that are coded at package level _ = spack.environment.EnvironmentModifications() # TODO : the code down below is quite similar to # TODO : build_environment.setup_package and needs to be factored out # TODO : to a single place # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications for item in dependencies(self.spec, 'all'): package = self.spec[item.name].package modules = build_environment.parent_class_modules(package.__class__) for mod in modules: build_environment.set_module_variables_for_package( package, mod) build_environment.set_module_variables_for_package( package, package.module) package.setup_dependent_package(self.spec.package.module, self.spec) package.setup_dependent_environment(_, env, self.spec) # Package specific modifications build_environment.set_module_variables_for_package( self.spec.package, self.spec.package.module) self.spec.package.setup_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 for x in env: x.name = self.spec.format(x.name) try: # Not every command has a value x.value = self.spec.format(x.value) except AttributeError: pass x.name = str(x.name).replace('-', '_').upper() return [(type(x).__name__, x) for x in env if x.name not in blacklist]
except OSError, e: raise InstallError("Unable to fork build process: %s" % e) if pid == 0: try: tty.msg("Building %s." % self.name) # create the install directory. The install layout # handles this in case so that it can use whatever # package naming scheme it likes. spack.install_layout.make_path_for_spec(self.spec) # Set up process's build environment before running install. build_env.set_compiler_environment_variables(self) build_env.set_build_environment_variables(self) build_env.set_module_variables_for_package(self) # Subclasses implement install() to do the real work. self.install(self.spec, self.prefix) # Ensure that something was actually installed. if not os.listdir(self.prefix): raise InstallError( "Install failed for %s. Nothing was installed!" % self.name) # On successful install, remove the stage. if not keep_stage: self.stage.destroy() tty.msg("Successfully installed %s" % self.name)
def environment_modifications(self): """List of environment modifications to be processed.""" # Modifications guessed inspecting the spec prefix env = spack.environment.inspect_path( self.spec.prefix, prefix_inspections, exclude=spack.util.environment.is_system_path ) # Modifications that are coded at package level _ = spack.environment.EnvironmentModifications() # TODO : the code down below is quite similar to # TODO : build_environment.setup_package and needs to be factored out # TODO : to a single place # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications for item in dependencies(self.spec, 'all'): package = self.spec[item.name].package modules = build_environment.parent_class_modules(package.__class__) for mod in modules: build_environment.set_module_variables_for_package( package, mod ) build_environment.set_module_variables_for_package( package, package.module ) package.setup_dependent_package( self.spec.package.module, self.spec ) package.setup_dependent_environment(_, env, self.spec) # Package specific modifications build_environment.set_module_variables_for_package( self.spec.package, self.spec.package.module ) self.spec.package.setup_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] = str.upper 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 write(self): """ Writes out a module file for this object. This method employs a template pattern and expects derived classes to: - override the header property - provide formats for autoload, prerequisites and environment changes """ if self.blacklisted: return tty.debug("\tWRITE : %s [%s]" % (self.spec.cshort_spec, self.file_name)) module_dir = os.path.dirname(self.file_name) if not os.path.exists(module_dir): mkdirp(module_dir) # Environment modifications guessed by inspecting the # installation prefix env = inspect_path(self.spec.prefix) # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications spack_env = EnvironmentModifications() # TODO : the code down below is quite similar to # TODO : build_environment.setup_package and needs to be factored out # TODO : to a single place for item in dependencies(self.spec, 'all'): package = self.spec[item.name].package modules = parent_class_modules(package.__class__) for mod in modules: set_module_variables_for_package(package, mod) set_module_variables_for_package(package, package.module) package.setup_dependent_package(self.pkg.module, self.spec) package.setup_dependent_environment(spack_env, env, self.spec) # Package-specific environment modifications set_module_variables_for_package(self.pkg, self.pkg.module) self.spec.package.setup_environment(spack_env, env) # Parse configuration file module_configuration, conf_env = parse_config_options(self) env.extend(conf_env) filters = module_configuration.get('filter', {}).get('environment_blacklist', {}) # Build up the module file content module_file_content = self.header for x in filter_blacklisted(module_configuration.pop('autoload', []), self.name): module_file_content += self.autoload(x) for x in filter_blacklisted( module_configuration.pop('prerequisites', []), self.name): module_file_content += self.prerequisite(x) for line in self.process_environment_command( filter_environment_blacklist(env, filters)): module_file_content += line for line in self.module_specific_content(module_configuration): module_file_content += line # Dump to file with open(self.file_name, 'w') as f: f.write(module_file_content)
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]
def write(self): """ Writes out a module file for this object. This method employs a template pattern and expects derived classes to: - override the header property - provide formats for autoload, prerequisites and environment changes """ if self.blacklisted: return tty.debug("\tWRITE : %s [%s]" % (self.spec.cshort_spec, self.file_name)) module_dir = os.path.dirname(self.file_name) if not os.path.exists(module_dir): mkdirp(module_dir) # Environment modifications guessed by inspecting the # installation prefix env = inspect_path(self.spec.prefix) # Let the extendee/dependency modify their extensions/dependencies # before asking for package-specific modifications spack_env = EnvironmentModifications() # TODO : the code down below is quite similar to # TODO : build_environment.setup_package and needs to be factored out # TODO : to a single place for item in dependencies(self.spec, 'all'): package = self.spec[item.name].package modules = parent_class_modules(package.__class__) for mod in modules: set_module_variables_for_package(package, mod) set_module_variables_for_package(package, package.module) package.setup_dependent_package(self.pkg.module, self.spec) package.setup_dependent_environment(spack_env, env, self.spec) # Package-specific environment modifications set_module_variables_for_package(self.pkg, self.pkg.module) self.spec.package.setup_environment(spack_env, env) # Parse configuration file module_configuration, conf_env = parse_config_options(self) env.extend(conf_env) filters = module_configuration.get('filter', {}).get( 'environment_blacklist', {}) # Build up the module file content module_file_content = self.header for x in filter_blacklisted( module_configuration.pop('autoload', []), self.name): module_file_content += self.autoload(x) for x in filter_blacklisted( module_configuration.pop('prerequisites', []), self.name): module_file_content += self.prerequisite(x) for line in self.process_environment_command( filter_environment_blacklist(env, filters)): module_file_content += line for line in self.module_specific_content(module_configuration): module_file_content += line # Dump to file with open(self.file_name, 'w') as f: f.write(module_file_content)