def editor_run(editor, config): if shutil_which(editor): get_editor = environ.get("EDITOR", editor) with open(config) as f: subprocess_call([get_editor, f.name]) exit(0) return
def which(cmd, mode=os.F_OK | os.X_OK, path=None, exts=None): """A wrapper around `shutil.which` to make the behavior on Windows consistent with other platforms. On non-Windows platforms, this is a direct call to `shutil.which`. On Windows, this: * Ensures that `cmd` without an extension will be found. Previously it was only found if it had an extension in `PATHEXT`. * Ensures the absolute path to the binary is returned. Previously if the binary was found in `cwd`, a relative path was returned. The arguments are the same as the ones in `shutil.which`. In addition there is an `exts` argument that only has an effect on Windows. This is used to set a custom value for PATHEXT and is formatted as a list of file extensions. """ try: from shutil import which as shutil_which except ImportError: from shutil_which import which as shutil_which if isinstance(path, (list, tuple)): path = os.pathsep.join(path) if sys.platform != "win32": return shutil_which(cmd, mode=mode, path=path) oldexts = os.environ.get("PATHEXT", "") if not exts: exts = oldexts.split(os.pathsep) # This ensures that `cmd` without any extensions will be found. # See: https://bugs.python.org/issue31405 if "." not in exts: exts.append(".") os.environ["PATHEXT"] = os.pathsep.join(exts) try: path = shutil_which(cmd, mode=mode, path=path) return os.path.abspath(path.rstrip('.')) if path else None finally: if oldexts: os.environ["PATHEXT"] = oldexts else: del os.environ["PATHEXT"]
def rm_init_file_package(init_file): with contextlib_suppress(Exception): os_remove(init_file) if shutil_which("pip") is not None: check_output( f'pip uninstall {package.info["name"]} -y', shell=True, universal_newlines=True, )
def main(): parser = ArgumentParser( description="Converts '.mac', '.rac' and '.vac' audio files to '.wav'.", epilog="Application expects sox to be installed and in PATH.") parser.add_argument("audio_file", type=Path, help="Path to the audio file(s)", nargs="+") parser.add_argument("-o", "--output_dir", type=Path, help="Output directory to place wav files in", default=".") args = parser.parse_args() if shutil_which("sox") is None: print("Sox is not installed and in PATH.") return if not args.output_dir.is_dir(): print("Output directory path is not a valid directory:", args.output_dir) return for input_file_path in args.audio_file: if not input_file_path.is_file(): print("{} is not a file".format(input_file_path.name)) continue if not input_file_path.suffix in [".mac", ".rac", ".vac"]: print("{} is not a supported file type ('.mac', '.rac', '.vac')". format(input_file_path.name)) continue if (input_file_path.suffix == ".rac"): output_file_path = _toStereoWav(input_file_path, args.output_dir) else: output_file_path = _toWav(input_file_path, args.output_dir) print("{} -> {}".format(input_file_path.name, output_file_path.name))
def which(cmd, mode=os.F_OK | os.X_OK, path=None, exts=None, extra_search_dirs=()): """A wrapper around `shutil.which` to make the behavior on Windows consistent with other platforms. On non-Windows platforms, this is a direct call to `shutil.which`. On Windows, this: * Ensures that `cmd` without an extension will be found. Previously it was only found if it had an extension in `PATHEXT`. * Ensures the absolute path to the binary is returned. Previously if the binary was found in `cwd`, a relative path was returned. * Checks the Windows registry if shutil.which doesn't come up with anything. The arguments are the same as the ones in `shutil.which`. In addition there is an `exts` argument that only has an effect on Windows. This is used to set a custom value for PATHEXT and is formatted as a list of file extensions. extra_search_dirs is a convenience argument. If provided, the strings in the sequence will be appended to the END of the given `path`. """ from shutil import which as shutil_which if isinstance(path, (list, tuple)): path = os.pathsep.join(path) if not path: path = os.environ.get("PATH", os.defpath) if extra_search_dirs: path = os.pathsep.join([path] + list(extra_search_dirs)) if sys.platform != "win32": return shutil_which(cmd, mode=mode, path=path) oldexts = os.environ.get("PATHEXT", "") if not exts: exts = oldexts.split(os.pathsep) # This ensures that `cmd` without any extensions will be found. # See: https://bugs.python.org/issue31405 if "." not in exts: exts.append(".") os.environ["PATHEXT"] = os.pathsep.join(exts) try: path = shutil_which(cmd, mode=mode, path=path) if path: return os.path.abspath(path.rstrip(".")) finally: if oldexts: os.environ["PATHEXT"] = oldexts else: del os.environ["PATHEXT"] # If we've gotten this far, we need to check for registered executables # before giving up. try: import winreg except ImportError: import _winreg as winreg if not cmd.lower().endswith(".exe"): cmd += ".exe" try: ret = winreg.QueryValue( winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%s" % cmd, ) return os.path.abspath(ret) if ret else None except winreg.error: return None
"Failed to install cmake") # if which('ninja') is None: _run_cmd(['python', '-m', 'pip', 'install', 'ninja'], "Failed to install ninja") if platform.system() != 'Windows': logging.info('Building static libaries...') do_build(use_tmp=os.environ.get('USE_TMP_DIR', False)) else: raise ValueError('Windows static libraries must be manually built!') else: logging.info('Static libraries appear to exist already') # Update list of link-ordered LLVM libraries if we # have llvm-config available if shutil_which('llvm-config') is not None: with open('clangTooling/lib/llvm_lib_list.txt', 'w') as txt: LLVM_LIBS = subprocess.run(['llvm-config', '--libs', '--link-static'], stdout=subprocess.PIPE, check=True).stdout.decode() LLVM_LIBS = [ _clean_prefix(_clean_ext(pathlib.Path(l)), '-l') for l in LLVM_LIBS.split() ] txt.write('\n'.join(LLVM_LIBS)) setup( name='clangTooling', version='0.0.8', author='Nicholas McKibben', author_email='*****@*****.**',
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir) PROJECT_SLUG = "{{ cookiecutter.project_slug }}" CREATE_VIRTUAL_ENVIRONMENT = '{{ cookiecutter.create_virtual_environment }}'.lower( ) == 'y' REPO_URL = "{{ cookiecutter.repo_url }}" INCLUDE_SPHINX_DOC = '{{ cookiecutter.include_sphinx_doc }}' != 'y' GIT_INIT = '{{ cookiecutter.git_init }}'.lower() == 'y' RUN_TESTS = '{{ cookiecutter.run_tests_on_init }}' == 'y' INCLUDE_SPHINX = '{{ cookiecutter.include_sphinx_doc }}' == 'y' try: from shutil import which as shutil_which except ImportError: from backports.shutil_which import which as shutil_which VEX_AVAILABLE = shutil_which('vex') PEW_AVAILABLE = shutil_which('pew') PIPENV_AVAILABLE = shutil_which('pipenv') def remove_file(filepath): os.remove(os.path.join(PROJECT_DIRECTORY, filepath)) def bootstrap_venv(): # On Windows current python3 may just be python or not available from PATH python = sys.executable or 'python3' if PEW_AVAILABLE: bootstrap_pew(python) return