def execute(self, env): tty.debug("RemovePath: {0}-{1}".format(self.name, str(self.value)), level=3) environment_value = env.get(self.name, '') directories = environment_value.split( self.separator) if environment_value else [] directories = [path_to_os_path(os.path.normpath(x)).pop() for x in directories if x != path_to_os_path(os.path.normpath(self.value)).pop()] env[self.name] = self.separator.join(directories)
def which_string(*args, **kwargs): """Like ``which()``, but return a string instead of an ``Executable``.""" path = kwargs.get('path', os.environ.get('PATH', '')) required = kwargs.get('required', False) if isinstance(path, string_types): path = path.split(os.pathsep) for name in args: win_candidates = [] if sys.platform == "win32" and (not name.endswith(".exe") and not name.endswith(".bat")): win_candidates = [name + ext for ext in ['.exe', '.bat']] candidate_names = [name] if not win_candidates else win_candidates for candidate_name in candidate_names: if os.path.sep in candidate_name: exe = os.path.abspath(candidate_name) if os.path.isfile(exe) and os.access(exe, os.X_OK): return exe else: for directory in path: directory = path_to_os_path(directory).pop() exe = os.path.join(directory, candidate_name) if os.path.isfile(exe) and os.access(exe, os.X_OK): return exe if required: raise CommandNotFoundError( "spack requires '%s'. Make sure it is in your path." % args[0]) return None
def execute(self, env): tty.debug("DeprioritizeSystemPaths: {0}".format(self.name), level=3) environment_value = env.get(self.name, '') directories = environment_value.split( self.separator) if environment_value else [] directories = deprioritize_system_paths( [path_to_os_path(os.path.normpath(x)).pop() for x in directories]) env[self.name] = self.separator.join(directories)
def execute(self, env): tty.debug("AppendPath: {0}+{1}".format(self.name, str(self.value)), level=3) environment_value = env.get(self.name, '') directories = environment_value.split( self.separator) if environment_value else [] directories.append(path_to_os_path(os.path.normpath(self.value)).pop()) env[self.name] = self.separator.join(directories)
def execute(self, env): tty.debug("PruneDuplicatePaths: {0}".format(self.name), level=3) environment_value = env.get(self.name, '') directories = environment_value.split( self.separator) if environment_value else [] directories = prune_duplicate_paths( [path_to_os_path(os.path.normpath(x)).pop() for x in directories]) env[self.name] = self.separator.join(directories)
def __init__(self, name): # necesary here for the shlex call to succeed name = format_os_path(name, mode=Path.unix) self.exe = shlex.split(str(name)) # filter back to platform dependent path self.exe = path_to_os_path(*self.exe) self.default_env = {} from spack.util.environment import EnvironmentModifications # no cycle self.default_envmod = EnvironmentModifications() self.returncode = None if not self.exe: raise ProcessError("Cannot construct executable for '%s'" % name)
def test_read_and_write_spec(temporary_store, config, mock_packages): """This goes through each package in spack and creates a directory for it. It then ensures that the spec for the directory's installed package can be read back in consistently, and finally that the directory can be removed by the directory layout. """ layout = temporary_store.layout pkg_names = list(spack.repo.path.all_package_names())[:max_packages] for name in pkg_names: if name.startswith('external'): # External package tests cannot be installed continue # If a spec fails to concretize, just skip it. If it is a # real error, it will be caught by concretization tests. try: spec = spack.spec.Spec(name).concretized() except Exception: continue layout.create_install_directory(spec) install_dir = path_to_os_path(layout.path_for_spec(spec))[0] spec_path = layout.spec_file_path(spec) # Ensure directory has been created in right place. assert os.path.isdir(install_dir) assert install_dir.startswith(temporary_store.root) # Ensure spec file exists when directory is created assert os.path.isfile(spec_path) assert spec_path.startswith(install_dir) # Make sure spec file can be read back in to get the original spec spec_from_file = layout.read_spec(spec_path) stored_deptypes = spack.hash_types.dag_hash expected = spec.copy(deps=stored_deptypes) expected._mark_concrete() assert expected.concrete assert expected == spec_from_file assert expected.eq_dag(spec_from_file) assert spec_from_file.concrete # Ensure that specs that come out "normal" are really normal. with open(spec_path) as spec_file: read_separately = Spec.from_yaml(spec_file.read()) # TODO: revise this when build deps are in dag_hash norm = read_separately.copy(deps=stored_deptypes) assert norm == spec_from_file assert norm.eq_dag(spec_from_file) # TODO: revise this when build deps are in dag_hash conc = read_separately.concretized().copy(deps=stored_deptypes) assert conc == spec_from_file assert conc.eq_dag(spec_from_file) assert expected.dag_hash() == spec_from_file.dag_hash() # Ensure directories are properly removed layout.remove_install_directory(spec) assert not os.path.isdir(install_dir) assert not os.path.exists(install_dir)