def from_dict(clazz, *args, **kwds): """Loads WMT environment variables from arguments. Parameters ---------- *args Variable length argument list. *kwds Arbitrary keyword arguments. Returns ------- WmtEnvironment A WmtEnvironment instance. """ env = clazz() d = dict(*args, **kwds) babel = Babel(babel_config=d['babel_config'], cca_spec_babel_config=d['cca_spec_babel_config']) python = Python(python=d['python']) wmt_prefix = d['wmt_prefix'] components_prefix = d['components_prefix'] env._env.update({ 'CURL': d['curl'], 'TAIL': d['tail'], 'BASH': d['bash'], 'PYTHONPATH': pathsep.join([ python.site_packages(), path.join(python.prefix, 'lib', python.version), python.site_packages(components_prefix), python.site_packages(babel.prefix), path.join(babel.libs, python.version, 'site-packages'), ]), 'LD_LIBRARY_PATH': pathsep.join([ path.join(python.prefix, 'lib'), path.join(components_prefix, 'lib'), path.join(wmt_prefix, 'lib'), path.join(babel.prefix, 'lib'), ]), 'PATH': pathsep.join([ path.join(python.prefix, 'bin'), '/usr/local/bin', '/usr/bin', '/bin', ]), 'CLASSPATH': pathsep.join([ path.join(components_prefix, 'lib', 'java'), ]), 'SIDL_DLL_PATH': ';'.join([ path.join(components_prefix, 'share', 'cca'), ]), }) env._env['LD_RUN_PATH'] = env['LD_LIBRARY_PATH'] return env
def run(self): """ Build the specified files """ from ..core import JDKManager, Macro sourcepath = pathsep.join(StateProperty().get_source_folders()) dependencies = ["."] + [ dependency[0] for dependency in DependencyManager().get_dependencies() ] classpath = pathsep.join(dependencies) output_location = Macro().parse(Settings().get("build_output_location")) executable = JDKManager().get_executable("build") if not executable: return build_script = "%s -sourcepath %s -classpath %s" % ( shlex.quote(executable), shlex.quote(sourcepath), shlex.quote(classpath) ) if output_location: if isfile(output_location): return elif not isdir(output_location): try: makedirs(output_location) except: pass build_script += " -d %s" % (shlex.quote(output_location)) while self.running and self.files: self.builds += 1 parallel_builds = Settings().get("parallel_builds") if parallel_builds > 0: files = self.files[:parallel_builds] self.files = self.files[parallel_builds:] else: files = self.files self.files = [] file_list = " ".join([ shlex.quote(filename) for filename in files ]) actual_build_script = build_script + " %s" % (file_list) build_args = Settings().get("build_arguments", "") if build_args: actual_build_script += " " + build_args shell = GenericSilentShell( actual_build_script, lambda elapse_time, data, ret, params: self.on_build_done( len(files), elapse_time, data, ret ) ) shell.set_cwd(Macro().parse(Settings().get("build_location"))) shell.start() while self.running and self.builds > 0: pass
def cmd(self): """ Returns the command to be used by SublimeLinter """ sourcepath = pathsep.join(StateProperty().get_source_folders()) dependencies = StateProperty().get_source_folders() + [ dependency[0] for dependency in DependencyManager().get_dependencies() ] output_location = Macro().parse( Settings().get("build_output_location")) if output_location: if isfile(output_location): return elif not isdir(output_location): try: makedirs(output_location) except: pass output_location = ["-d", output_location] else: output_location = [] if dependencies: classpath = ["-classpath", pathsep.join(dependencies)] else: classpath = [] return [ JDKManager().get_executable("lint") or "javac", "-sourcepath", sourcepath ] + classpath + output_location + [ sublime.active_window().active_view().file_name(), Settings().get("linter_arguments", "") ]
def setup_3rdparty(lib): # Normalize library path for name, path in lib.items(): lib[name] = realpath(expanduser(path)) # Setup environment variable environ['LD_PRELOAD'] = pathsep.join( filter(None, [ getenv('LD_PRELOAD'), os.path.join(lib['gcc'], "libgfortran.so"), os.path.join(lib['gcc'], "libgcc_s.so"), os.path.join(lib['gcc'], "libstdc++.so"), os.path.join(lib['gcc'], "libgomp.so"), ])) environ['PYTHONPATH'] = pathsep.join( filter(None, [ getenv('PYTHON'), os.path.join(lib['libsvm'], "python"), os.path.join(lib['liblinear'], "python"), os.path.join(lib['spams-python']), ])) environ['MATLABPATH'] = pathsep.join( filter(None, [ getenv('MATLABPATH'), os.path.join(lib['liblinear'], "matlab"), os.path.join(lib['libsvm'], "matlab"), os.path.join(lib['spams-matlab'], "build"), os.path.join(lib['spams-matlab'], "src_release"), os.path.join(lib['spams-matlab'], "test_release"), ])) return lib
def cmd(self): """ Returns the command to be used by SublimeLinter """ sourcepath = pathsep.join(StateProperty().get_source_folders()) dependencies = StateProperty().get_source_folders() + [ dependency[0] for dependency in DependencyManager().get_dependencies() ] output_location = Macro().parse(Settings().get("build_output_location")) if output_location: if isfile(output_location): return elif not isdir(output_location): try: makedirs(output_location) except: pass output_location = ["-d", output_location] else: output_location = [] if dependencies: classpath = ["-classpath", pathsep.join(dependencies)] else: classpath = [] return [ JDKManager().get_executable("lint") or "javac", "-sourcepath", sourcepath ] + classpath + output_location + [ sublime.active_window().active_view().file_name(), Settings().get("linter_arguments", "") ]
def CheckOde(localOdeInstallDir): ldLibraryPath = environ.get('LD_LIBRARY_PATH') if ldLibraryPath is None: ldLibraryPath = [] else: ldLibraryPath = ldLibraryPath.split(pathsep) ldLibraryPath.append(path.join(localOdeInstallDir, 'lib')) environ['LD_LIBRARY_PATH'] = pathsep.join(ldLibraryPath) environ['LIBRARY_PATH'] = pathsep.join(ldLibraryPath) return find_library('ode') is not None
class EnvVarTestParamDataComponents: TAlias_param_types = Final[list[type]] TAlias_param_data_by_type = Final[dict[type:list[Any]]] __TAlias_param_data_str = Final[list[str]] __TAlias_param_data_path = Final[list[PurePath]] __TAlias_invalid_param_data_none = Final[list[type[None]]] __TAlias_invalid_param_data_int = Final[list[type[int]]] __TAlias_invalid_param_data_bool = Final[list[type[bool]]] __TAlias_invalid_param_data_float = Final[list[type[float]]] __TAlias_invalid_joined_values_data_path = Final[list[type[PurePath]]] valid_key_data_str: __TAlias_param_data_str = [ '', 'key', 'test', '123', 'KEY', 'key_', '_key', 'z-abc', 'space space' ] valid_values_windows_path_data_str: __TAlias_param_data_str = [ 'C:\\', 'C:\\Users', 'C:\\Users\\', 'C:\\Users\\Public', 'C:\\Users\\Public\\', 'C:\\Users\\Public\\wow.doge', '.\\', '.\\Users', '.\\Users\\', '.\\Users\\Public', '.\\Users\\Public\\', '.\\Users\\Public\\wow.doge' ] valid_values_unix_path_data_str: __TAlias_param_data_str = [ '/usr', '/usr/', '/usr/tmp', '/usr/tmp/', '~' ] valid_values_data_str: __TAlias_param_data_str = \ valid_key_data_str + \ [f'%{key_str}%' for key_str in valid_key_data_str] + \ valid_values_windows_path_data_str + \ valid_values_unix_path_data_str + \ ['val1;', 'val1;val2', 'val1;val2;', 'many_postfix_sep;;;;', ';;;;;many_prefix_sep'] valid_values_data_path: __TAlias_param_data_path = \ [PurePath(values_path_str) for values_path_str in valid_values_windows_path_data_str] + \ [PurePath(values_path_str) for values_path_str in valid_values_unix_path_data_str] valid_joined_values_data_str: __TAlias_param_data_str = [ pathsep.join(valid_key_data_str), pathsep.join(valid_values_windows_path_data_str), pathsep.join(valid_values_unix_path_data_str) ] invalid_param_data_none: __TAlias_invalid_param_data_none = [None] invalid_param_data_int: __TAlias_invalid_param_data_int = [ -52323, -7, -10, -5, -1, 0, 1, 5, 7, 10, 25893 ] invalid_param_data_bool: __TAlias_invalid_param_data_bool = [False, True] invalid_param_data_float: __TAlias_invalid_param_data_float = [ -0.1, -0.000001, -0.4123, -0.00546, -10.9023, -345.245, 0.0, 0.1, 0.000001, 0.4123, 0.00546, 10.9023, 345.245 ] invalid_joined_values_data_path: __TAlias_invalid_joined_values_data_path = valid_values_data_path
def run(self): """ Build the specified files """ from ..core import JDKManager, Macro sourcepath = pathsep.join(StateProperty().get_source_folders()) dependencies = ["."] + [ dependency[0] for dependency in DependencyManager().get_dependencies() ] classpath = pathsep.join(dependencies) output_location = Macro().parse( Settings().get("build_output_location")) executable = JDKManager().get_executable("build") if not executable: return build_script = "%s -sourcepath %s -classpath %s" % (shlex.quote( executable), shlex.quote(sourcepath), shlex.quote(classpath)) if output_location: if isfile(output_location): return elif not isdir(output_location): try: makedirs(output_location) except: pass build_script += " -d %s" % (shlex.quote(output_location)) while self.running and self.files: self.builds += 1 parallel_builds = Settings().get("parallel_builds") if parallel_builds > 0: files = self.files[:parallel_builds] self.files = self.files[parallel_builds:] else: files = self.files self.files = [] file_list = " ".join([shlex.quote(filename) for filename in files]) actual_build_script = build_script + " %s" % (file_list) build_args = Settings().get("build_arguments", "") if build_args: actual_build_script += " " + build_args shell = GenericSilentShell( actual_build_script, lambda elapse_time, data, ret, params: self.on_build_done( len(files), elapse_time, data, ret)) shell.set_cwd(Macro().parse(Settings().get("build_location"))) shell.start() while self.running and self.builds > 0: pass
def _spawn(script, outputFD): """ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.py') @type script: C{str} @rtype: L{StartStopProcessProtocol} """ pyExe = FilePath(sys.executable).asBytesMode().path env = bytesEnviron() env[b"PYTHONPATH"] = FilePath( pathsep.join(sys.path)).asBytesMode().path sspp = StartStopProcessProtocol() reactor.spawnProcess( sspp, pyExe, [ pyExe, FilePath(__file__).sibling(script + ".py").asBytesMode().path, intToBytes(outputFD), ], env=env, childFDs={0: "w", 1: "r", 2: "r", outputFD: outputFD} ) return sspp
async def cont(path: PurePath, bin: str, pkg: ScriptSpec) -> _SortOfMonoid: env = { "PATH": pathsep.join(( normcase(INSTALL_SCRIPTS_DIR), environ["PATH"], )), "ARCH": sys.machine, "OS": sys.system, "BIN": normcase(BIN_DIR / bin), "LIB": normcase(LIB_DIR / bin), } p = await call( path, env={ **env, **pkg.env }, cwd=TMP_DIR, check_returncode=set(), ) return (("", p), )
def _build_paths(self, name, spec_path_lists, exists): """ Given an environment variable name and specified paths, return a pathsep-separated string of paths containing unique, extant, directories from those paths and from the environment variable. Raise an error if no paths are resolved. Parameters ---------- name: str Environment variable name spec_path_lists: list of str Paths exists: bool It True, only return existing paths. Return ------ str Pathsep-separated paths """ # flatten spec_path_lists spec_paths = itertools.chain.from_iterable(spec_path_lists) env_paths = environ.get(name, '').split(pathsep) paths = itertools.chain(spec_paths, env_paths) extant_paths = list(filter(isdir, paths)) if exists else paths if not extant_paths: msg = "%s environment variable is empty" % name.upper() raise distutils.errors.DistutilsPlatformError(msg) unique_paths = self._unique_everseen(extant_paths) return pathsep.join(unique_paths)
def _spawn(script, outputFD): """ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.Dockerfile.bak') @type script: C{str} @rtype: L{StartStopProcessProtocol} """ pyExe = FilePath(sys.executable).asBytesMode().path env = bytesEnviron() env[b"PYTHONPATH"] = FilePath(pathsep.join(sys.path)).asBytesMode().path sspp = StartStopProcessProtocol() reactor.spawnProcess( sspp, pyExe, [ pyExe, FilePath(__file__).sibling(script + ".Dockerfile.bak").asBytesMode().path, intToBytes(outputFD), ], env=env, childFDs={ 0: "w", 1: "r", 2: "r", outputFD: outputFD }) return sspp
def _spawn(script, outputFD): """ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.py') @type script: C{str} @rtype: L{StartStopProcessProtocol} """ pyExe = FilePath(sys.executable).asTextMode().path env = dict(os.environ) env["PYTHONPATH"] = FilePath(pathsep.join(sys.path)).asTextMode().path sspp = StartStopProcessProtocol() reactor.spawnProcess( sspp, pyExe, [ pyExe, FilePath(__file__).sibling(script + ".py").asTextMode().path, b"%d" % (outputFD, ), ], env=env, childFDs={ 0: "w", 1: "r", 2: "r", outputFD: outputFD }, ) return sspp
def save_plot_from_file(filename, stat_name): """ Saves a plot of a given stat from the stats file. :param filename: a full specified path to a .csv stats file. :param stat_name: the stat of interest for plotting. :return: Nothing. """ # Read in the data data = pd.read_csv(filename, sep="\t") try: stat = list(data[stat_name]) except KeyError: s = "utilities.stats.save_plots.save_plot_from_file\n" \ "Error: stat %s does not exist" % stat_name raise Exception(s) # Set up the figure. fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) # Plot the data. ax1.plot(stat) # Plot title. plt.title(stat_name) # Get save path save_path = pathsep.join(filename.split(pathsep)[:-1]) # Save plot and close. plt.savefig(path.join(save_path, (stat_name + '.pdf'))) plt.close()
def save_plot_from_file(filename, stat_name): """ Saves a plot of a given stat from the stats file. :param filename: a full specified path to a .csv stats file. :param stat_name: the stat of interest for plotting. :return: Nothing. """ # Read in the data data = pd.read_csv(filename, sep="\t") try: stat = list(data[stat_name]) except KeyError: s = "utilities.stats.save_plots.save_plot_from_file\n" \ "Error: stat %s does not exist" % stat_name raise Exception(s) # Plot the data fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.plot(stat) plt.title(stat_name) # Get save path save_path = pathsep.join(filename.split(pathsep)[:-1]) # Save plot plt.savefig(path.join(save_path, (stat_name + '.pdf'))) plt.close()
def setup_path(root, paths): paths = [os.path.join(root, path) for path in paths] paths.append(root) if getenv('MATLABPATH') is not None: paths.insert(0, getenv('MATLABPATH')) environ['MATLABPATH'] = pathsep.join(paths)
def call_brazil_path(command): # add some apollo-specific paths paths = pathsep.join([ environ["PATH"], environ["HOME"] + '/.toolbox/bin', "/apollo/env/BrazilCLI/bin", "/apollo/env/SDETools/bin" ]) # Check $PATH for the tool brazil_tool_path = distutils.spawn.find_executable("brazil-path", path=paths) if brazil_tool_path is None: raise FileNotFoundError("Failed to find brazil-path in any of " + paths) print("Using brazil-path located at " + brazil_tool_path + " for " + command) # defaults to locale.getpreferredencoding(False) by setting universal_newlines=True proc = subprocess.Popen( [brazil_tool_path, command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, # if universal_newlines=True is removed, the output will be in bytes rather than an encoded str. universal_newlines=True) (brazil_path_out, err) = proc.communicate() if proc.returncode != 0: print("Error while determining the current workspace-root \ from brazil-path \nOutput: %s \nError: %s" % (brazil_path_out, err)) return None else: return brazil_path_out.strip()
def remove_value(name, values): paths = get_key(name).split(pathsep) remove(paths, '') for value in values: paths = unique(paths) remove(paths, value) set_key(name, pathsep.join(paths))
def StripPath(path): collected = [] for p in path.split(pathsep): rp = realpath(p) if exists(rp) and isdir(rp): if len(listdir(rp)) != 0: collected.append(p) return pathsep.join(collected)
def _overwrite_environment(self, environment): # type: (MutableMapping[str, str]) -> None if not self._overwrite: return for variable, overwrite_values in self._overwrite.items(): overwrite_value = pathsep.join(overwrite_values) environment[variable] = overwrite_value
def prepend_value(name, values): paths = get_key(name).split(pathsep) for value in values: remove(paths, '') paths = unique(paths) remove(paths, value) paths.insert(0, value) set_key(name, pathsep.join(paths))
def setup_env(): from os import environ as env, pathsep from os.path import join conda_path = get_conda_path() assert conda_path is not None conda_path = [conda_path, join(conda_path, "Scripts")] env["PATH"] = pathsep.join(conda_path) + pathsep + env["PATH"]
def __GetDrawstuffLib(): ldLibraryPath = environ.get('LD_LIBRARY_PATH') if ldLibraryPath is None: ldLibraryPath = [] else: ldLibraryPath = ldLibraryPath.split(pathsep) localOdeInstallLibDir = path.join(environ.get('HOME'), '.odepy', 'lib') ldLibraryPath.append(localOdeInstallLibDir) environ['LD_LIBRARY_PATH'] = pathsep.join(ldLibraryPath) environ['LIBRARY_PATH'] = pathsep.join(ldLibraryPath) drawstuffLibName = find_library('drawstuff') if drawstuffLibName is None: raise DrawstuffPyError('drawstuff library not found.') if path.exists(path.join(localOdeInstallLibDir, drawstuffLibName)): return CDLL(path.join(localOdeInstallLibDir, drawstuffLibName), use_errno=True) return CDLL(drawstuffLibName, use_errno=True)
def from_dict(clazz, *args, **kwds): env = clazz() d = dict(*args, **kwds) babel = Babel(babel_config=d['babel_config'], cca_spec_babel_config=d['cca_spec_babel_config']) python = Python(python=d['python']) wmt_prefix = d['wmt_prefix'] components_prefix = d['components_prefix'] env._env.update({ 'CURL': d['curl'], 'TAIL': d['tail'], 'BASH': d['bash'], 'PYTHONPATH': pathsep.join([ python.site_packages(), path.join(python.prefix, 'lib', python.version), python.site_packages(components_prefix), python.site_packages(babel.prefix), path.join(babel.libs, python.version, 'site-packages'), ]), 'LD_LIBRARY_PATH': pathsep.join([ path.join(python.prefix, 'lib'), path.join(components_prefix, 'lib'), path.join(wmt_prefix, 'lib'), path.join(babel.prefix, 'lib'), ]), 'PATH': pathsep.join([ path.join(python.prefix, 'bin'), '/usr/local/bin', '/usr/bin', '/bin', ]), 'CLASSPATH': pathsep.join([ path.join(components_prefix, 'lib', 'java'), ]), 'SIDL_DLL_PATH': ';'.join([ path.join(components_prefix, 'share', 'cca'), ]), }) env._env['LD_RUN_PATH'] = env['LD_LIBRARY_PATH'] return env
def _load_library(): # We assume the DLL is next to the driver, the build (setup.py) should take # care of it (it currently doesn't) old_path = environ["PATH"] environ["PATH"] = pathsep.join([environ["PATH"], abspath(dirname(__file__))]) try: return ctypes.cdll.LoadLibrary("InternetExplorerDriver.dll") finally: environ["PATH"] = old_path
def _create_python_path(self): python_path = pathsep.join(sys.path) if "PYTHONPATH" in environ: python_path += pathsep + environ["PYTHONPATH"] python_path += pathsep + abspath(join("..", "hostexpand", "src", "main", "python")) python_path += pathsep + abspath(join("src", "main", "python")) return python_path
def update_python_environment_with(module_path): from os.path import dirname module_folder = dirname(module_path) from sys import path if not (module_folder in path): path.insert(0, module_folder) from os import environ, pathsep, putenv python_path = pathsep.join(path) environ["PYTHONPATH"] = python_path putenv("PYTHONPATH", python_path) return
def _create_python_path(self): python_path = pathsep.join(sys.path) if 'PYTHONPATH' in environ: python_path += pathsep + environ['PYTHONPATH'] python_path += pathsep + \ abspath(join('..', 'hostexpand', 'src', 'main', 'python')) python_path += pathsep + abspath(join('src', 'main', 'python')) return python_path
def _check_linter_path(): if getattr(_check_linter_path, 'skip', False): return LOCAL_BIN = '/usr/local/bin' PATH = environ['PATH'].split(pathsep) if platform == 'posix' and LOCAL_BIN not in PATH: environ['PATH'] = pathsep.join([LOCAL_BIN] + PATH) _check_linter_path.skip = True
def _append_run_path(): """ 添加Qt的环境变量\n :return: """ if getattr(sys, 'frozen', False): path_list = [sys._MEIPASS] _main_app_path = path.dirname(sys.executable) path_list.append(_main_app_path) environ["PATH"] += pathsep + pathsep.join(path_list)
def has_valid_kerberos_ticket(): paths = pathsep.join([ environ["PATH"], environ["HOME"] + "/.toolbox/bin", "/usr/kerberos/bin", "/usr/bin" ]) klist_path = distutils.spawn.find_executable("klist", path=paths) if klist_path is None: raise FileNotFoundError("Failed to find klist in any of " + paths) print("using klist from " + str(klist_path)) return True if subprocess.call([klist_path, "-s"]) == 0 else False
def main(argv=None): from os.path import join, isfile, dirname from tempfile import mkstemp from os import chdir, close, environ, pathsep import os # So we can look kill up later from subprocess import Popen, call import sys import signal from time import sleep from optparse import OptionParser argv = argv or sys.argv parser = OptionParser("%prog") opts, args = parser.parse_args(argv[1:]) if args: parser.error("wrong number of arguments") # Will exit chdir(dirname(__file__)) jarfile = join("..", "..", "..", "build", "selenium-server-standalone.jar") if not isfile(jarfile): raise SystemExit("error: can't find selenium jar at %s" % jarfile) corefile = join("..", "..", "..", "build", "selenium-core.jar") if not isfile(corefile): raise SystemExit("error: can't find selenium jar at %s" % corefile) fd, name = mkstemp() close(fd) fo = open(name, "w") server = Popen([ "java", "-cp", jarfile + pathsep + corefile, "org.openqa.selenium.server.SeleniumServer" ], shell=False, stdout=fo) srcdir = join("..", "..", "src", "py") # we should really be waiting for the server to be up and running sleep(5) try: env = environ.copy() env["PYTHONPATH"] = pathsep.join([env.get("PYTHONPATH", ""), srcdir]) ok = call([sys.executable, "selenium_test_suite.py"], env=env) except AttributeError: pass # try the python 2.6 way of killing the task try: server.kill except: os.kill(server.pid, signal.SIGTERM) raise SystemExit(ok)
def __init__(self): tree = ET.parse(pathsep.join([ file_location, file_name ])) if file_location else ET.parse(file_name) root = tree.getroot() self.library = root.findtext("metadata_displays/library_name") self.library_message = root.findtext( "metadata_displays/library_message") self.title = root.findtext("metadata_displays/page_title") self.displays = [Display(d) for d in root.findall("display")]
def _set_environment_defaults(self, environment): # type: (MutableMapping[str, str]) -> None if not self._default: return for variable, default_values in self._default.items(): if variable in environment: continue default_value = pathsep.join(default_values) environment[variable] = default_value
def StripPath(path): collected = [] for p in path.split(pathsep): rp = realpath(p) # We keep the entry if it is a directory not empty or a zipfile try : if exists(rp) and ((isdir(rp) and listdir(rp)) or is_zipfile(rp)) and p not in collected: collected.append(p) except OSError : pass return pathsep.join(collected)
def StripPath(path): collected = [] for p in path.split(pathsep): rp = realpath(p) np = normpath(p) # We keep the entry if it is a directory not empty or a zipfile try : if exists(rp) and ((isdir(rp) and listdir(rp)) or is_zipfile(rp)) and np not in collected: collected.append(np) except OSError : pass return pathsep.join(collected)
def populate_idf_env_vars(idf_env): idf_env["IDF_PATH"] = env.subst("$FRAMEWORK_DIR") #platform.get_package_dir("framework-espidf") additional_packages = [ join(platform.get_package_dir("toolchain-xtensa-lx106-elf"), "bin"), platform.get_package_dir("tool-ninja"), join(platform.get_package_dir("tool-cmake"), "bin"), ] if "windows" in get_systype(): additional_packages.append(platform.get_package_dir("tool-mconf")) idf_env["PATH"] = pathsep.join(additional_packages + [idf_env["PATH"]])
def find_tool(tool, env): """Part of the public API""" path = env["PATH"] paths = path.split(pathsep) ctinker_path = env[CTINKER_PATH] # We need PATH without our shim for real tool execution idx = paths.index(ctinker_path) del paths[idx] tool_path_env = pathsep.join(paths) return shutil.which(tool, path=tool_path_env)
def expand_classpath(): from os import pathsep from glob import glob paths = [] # deal with wildcards for path in get_classpath(): if not path.endswith("*"): paths.append(path) else: paths.extend(glob(path + ".[Jj][Aa][Rr]")) return pathsep.join(paths)
def main(argv=None): from os.path import join, isfile, dirname from tempfile import mkstemp from os import chdir, close, environ, pathsep import os # So we can look kill up later from subprocess import Popen, call import sys import signal from time import sleep from optparse import OptionParser argv = argv or sys.argv parser = OptionParser("%prog") opts, args = parser.parse_args(argv[1:]) if args: parser.error("wrong number of arguments") # Will exit chdir(dirname(__file__)) jarfile = join("..", "..", "..", "build", "selenium-server-standalone.jar") if not isfile(jarfile): raise SystemExit("error: can't find selenium jar at %s" % jarfile) corefile = join("..", "..", "..", "build", "selenium-core.jar") if not isfile(corefile): raise SystemExit("error: can't find selenium jar at %s" % corefile) fd, name = mkstemp() close(fd) fo = open(name, "w") server = Popen(["java", "-cp", jarfile + pathsep + corefile, "org.openqa.selenium.server.SeleniumServer"], shell=False, stdout=fo) srcdir = join("..", "..", "src", "py") # we should really be waiting for the server to be up and running sleep(5) try: env = environ.copy() env["PYTHONPATH"] = pathsep.join([env.get("PYTHONPATH", ""), srcdir]) ok = call([sys.executable, "selenium_test_suite.py"], env=env) except AttributeError: pass # try the python 2.6 way of killing the task try: server.kill except: os.kill(server.pid, signal.SIGTERM) raise SystemExit(ok)
def _load_library(): # We assume the DLL is next to the driver, the build (setup.py) should take # care of it old_path = environ["PATH"] environ["PATH"] = pathsep.join([environ["PATH"], abspath(dirname(__file__))]) try: # We first try the platform specific dll and then the general one for suffix in (_num_bits(), ""): dll = "InternetExplorerDriver%s.dll" % suffix try: return ctypes.cdll.LoadLibrary(dll) except WindowsError: pass finally: environ["PATH"] = old_path
def man_replacements(): # XXX: We should use conda-api for this, but it's currently annoying to set the # root prefix with. info = json.loads(str_check_output(['conda', 'info', '--json'])) # We need to use an ordered dict because the root prefix should be # replaced last, since it is typically a substring of the default prefix r = OrderedDict([ (info['default_prefix'], 'default prefix'), (pathsep.join(info['envs_dirs']), 'envs dirs'), # For whatever reason help2man won't italicize these on its own # Note these require conda > 3.7.1 (info['user_rc_path'], r'\fI\,user .condarc path\/\fP'), (info['sys_rc_path'], r'\fI\,system .condarc path\/\fP'), (info['root_prefix'], r'root prefix'), ]) return r
def main(): if argv[1:] == []: process(abspath(getcwd())) for e, ds in executables.items(): if len(set(ds)) > 1: stderr.write('Warning: using {0} from {1}; ignoring {0} from {2}\n'. format(e, ds[0], ' and '.join(list(set(ds[1:]))))) for d in getenv('PATH').split(pathsep): add_to_path(d) elif argv[1:] == ['-remove']: collect(abspath(getcwd())) for d in getenv('PATH').split(pathsep): if abspath(d) not in all_dirs: add_to_path(d) else: stderr.write('Error: Bad usage. I am just removing duplicates.\n') for d in getenv('PATH').split(pathsep): add_to_path(d) stdout.write(pathsep.join(new_path))
def updateEnviron(): oper = platform if oper.startswith("win32"): oper = "windows" elif oper.startswith("darwin"): oper = "macosx" elif oper.startswith("linux"): oper = "linux-" + ("amd64" if arch() == "x86_64" else "i386") libs = path.join(base, "libs") casper = path.join(libs, "casperjs", ("bin" if oper is not "windows" else "batchbin")) phantom = path.join(libs, "phantomjs") phantomBin = path.join(phantom, "bin") if oper.startswith("cygwin"): oper = "windows" phantomBinOS = path.join(phantomBin, oper) environ["PATH"] += pathsep + pathsep.join([casper, phantomBinOS, phantom, phantomBin])
def fix_binpath(paths): if paths is not None: if isinstance(paths, basestring): environ['PATH'] = paths elif isinstance(paths, list): environ['PATH'] = pathsep.join(paths)
filterdict_pop, \ filterdict_remove, \ hybridproperty, \ tuplist from .utils_2to3 import StandardError, filter_u, foreach_u #, iter_values from .utils_func import apply_intercalate from .utils_prog import ProtectedDict, cli_decor, getenv_namespaced log = getLogger(__name__) module_ext = dict((t, s) for s, m, t in get_suffixes())[PY_SOURCE] here = dirname(abspath(__file__)) EXTPLUGINS = tuple(e if isabs(e) else join(here, e) for e in map(str.strip, getenv_namespaced( 'EXTPLUGINS', pathsep.join(('ext-plugins', EXTPLUGINS_SHARED)) ).rstrip(pathsep).split(pathsep)) ) class MetaPlugin(object): """For use in the internal meta-hierarchy as "do not register me" mark""" class PluginRegistry(type): """Core of simple plugin framework This ``superclass'' serves two roles: (1) metaclass for plugins (and its class hierarchy) - only a tiny wrapper on top of `type`
def main(argv = None): if argv is None: argv = sys.argv version = __doc__.split ('\n')[0] parser = OptionParser (usage = '%prog', version = version, description = __doc__) parser.add_option('--showops', action = 'store_true', dest = 'showops', default = False, help = 'show operations') parser.add_option('--modules', action = 'store_true', dest = 'modules', default = False, help = 'generate module dependencies') parser.add_option('--calls', action = 'store_true', dest = 'calls', default = False, help = 'generate callgraph') parser.add_option('--files', action = 'store_true', dest = 'files', default = False, help = 'generate file dependencies') parser.add_option('--debug', action = 'store_true', dest = 'debug', default = False, help = 'enable debugging') parser.add_option('--exclude', dest = 'exclude', default = '', help = 'files to exclude') parser.add_option('--objext', dest = 'objext', default = '.o', help = 'object file extension') parser.add_option('--exeext', dest = 'exeext', default = '.out', help = 'executable file extension') parser.add_option('--cc', dest = 'cc', default = 'gcc', help = 'compiler name') parser.add_option('--cflags', dest = 'cflags', default = '', help = 'CFLAGS') parser.add_option('--relpath', action = 'store_true', dest = 'relpath', default = False, help = 'use relative paths') parser.add_option('--outfile', dest = 'outfilename', default = None, help = 'output filename') parser.add_option('--builddir', dest = 'builddir', default = '', help = 'build dirname') parser.add_option('--template', dest = 'template', default = None, help = 'template filename') (options, args) = parser.parse_args () if len (args) < 1: print __doc__ sys.exit (0) if ',' in options.exclude: options.exclude = options.exclude.split(',') else: options.exclude = options.exclude.split() maincfilename = args[0] search_list = [] if len (args) > 1: search_list.extend (args[1:len (args)]) search_path = pathsep.join (search_list) includes = '-I' + ' -I'.join (search_list) options.compile = options.cc + ' ' + options.cflags + ' ' + includes if options.debug: print >> sys.stderr, search_list print >> sys.stderr, 'template', options.template print >> sys.stderr, 'cfile', maincfilename print >> sys.stderr, 'search_path', search_path print >> sys.stderr, 'CWD = ', os.getcwd() print >> sys.stderr, options.compile if os.path.isdir (maincfilename): if options.debug: print >> sys.stderr, 'Searching ' + maincfilename maincfilename = maincfilename_find (maincfilename) if not maincfilename: sys.exit (1) if options.debug: print >> sys.stderr, 'Found C file ' + maincfilename # Search main c file looking for header files included with #include # and any header files included by the header files filedeps = {} moduledeps = {} files_find (maincfilename, search_path, filedeps, moduledeps, '', options.debug) cfilelist = cfiles_get_all (filedeps) ofilelist = [cfile[:-2] + options.objext for cfile in cfilelist] outfile = maincfilename[:-2] + options.exeext filedeps[outfile] = ofilelist for ofile in ofilelist: deps = [] deps.append (ofile[:-2] + '.c') filedeps[ofile] = deps if options.calls: functiondeps = {} functions = {} for cfile in cfilelist: functions_find (cfile, functiondeps, functions, options) callgraph_print ('main', functiondeps, functions, options) if options.files: deps_print (outfile, filedeps, options) if options.modules: target, ext = os.path.splitext (os.path.basename (maincfilename)) deps_print (target, moduledeps, options) if options.template: makefile_print (options, options.template, maincfilename, filedeps, search_list) return 0
def makefile_print (options, template, maincfilename, filedeps, search_list): cfilelist = cfiles_get_all (filedeps) cfilelist.sort () basecfilelist = [os.path.basename (cfile) for cfile in cfilelist] project = os.path.splitext (os.path.basename (maincfilename)) project = project[0] file = open (template, 'r') text = file.read () file.close () hfilelist = hfiles_get_all (filedeps) includedirs = paths_prune (hfilelist) moduledirs = paths_prune (cfilelist) vpath = ' '.join (moduledirs) includes = '-I' + ' -I'.join (includedirs) src = ' '.join (basecfilelist) obj = src if options.builddir != '': objfilelist = [os.path.join (options.builddir, obj1) for obj1 in basecfilelist] objfilelist.sort () obj = ' '.join (objfilelist) project = os.path.join (options.builddir, project) obj = re.sub (r'([a-zA-Z0-9/.-_]*)[.]c', r'\1' + options.objext, obj) text = re.sub (r'@PROJECT@', project, text) text = re.sub (r'@VPATH@', vpath, text) text = re.sub (r'@CC@', options.cc, text) text = re.sub (r'@CFLAGS@', options.cflags, text) text = re.sub (r'@INCLUDES@', includes, text) text = re.sub (r'@SRC@', src, text) text = re.sub (r'@OBJ@', obj, text) if re.search (r'@CCRULES@', text) != None: search_path = pathsep.join (search_list) rules = '' for cfile in cfilelist: cfilebase = os.path.basename (cfile) if options.relpath: cfile1 = os.path.relpath (cfile) else: cfile1 = cfilebase if options.builddir != '': rules = rules + os.path.join (options.builddir, '') rules = rules + re.sub ('([a-zA-Z0-9/.-_]*)[.]c', r'\1' + options.objext, cfilebase) + ': ' + cfile1 hfilelist = hfiles_get (cfile, filedeps, options) hfilelist.sort () if options.debug: print >> sys.stderr, 'Need hfiles', hfilelist, 'for', cfile for hfile in hfilelist: rules = rules + ' ' + hfile rules = rules + '\n' rules = rules + '\t$(CC) -c $(CFLAGS) $< -o $@\n\n' text = re.sub (r'@CCRULES@', rules, text) print text
def ld_lib_path(): global ld_lib_path_original global ld_lib_path_settings # concatenations with platform specific path separator (eg ':' colon on UNIX, ';' semicolon on windows) environ[ld_path_env_name()] = pathsep.join(ld_lib_path_settings.get("ld_library_path_items", []))
def java_classpath(current_workdir): return pathsep.join([antlr, current_workdir])
import shutil from os import chmod, environ, pathsep from pathlib import Path build_root = Path(environ['MESON_BUILD_ROOT']) source_root = Path(environ['MESON_SOURCE_ROOT']) install_prefix = Path(environ['MESON_INSTALL_DESTDIR_PREFIX']) args = sys.argv[1:] macos_lib_paths = filter(None, (Path(x) for x in args.pop(0).split(pathsep))) macos_tool_paths = filter(None, (Path(x) for x in args.pop(0).split(pathsep))) macos_tool_prefix = args.pop(0) if macos_tool_paths: environ['PATH'] = pathsep.join(itertools.chain((str(p) for p in macos_tool_paths), [environ['PATH']])) exe_path = install_prefix / 'Taisei.app' / 'Contents' / 'MacOS' / 'Taisei' dylib_dir_path = exe_path.parent / 'dylibs' dylib_dir_path.mkdir(mode=0o755, parents=True, exist_ok=True) def tool(name): def func(*args): cmd = [macos_tool_prefix + name] + list(args) print(' '.join(('{0!r}' if ' ' in str(s) else '{0}').format(str(s)) for s in cmd)) return subprocess.check_output(cmd, universal_newlines=True) return func otool = tool('otool') install_name_tool = tool('install_name_tool')
def _sequence_to_path(seq): return PATHSEP.join(seq)