Python os.pathsep() Examples

The following are 30 code examples for showing how to use os.pathsep(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module os , or try the search function .

Example 1
Project: cherrypy   Author: cherrypy   File: wspbus.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _extend_pythonpath(env):
        """Prepend current working dir to PATH environment variable if needed.

        If sys.path[0] is an empty string, the interpreter was likely
        invoked with -m and the effective path is about to change on
        re-exec.  Add the current directory to $PYTHONPATH to ensure
        that the new process sees the same path.

        This issue cannot be addressed in the general case because
        Python cannot reliably reconstruct the
        original command line (http://bugs.python.org/issue14208).

        (This idea filched from tornado.autoreload)
        """
        path_prefix = '.' + os.pathsep
        existing_path = env.get('PYTHONPATH', '')
        needs_patch = (
            sys.path[0] == '' and
            not existing_path.startswith(path_prefix)
        )

        if needs_patch:
            env['PYTHONPATH'] = path_prefix + existing_path 
Example 2
Project: CAMISIM   Author: CAMI-challenge   File: configparserwrapper.py    License: Apache License 2.0 6 votes vote down vote up
def _get_full_path(value):
		"""
			convert string to absolute normpath.

			@param value: some string to be converted
			@type value: basestring

			@return: absolute normpath
			@rtype: basestring
		"""
		assert isinstance(value, basestring)
		parent_directory, filename = os.path.split(value)
		if not parent_directory and not os.path.isfile(value):
			for path in os.environ["PATH"].split(os.pathsep):
				path = path.strip('"')
				exe_file = os.path.join(path, filename)
				if os.path.isfile(exe_file):
					value = exe_file
					break
		value = os.path.expanduser(value)
		value = os.path.normpath(value)
		value = os.path.abspath(value)
		return value 
Example 3
Project: PyOptiX   Author: ozen   File: setup.py    License: MIT License 6 votes vote down vote up
def save_pyoptix_conf(nvcc_path, compile_args, include_dirs, library_dirs, libraries):
    try:
        config = ConfigParser()
        config.add_section('pyoptix')

        config.set('pyoptix', 'nvcc_path', nvcc_path)
        config.set('pyoptix', 'compile_args', os.pathsep.join(compile_args))
        config.set('pyoptix', 'include_dirs', os.pathsep.join(include_dirs))
        config.set('pyoptix', 'library_dirs', os.pathsep.join(library_dirs))
        config.set('pyoptix', 'libraries', os.pathsep.join(libraries))

        tmp = NamedTemporaryFile(mode='w+', delete=False)
        config.write(tmp)
        tmp.close()
        config_path = os.path.join(os.path.dirname(sys.executable), 'pyoptix.conf')
        check_call_sudo_if_fails(['cp', tmp.name, config_path])
        check_call_sudo_if_fails(['cp', tmp.name, '/etc/pyoptix.conf'])
        check_call_sudo_if_fails(['chmod', '644', config_path])
        check_call_sudo_if_fails(['chmod', '644', '/etc/pyoptix.conf'])
    except Exception as e:
        print("PyOptiX configuration could not be saved. When you use pyoptix.Compiler, "
              "nvcc path must be in PATH, OptiX library paths must be in LD_LIBRARY_PATH, and pyoptix.Compiler "
              "attributes should be set manually.") 
Example 4
Project: mx   Author: graalvm   File: select_jdk.py    License: GNU General Public License v2.0 6 votes vote down vote up
def get_shell_commands(args, jdk, extra_jdks):
    setvar_format = get_setvar_format(args.shell)
    shell_commands = StringIO()
    print(setvar_format % ('JAVA_HOME', jdk), file=shell_commands)
    if extra_jdks:
        print(setvar_format % ('EXTRA_JAVA_HOMES', os.pathsep.join(extra_jdks)), file=shell_commands)
    path = os.environ.get('PATH').split(os.pathsep)
    if path:
        jdk_bin = join(jdk, 'bin')
        old_java_home = os.environ.get('JAVA_HOME')
        replace = join(old_java_home, 'bin') if old_java_home else None
        if replace in path:
            path = [e if e != replace else jdk_bin for e in path]
        else:
            path = [jdk_bin] + path
        print(setvar_format % ('PATH', get_PATH_sep(args.shell).join(path)), file=shell_commands)
    return shell_commands.getvalue().strip() 
Example 5
Project: mx   Author: graalvm   File: select_jdk.py    License: GNU General Public License v2.0 6 votes vote down vote up
def apply_selection(args, jdk, extra_jdks):
    print('JAVA_HOME=' + jdk)
    if extra_jdks:
        print('EXTRA_JAVA_HOMES=' + os.pathsep.join(extra_jdks))

    if args.shell_file:
        with open(args.shell_file, 'w') as fp:
            print(get_shell_commands(args, jdk, extra_jdks), file=fp)
    else:
        env = get_suite_env_file(args.suite_path)
        if env:
            with open(env, 'a') as fp:
                print('JAVA_HOME=' + jdk, file=fp)
                if extra_jdks:
                    print('EXTRA_JAVA_HOMES=' + os.pathsep.join(extra_jdks), file=fp)
            print('Updated', env)
        else:
            print()
            print('To apply the above environment variable settings, eval the following in your shell:')
            print()
            print(get_shell_commands(args, jdk, extra_jdks)) 
Example 6
Project: pyspectator   Author: it-geeks-club   File: processor.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __get_processor_name(cls):
        cpu_name = None
        os_name = platform.system()
        if os_name == 'Windows':
            cpu_name = platform.processor()
        elif os_name == 'Darwin':
            os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin'
            command = ('sysctl', '-n', 'machdep.cpu.brand_string')
            output = subprocess.check_output(command)
            if output:
                cpu_name = output.decode().strip()
        elif os_name == 'Linux':
            all_info = subprocess.check_output('cat /proc/cpuinfo', shell=True)
            all_info = all_info.strip().split(os.linesep.encode())
            for line in all_info:
                line = line.decode()
                if 'model name' not in line:
                    continue
                cpu_name = re.sub('.*model name.*:', str(), line, 1).strip()
                break
        return cpu_name 
Example 7
Project: maya-command-search   Author: robertjoosten   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
def findSearchIcon():
    """
    Loop over all paths in the XBMLANGPATH variable and see if custom icon
    can be found, if this is not the case a maya default one will be returned.
    
    :return: CMD search icon.
    :rtype: QIcon
    """
    # construct all icon paths
    paths = []
    if os.environ.get("XBMLANGPATH"):
        paths = os.environ.get("XBMLANGPATH").split(os.pathsep)
    paths.append(os.path.join(os.path.split(__file__)[0], "icons"))

    # find icon
    for path in paths:
        filepath = os.path.join(path, "rjCMDSearch.png")
        if os.path.exists(filepath):
            return QIcon(filepath)
            
    return QIcon(":/cmdWndIcon.png")  
    
# ---------------------------------------------------------------------------- 
Example 8
Project: toonapilib   Author: costastf   File: core_library.py    License: MIT License 6 votes vote down vote up
def get_binary_path(executable, logging_level='INFO'):
    """Gets the software name and returns the path of the binary."""
    if sys.platform == 'win32':
        if executable == 'start':
            return executable
        executable = executable + '.exe'
        if executable in os.listdir('.'):
            binary = os.path.join(os.getcwd(), executable)
        else:
            binary = next((os.path.join(path, executable)
                           for path in os.environ['PATH'].split(os.pathsep)
                           if os.path.isfile(os.path.join(path, executable))), None)
    else:
        venv_parent = get_venv_parent_path()
        venv_bin_path = os.path.join(venv_parent, '.venv', 'bin')
        if not venv_bin_path in os.environ.get('PATH'):
            if logging_level == 'DEBUG':
                print(f'Adding path {venv_bin_path} to environment PATH variable')
            os.environ['PATH'] = os.pathsep.join([os.environ['PATH'], venv_bin_path])
        binary = shutil.which(executable)
    return binary if binary else None 
Example 9
Project: py-solc   Author: ethereum   File: install_solc.py    License: MIT License 6 votes vote down vote up
def is_executable_available(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath = os.path.dirname(program)
    if fpath:
        if is_exe(program):
            return True
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return True

    return False 
Example 10
Project: py-solc   Author: ethereum   File: filesystem.py    License: MIT License 6 votes vote down vote up
def is_executable_available(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath = os.path.dirname(program)
    if fpath:
        if is_exe(program):
            return True
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return True

    return False 
Example 11
Project: py-solc   Author: ethereum   File: install.py    License: MIT License 6 votes vote down vote up
def is_executable_available(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath = os.path.dirname(program)
    if fpath:
        if is_exe(program):
            return True
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return True

    return False 
Example 12
Project: recipes-py   Author: luci   File: main.py    License: Apache License 2.0 6 votes vote down vote up
def _strip_virtualenv():
  # Prune all evidence of VPython/VirtualEnv out of the environment. This means
  # that recipe engine 'unwraps' vpython VirtualEnv path/env manipulation.
  # Invocations of `python` from recipes should never inherit the recipe
  # engine's own VirtualEnv.

  # Set by VirtualEnv, no need to keep it.
  os.environ.pop('VIRTUAL_ENV', None)

  # Set by VPython, if recipes want it back they have to set it explicitly.
  os.environ.pop('PYTHONNOUSERSITE', None)

  # Look for "activate_this.py" in this path, which is installed by VirtualEnv.
  # This mechanism is used by vpython as well to sanitize VirtualEnvs from
  # $PATH.
  os.environ['PATH'] = os.pathsep.join([
    p for p in os.environ.get('PATH', '').split(os.pathsep)
    if not os.path.isfile(os.path.join(p, 'activate_this.py'))
  ]) 
Example 13
Project: llvm-zorg   Author: llvm   File: monorepo_build.py    License: Apache License 2.0 6 votes vote down vote up
def static_analyzer_benchmarks_builder():
    """Run static analyzer benchmarks"""
    header("Static Analyzer Benchmarks")

    benchmark_script = conf.workspace + "/utils-analyzer/SATestBuild.py"
    benchmarks_dir = conf.workspace + "/test-suite-ClangAnalyzer/"

    compiler_bin_dir = conf.workspace + "/host-compiler/bin/"
    scanbuild_bin_dir = conf.workspace + "/tools-scan-build/bin/"

    old_path = os.environ.get("PATH", "")
    env = dict(os.environ, PATH=compiler_bin_dir + os.pathsep +
                                scanbuild_bin_dir + os.pathsep +
                                old_path)

    benchmark_cmd = [benchmark_script,
                     "--strictness", "0"
                     ]
    run_cmd(benchmarks_dir, benchmark_cmd, env=env)

    footer() 
Example 14
Project: llvm-zorg   Author: llvm   File: build.py    License: Apache License 2.0 6 votes vote down vote up
def static_analyzer_benchmarks_builder():
    """Run static analyzer benchmarks"""
    header("Static Analyzer Benchmarks")

    benchmark_script = conf.workspace + "/utils-analyzer/SATestBuild.py"
    benchmarks_dir = conf.workspace + "/test-suite-ClangAnalyzer/"

    compiler_bin_dir = conf.workspace + "/host-compiler/bin/"
    scanbuild_bin_dir = conf.workspace + "/tools-scan-build/bin/"

    old_path = os.environ.get("PATH", "")
    env = dict(os.environ, PATH=compiler_bin_dir + os.pathsep +
                                scanbuild_bin_dir + os.pathsep +
                                old_path)

    benchmark_cmd = [benchmark_script,
                     "--strictness", "0"
                     ]
    run_cmd(benchmarks_dir, benchmark_cmd, env=env)

    footer() 
Example 15
Project: core   Author: getavalon   File: compat.py    License: MIT License 6 votes vote down vote up
def remove_googleapiclient():
    """Check if the compatibility must be maintained

    The Maya 2018 version tries to import the `http` module from
    Maya2018/plug-ins/MASH/scripts/googleapiclient/http.py in stead of the
    module from six.py. This import conflict causes a crash Avalon's publisher.
    This is due to Autodesk adding paths to the PYTHONPATH environment variable
    which contain modules instead of only packages.
    """

    keyword = "googleapiclient"

    # reconstruct python paths
    python_paths = os.environ["PYTHONPATH"].split(os.pathsep)
    paths = [path for path in python_paths if keyword not in path]
    os.environ["PYTHONPATH"] = os.pathsep.join(paths) 
Example 16
Project: core   Author: getavalon   File: lib.py    License: MIT License 6 votes vote down vote up
def which(program):
    """Locate `program` in PATH

    Arguments:
        program (str): Name of program, e.g. "python"

    """

    def is_exe(fpath):
        if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
            return True
        return False

    for path in os.environ["PATH"].split(os.pathsep):
        for ext in os.getenv("PATHEXT", "").split(os.pathsep):
            fname = program + ext.lower()
            abspath = os.path.join(path.strip('"'), fname)

            if is_exe(abspath):
                return abspath

    return None 
Example 17
Project: core   Author: getavalon   File: lib.py    License: MIT License 6 votes vote down vote up
def which_app(app):
    """Locate `app` in PATH

    Arguments:
        app (str): Name of app, e.g. "python"

    """

    for path in os.environ["PATH"].split(os.pathsep):
        fname = app + ".toml"
        abspath = os.path.join(path.strip('"'), fname)

        if os.path.isfile(abspath):
            return abspath

    return None 
Example 18
Project: toil-scripts   Author: BD2KGenomics   File: rnaseq_unc_tcga_versions.py    License: Apache License 2.0 6 votes vote down vote up
def which(program):
    import os

    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None 
Example 19
Project: toil-scripts   Author: BD2KGenomics   File: rnaseq_unc_pipeline.py    License: Apache License 2.0 6 votes vote down vote up
def which(program):
    import os

    def is_exe(f):
        return os.path.isfile(f) and os.access(f, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None 
Example 20
Project: pyspelling   Author: facelessuser   File: util.py    License: MIT License 6 votes vote down vote up
def which(executable):
    """See if executable exists."""

    location = None
    if os.path.basename(executable) != executable:
        if os.path.isfile(executable):
            location = executable
    else:
        paths = [x for x in os.environ["PATH"].split(os.pathsep) if not x.isspace()]
        paths.extend([x for x in os.environ.get("TOX_SPELL_PATH", "").split(os.pathsep) if not x.isspace()])
        for path in paths:
            exe = os.path.join(path, executable)
            if os.path.isfile(exe):
                location = exe
                break
    return location 
Example 21
Project: tox   Author: tox-dev   File: conf.py    License: MIT License 6 votes vote down vote up
def generate_draft_news():
    home = "https://github.com"
    issue = "{}/issue".format(home)
    fragments_path = ROOT_SRC_TREE_DIR / "docs" / "changelog"
    for pattern, replacement in (
        (r"[^`]@([^,\s]+)", r"`@\1 <{}/\1>`_".format(home)),
        (r"[^`]#([\d]+)", r"`#pr\1 <{}/\1>`_".format(issue)),
    ):
        for path in fragments_path.glob("*.rst"):
            path.write_text(re.sub(pattern, replacement, path.read_text()))
    env = os.environ.copy()
    env["PATH"] += os.pathsep.join(
        [os.path.dirname(sys.executable)] + env["PATH"].split(os.pathsep),
    )
    changelog = subprocess.check_output(
        ["towncrier", "--draft", "--version", "DRAFT"], cwd=str(ROOT_SRC_TREE_DIR), env=env,
    ).decode("utf-8")
    if "No significant changes" in changelog:
        content = ""
    else:
        note = "*Changes in master, but not released yet are under the draft section*."
        content = "{}\n\n{}".format(note, changelog)
    (ROOT_SRC_TREE_DIR / "docs" / "_draft.rst").write_text(content) 
Example 22
Project: tox   Author: tox-dev   File: common.py    License: MIT License 6 votes vote down vote up
def base_discover(envconfig):
    base_python = envconfig.basepython
    spec = PythonSpec.from_name(base_python)

    # 1. check passed in discover elements
    discovers = envconfig.config.option.discover
    if not discovers:
        discovers = os.environ.get(str("TOX_DISCOVER"), "").split(os.pathsep)
    for discover in discovers:
        if os.path.exists(discover):
            cur_spec = exe_spec(discover, envconfig.basepython)
            if cur_spec is not None and cur_spec.satisfies(spec):
                return spec, cur_spec.path

    # 2. check current
    if spec.name is not None and CURRENT.satisfies(spec):
        return spec, CURRENT.path

    return spec, None 
Example 23
Project: tox   Author: tox-dev   File: test_interpreters.py    License: MIT License 6 votes vote down vote up
def test_find_alias_on_path(monkeypatch, tmp_path, mocker):
    reporter.update_default_reporter(Verbosity.DEFAULT, Verbosity.DEBUG)
    magic = tmp_path / "magic{}".format(os.path.splitext(sys.executable)[1])
    os.symlink(sys.executable, str(magic))
    monkeypatch.setenv(
        str("PATH"),
        os.pathsep.join([str(tmp_path)] + os.environ.get(str("PATH"), "").split(os.pathsep)),
    )

    class envconfig:
        basepython = "magic"
        envname = "pyxx"
        config = mocker.MagicMock()
        config.return_value.option.return_value.discover = []

    detected = py.path.local.sysfind("magic")
    assert detected

    t = tox_get_python_executable(envconfig).lower()
    assert t == str(magic).lower() 
Example 24
Project: recruit   Author: Frank-qlu   File: system_info.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example 25
Project: CAMISIM   Author: CAMI-challenge   File: validator.py    License: Apache License 2.0 5 votes vote down vote up
def get_full_path(value):
		"""
			Get the normalized absolute path.

			@attention:

			@param value: directory path or file path
			@type value: basestring

			@return: full path
			@rtype: str
		"""
		assert isinstance(value, basestring)

		parent_directory, filename = os.path.split(value)

		if not parent_directory and not os.path.isfile(value):
			for path in os.environ["PATH"].split(os.pathsep):
				path = path.strip('"')
				exe_file = os.path.join(path, filename)
				if os.path.isfile(exe_file):
					value = exe_file
					break

		value = os.path.expanduser(value)
		value = os.path.normpath(value)
		value = os.path.abspath(value)
		return value 
Example 26
Project: CAMISIM   Author: CAMI-challenge   File: configparserwrapper.py    License: Apache License 2.0 5 votes vote down vote up
def _get_full_path(value):
        """
            convert string to absolute normpath.

            @param value: some string to be converted
            @type value: str

            @return: absolute normpath
            @rtype: str
        """
        assert isinstance(value, str), "Invalid argument, 'value' must be string, but got: '{}'".format(type(value))

        parent_directory, filename = os.path.split(value)

        if not parent_directory and not os.path.isfile(value):
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, filename)
                if os.path.isfile(exe_file):
                    value = exe_file
                    break

        value = os.path.expanduser(value)
        value = os.path.normpath(value)
        value = os.path.abspath(value)
        return value 
Example 27
Project: video2commons   Author: toolforge   File: transcodejob.py    License: GNU General Public License v3.0 5 votes vote down vote up
def remove_ffmpeg_log_files(self):
        """Remove any log files."""
        path = self.get_target_path()
        dir = os.path.dirname(path.rstrip(os.pathsep))
        if os.path.isdir(dir):
            for file in os.listdir(dir):
                log_path = os.path.abspath(dir + "/" + file)
                ext = file.split('.')[-1]
                if ext == 'log' and log_path.startswith(path):
                    os.unlink(log_path) 
Example 28
Project: PyOptiX   Author: ozen   File: setup.py    License: MIT License 5 votes vote down vote up
def populate_ld_paths():
    global ld_paths
    ld_paths = []
    for line in check_output_sudo_if_fails(['ldconfig', '-vNX']).decode('utf8').splitlines():
        if line.startswith('/'):
            ld_paths.append(line[:line.find(':')])
    if "LD_LIBRARY_PATH" in os.environ:
        ld_paths.extend(os.environ["LD_LIBRARY_PATH"].split(os.pathsep)) 
Example 29
Project: PyOptiX   Author: ozen   File: setup.py    License: MIT License 5 votes vote down vote up
def search_on_path(filenames):
    filenames = list(filenames)

    for path in os.environ["PATH"].split(os.pathsep):
        for filename in filenames:
            if os.path.exists(os.path.join(path, filename)):
                return os.path.abspath(os.path.join(path, filename)) 
Example 30
Project: QCElemental   Author: MolSSI   File: importing.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def which(
    command: str, *, return_bool: bool = False, raise_error: bool = False, raise_msg: str = None, env: str = None
) -> Union[bool, None, str]:
    """Test to see if a command is available.

    Returns
    -------
    str or None
        By default, returns command path if command found or `None` if not.
        Environment is $PATH or `os.pathsep`-separated `env`, less any None values.
    bool
        When `return_bool=True`, returns whether or not found.

    Raises
    ------
    ModuleNotFoundError
        When `raises_error=True` and command not found. Raises generic message plus any `raise_msg`.

    """
    if env is None:
        lenv = {"PATH": os.pathsep + os.environ.get("PATH", "") + os.path.dirname(sys.executable)}
    else:
        lenv = {"PATH": os.pathsep.join([os.path.abspath(x) for x in env.split(os.pathsep) if x != ""])}
    lenv = {k: v for k, v in lenv.items() if v is not None}

    ans = shutil.which(command, mode=os.F_OK | os.X_OK, path=lenv["PATH"])

    if raise_error and ans is None:
        raise ModuleNotFoundError(
            f"Command '{command}' not found in envvar PATH.{' ' + raise_msg if raise_msg else ''}"
        )

    if return_bool:
        return bool(ans)
    else:
        return ans