Python distutils.spawn.find_executable() Examples
The following are 30
code examples of distutils.spawn.find_executable().
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 also want to check out all available functions/classes of the module
distutils.spawn
, or try the search function
.
Example #1
Source File: diagnose.py From xuebao with MIT License | 7 votes |
def check_executable(executable): """ Checks if an executable exists in $PATH. Arguments: executable -- the name of the executable (e.g. "echo") Returns: True or False """ logger = logging.getLogger(__name__) logger.debug("Checking executable '%s'...", executable) executable_path = find_executable(executable) found = executable_path is not None if found: logger.debug("Executable '%s' found: '%s'", executable, executable_path) else: logger.debug("Executable '%s' not found", executable) return found
Example #2
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _install_linecache_wrapper(self): """Disable linecache.checkcache to not invalidate caches. This gets installed permanently to also bypass e.g. pytest using `inspect.getsource`, which would invalidate it outside of the interaction them. """ if not hasattr(self, "_orig_linecache_checkcache"): import linecache # Save it, although not used really (can be useful for debugging). self._orig_linecache_checkcache = linecache.checkcache def _linecache_checkcache(*args, **kwargs): return linecache.checkcache = _linecache_checkcache
Example #3
Source File: test_yarn.py From mars with Apache License 2.0 | 6 votes |
def tearDown(self): time.sleep(5) dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage') if os.path.exists(dist_coverage_path): # change ownership of coverage files if find_executable('sudo'): proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()), dist_coverage_path], shell=False) proc.wait() # rewrite paths in coverage result files for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')): cov_db = sqlite3.connect(fn) c = cov_db.cursor() c.execute('UPDATE file SET path=REPLACE(path, \'%s\', \'\')' % (MARS_ROOT + os.path.sep)) cov_db.commit() cov_db.close() if 'COVERAGE_FILE' in os.environ: new_cov_file = os.environ['COVERAGE_FILE'] \ + os.path.basename(fn).replace('.coverage', '') else: new_cov_file = fn.replace('.dist-coverage' + os.sep, '') shutil.copyfile(fn, new_cov_file) shutil.rmtree(dist_coverage_path)
Example #4
Source File: test_kubernetes.py From mars with Apache License 2.0 | 6 votes |
def tearDown(self): dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage') if os.path.exists(dist_coverage_path): # change ownership of coverage files if find_executable('sudo'): proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()), dist_coverage_path], shell=False) proc.wait() # rewrite paths in coverage result files for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')): if 'COVERAGE_FILE' in os.environ: new_cov_file = os.environ['COVERAGE_FILE'] \ + os.path.basename(fn).replace('.coverage', '') else: new_cov_file = fn.replace('.dist-coverage' + os.sep, '') shutil.copyfile(fn, new_cov_file) shutil.rmtree(dist_coverage_path)
Example #5
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def do_track(self, arg): """ track expression Display a graph showing which objects are referred by the value of the expression. This command requires pypy to be in the current PYTHONPATH. """ try: from rpython.translator.tool.reftracker import track except ImportError: print('** cannot import pypy.translator.tool.reftracker **', file=self.stdout) return try: val = self._getval(arg) except: pass else: track(val)
Example #6
Source File: osquery.py From rekall with GNU General Public License v2.0 | 6 votes |
def try_to_find_osquery(self): extention = "" if platform.system() == "Windows": extention = ".exe" try: return resources.get_resource("osqueryi" + extention) except IOError as e: # Maybe it is installed on the system. if platform.system() == "Windows": result = r"c:\ProgramData\osquery\osqueryi.exe" if os.access(result, os.R_OK): return result else: # Try to find it somewhere on the system. return spawn.find_executable("osqueryi") raise e
Example #7
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _get_editor_cmd(self, filename, lineno): editor = self.config.editor if editor is None: try: editor = os.environ["EDITOR"] except KeyError: try: from shutil import which except ImportError: from distutils.spawn import find_executable as which editor = which("vim") if editor is None: editor = which("vi") if not editor: raise RuntimeError("Could not detect editor. Configure it or set $EDITOR.") # noqa: E501 return self._format_editcmd(editor, filename, lineno)
Example #8
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def set_trace(self, frame=None): """Remember starting frame. This is used with pytest, which does not use pdb.set_trace(). """ if getattr(local, "_pdbpp_completing", False): # Handle set_trace being called during completion, e.g. with # fancycompleter's attr_matches. return if self.disabled: return if frame is None: frame = sys._getframe().f_back self._via_set_trace_frame = frame self._stopped_for_set_trace = False self.start_filename = frame.f_code.co_filename self.start_lineno = frame.f_lineno return super(Pdb, self).set_trace(frame)
Example #9
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setbgcolor(line, color): # hack hack hack # add a bgcolor attribute to all escape sequences found import re setbg = '\x1b[%sm' % color regexbg = '\\1;%sm' % color result = setbg + re.sub('(\x1b\\[.*?)m', regexbg, line) + '\x1b[00m' if os.environ.get('TERM') == 'eterm-color': # it seems that emacs' terminal has problems with some ANSI escape # sequences. Eg, 'ESC[44m' sets the background color in all terminals # I tried, but not in emacs. To set the background color, it needs to # have also an explicit foreground color, e.g. 'ESC[37;44m'. These # three lines are a hack, they try to add a foreground color to all # escape sequences which are not recognized by emacs. However, we need # to pick one specific fg color: I choose white (==37), but you might # want to change it. These lines seems to work fine with the ANSI # codes produced by pygments, but they are surely not a general # solution. result = result.replace(setbg, '\x1b[37;%dm' % color) result = result.replace('\x1b[00;%dm' % color, '\x1b[37;%dm' % color) result = result.replace('\x1b[39;49;00;', '\x1b[37;') return result
Example #10
Source File: pdbpp.py From pdbpp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _disable_pytest_capture_maybe(self): try: import py.test # Force raising of ImportError if pytest is not installed. py.test.config except (ImportError, AttributeError): return try: capman = py.test.config.pluginmanager.getplugin('capturemanager') capman.suspendcapture() except KeyError: pass except AttributeError: # Newer pytest with support ready, or very old py.test for which # this hack does not work. pass
Example #11
Source File: new_process.py From clusterfuzz with Apache License 2.0 | 6 votes |
def get_command(self, additional_args=None): """Overridden get_command.""" if environment.platform() != 'LINUX': raise RuntimeError('UnshareProcessRunner only supported on Linux') unshare_path = spawn.find_executable('unshare') if not unshare_path: raise RuntimeError('unshare not found') command = [unshare_path] command.extend([ '-n', # Enter network namespace. ]) command.append(self._executable_path) command.extend(self._default_args) if additional_args: command.extend(additional_args) return command
Example #12
Source File: run.py From github-stats with MIT License | 6 votes |
def find_gae_path(): global GAE_PATH if GAE_PATH: return GAE_PATH if IS_WINDOWS: gae_path = None for path in os.environ['PATH'].split(os.pathsep): if os.path.isfile(os.path.join(path, 'dev_appserver.py')): gae_path = path else: gae_path = spawn.find_executable('dev_appserver.py') if gae_path: gae_path = os.path.dirname(os.path.realpath(gae_path)) if not gae_path: return '' gcloud_exec = 'gcloud.cmd' if IS_WINDOWS else 'gcloud' if not os.path.isfile(os.path.join(gae_path, gcloud_exec)): GAE_PATH = gae_path else: gae_path = os.path.join(gae_path, '..', 'platform', 'google_appengine') if os.path.exists(gae_path): GAE_PATH = os.path.realpath(gae_path) return GAE_PATH
Example #13
Source File: appengine.py From clusterfuzz with Apache License 2.0 | 6 votes |
def find_sdk_path(): """Find the App Engine SDK path.""" if common.get_platform() == 'windows': _, gcloud_path = common.execute('where gcloud.cmd', print_output=False) else: gcloud_path = spawn.find_executable('gcloud') if not gcloud_path: print('Please install the Google Cloud SDK and set up PATH to point to it.') sys.exit(1) cloud_sdk_path = os.path.dirname( os.path.dirname(os.path.realpath(gcloud_path))) appengine_sdk_path = os.path.join(cloud_sdk_path, 'platform', 'google_appengine') if not os.path.exists(appengine_sdk_path): print('App Engine SDK not found. Please run local/install_deps.bash') sys.exit(1) return appengine_sdk_path
Example #14
Source File: test_pygdbmi.py From pygdbmi with MIT License | 6 votes |
def _get_c_program(self, makefile_target_name, binary_name): """build c program and return path to binary""" find_executable(MAKE_CMD) if not find_executable(MAKE_CMD): print( 'Could not find executable "%s". Ensure it is installed and on your $PATH.' % MAKE_CMD ) exit(1) SAMPLE_C_CODE_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), "sample_c_app" ) binary_path = os.path.join(SAMPLE_C_CODE_DIR, binary_name) subprocess.call(["rm", "pygdbmi.a*"], cwd=SAMPLE_C_CODE_DIR) # Build C program subprocess.check_output( [MAKE_CMD, makefile_target_name, "-C", SAMPLE_C_CODE_DIR, "--quiet"] ) return binary_path
Example #15
Source File: base_executor.py From judge-server with GNU Affero General Public License v3.0 | 5 votes |
def find_command_from_list(cls, files: str) -> Optional[str]: for file in files: if os.path.isabs(file): if os.path.exists(file): return file else: path = find_executable(file) if path is not None: return os.path.abspath(path) return None
Example #16
Source File: easy_install.py From anpr with Creative Commons Attribution 4.0 International | 5 votes |
def _use_header(new_header): """ Should _adjust_header use the replaced header? On non-windows systems, always use. On Windows systems, only use the replaced header if it resolves to an executable on the system. """ clean_header = new_header[2:-1].strip('"') return sys.platform != 'win32' or find_executable(clean_header)
Example #17
Source File: easy_install.py From pex with Apache License 2.0 | 5 votes |
def _use_header(new_header): """ Should _adjust_header use the replaced header? On non-windows systems, always use. On Windows systems, only use the replaced header if it resolves to an executable on the system. """ clean_header = new_header[2:-1].strip('"') return sys.platform != 'win32' or find_executable(clean_header)
Example #18
Source File: TincanInterface.py From Controllers with MIT License | 5 votes |
def __init__(self, cfx_handle, module_config, module_name): super(TincanInterface, self).__init__(cfx_handle, module_config, module_name) self._tincan_listener_thread = None # UDP listener thread object self._tci_publisher = None self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._sock_svr = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Controller UDP listening socket self._sock_svr.bind((self._cm_config["RcvServiceAddress"], self._cm_config["CtrlRecvPort"])) # Controller UDP sending socket self._dest = (self._cm_config["SndServiceAddress"], self._cm_config["CtrlSendPort"]) self._sock.bind(("", 0)) self._sock_list = [self._sock_svr] self.iptool = spawn.find_executable("ip")
Example #19
Source File: easy_install.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def _use_header(new_header): """ Should _adjust_header use the replaced header? On non-windows systems, always use. On Windows systems, only use the replaced header if it resolves to an executable on the system. """ clean_header = new_header[2:-1].strip('"') return sys.platform != 'win32' or find_executable(clean_header)
Example #20
Source File: image.py From sagemaker-python-sdk with Apache License 2.0 | 5 votes |
def __init__(self, instance_type, instance_count, image, sagemaker_session=None): """Initialize a SageMakerContainer instance It uses a :class:`sagemaker.session.Session` for general interaction with user configuration such as getting the default sagemaker S3 bucket. However this class does not call any of the SageMaker APIs. Args: instance_type (str): The instance type to use. Either 'local' or 'local_gpu' instance_count (int): The number of instances to create. image (str): docker image to use. sagemaker_session (sagemaker.session.Session): a sagemaker session to use when interacting with SageMaker. """ from sagemaker.local.local_session import LocalSession # check if docker-compose is installed if find_executable("docker-compose") is None: raise ImportError( "'docker-compose' is not installed. " "Local Mode features will not work without docker-compose. " "For more information on how to install 'docker-compose', please, see " "https://docs.docker.com/compose/install/" ) self.sagemaker_session = sagemaker_session or LocalSession() self.instance_type = instance_type self.instance_count = instance_count self.image = image # Since we are using a single docker network, Generate a random suffix to attach to the # container names. This way multiple jobs can run in parallel. suffix = "".join(random.choice(string.ascii_lowercase + string.digits) for _ in range(5)) self.hosts = [ "{}-{}-{}".format(CONTAINER_PREFIX, i, suffix) for i in range(1, self.instance_count + 1) ] self.container_root = None self.container = None
Example #21
Source File: test_sdist.py From Computable with MIT License | 5 votes |
def test_make_distribution(self): # check if tar and gzip are installed if (find_executable('tar') is None or find_executable('gzip') is None): return # now building a sdist dist, cmd = self.get_cmd() # creating a gztar then a tar cmd.formats = ['gztar', 'tar'] cmd.ensure_finalized() cmd.run() # making sure we have two files dist_folder = join(self.tmp_dir, 'dist') result = os.listdir(dist_folder) result.sort() self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'] ) os.remove(join(dist_folder, 'fake-1.0.tar')) os.remove(join(dist_folder, 'fake-1.0.tar.gz')) # now trying a tar then a gztar cmd.formats = ['tar', 'gztar'] cmd.ensure_finalized() cmd.run() result = os.listdir(dist_folder) result.sort() self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
Example #22
Source File: emxccompiler.py From BinderFilter with MIT License | 5 votes |
def get_versions(): """ Try to find out the versions of gcc and ld. If not possible it returns None for it. """ from distutils.version import StrictVersion from distutils.spawn import find_executable import re gcc_exe = find_executable('gcc') if gcc_exe: out = os.popen(gcc_exe + ' -dumpversion','r') try: out_string = out.read() finally: out.close() result = re.search('(\d+\.\d+\.\d+)',out_string) if result: gcc_version = StrictVersion(result.group(1)) else: gcc_version = None else: gcc_version = None # EMX ld has no way of reporting version number, and we use GCC # anyway - so we can link OMF DLLs ld_version = None return (gcc_version, ld_version)
Example #23
Source File: github_releaser.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self): self._pandoc = find_executable('pandoc') if self._pandoc is None: sys.stderr.write("ERROR: pandoc not found on PATH.\n") raise SystemExit(1) self._gh_token = os.environ.get('GITHUB_TOKEN', None) if self._gh_token is None: sys.stderr.write("ERROR: GITHUB_TOKEN env var must be set\n") raise SystemExit(1) self._gh = login(token=self._gh_token) self._repo = self._gh.repository('jantman', 'biweeklybudget')
Example #24
Source File: conda.py From ansible-conda with BSD 2-Clause "Simplified" License | 5 votes |
def find_conda(executable): """ If `executable` is not None, checks whether it points to a valid file and returns it if this is the case. Otherwise tries to find the `conda` executable in the path. Calls `fail_json` if either of these fail. """ if not executable: conda = find_executable('conda') if conda: return conda else: if os.path.isfile(executable): return executable raise CondaExecutableNotFoundError()
Example #25
Source File: conda.py From ansible-conda with BSD 2-Clause "Simplified" License | 5 votes |
def find_conda(executable): """ If `executable` is not None, checks whether it points to a valid file and returns it if this is the case. Otherwise tries to find the `conda` executable in the path. Calls `fail_json` if either of these fail. """ if not executable: conda = find_executable('conda') if conda: return conda else: if os.path.isfile(executable): return executable raise CondaExecutableNotFoundError()
Example #26
Source File: tools.py From acsoo with GNU General Public License v3.0 | 5 votes |
def find_python(exe): if os.path.isabs(exe): return exe exe_path = _fe(exe) if exe_path: return exe_path raise RuntimeError("{} executable not found".format(exe))
Example #27
Source File: tools.py From acsoo with GNU General Public License v3.0 | 5 votes |
def _find_executable(exe): if os.path.isabs(exe): return exe python_dir = os.path.dirname(sys.executable) exe_path = os.path.join(python_dir, exe) if os.path.exists(exe_path): return exe_path exe_path = _fe(exe) if exe_path: return exe_path raise RuntimeError("{} executable not found".format(exe))
Example #28
Source File: build_manager.py From clusterfuzz with Apache License 2.0 | 5 votes |
def _set_rpaths_patchelf(binary_path, rpaths): """Set rpaths using patchelf.""" patchelf = spawn.find_executable('patchelf') if not patchelf: raise BuildManagerException('Failed to find patchelf') subprocess.check_output( [patchelf, '--force-rpath', '--set-rpath', ':'.join(rpaths), binary_path], stderr=subprocess.PIPE)
Example #29
Source File: utils.py From LKI with MIT License | 5 votes |
def check_executable(name): """ check if executable exists. (raise exeception if not) """ if not spawn.find_executable(name): raise error.LKIError("there is no {} executable".format(name))
Example #30
Source File: easy_install.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def _use_header(new_header): """ Should _adjust_header use the replaced header? On non-windows systems, always use. On Windows systems, only use the replaced header if it resolves to an executable on the system. """ clean_header = new_header[2:-1].strip('"') return sys.platform != 'win32' or find_executable(clean_header)