def install_environment(prefix, version, additional_dependencies): additional_dependencies = tuple(additional_dependencies) assert prefix.exists('package.json') envdir = _envdir(prefix, version) # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath if sys.platform == 'win32': # pragma: no cover envdir = '\\\\?\\' + os.path.normpath(envdir) with clean_path_on_failure(envdir): cmd = [ sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir, ] if version != 'default': cmd.extend(['-n', version]) cmd_output(*cmd) with in_env(prefix, version): helpers.run_setup_cmd( prefix, ('npm', 'install', '-g', '.') + additional_dependencies, )
def install_environment(prefix, version, additional_dependencies): helpers.assert_version_default('golang', version) directory = prefix.path( helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT), ) with clean_path_on_failure(directory): remote = git.get_remote_url(prefix.prefix_dir) repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote)) # Clone into the goenv we'll create helpers.run_setup_cmd(prefix, ('git', 'clone', '.', repo_src_dir)) if sys.platform == 'cygwin': # pragma: no cover _, gopath, _ = cmd_output('cygpath', '-w', directory) gopath = gopath.strip() else: gopath = directory env = dict(os.environ, GOPATH=gopath) cmd_output('go', 'get', './...', cwd=repo_src_dir, env=env) for dependency in additional_dependencies: cmd_output('go', 'get', dependency, cwd=repo_src_dir, env=env) # Same some disk space, we don't need these after installation rmtree(prefix.path(directory, 'src')) pkgdir = prefix.path(directory, 'pkg') if os.path.exists(pkgdir): # pragma: no cover (go<1.10) rmtree(pkgdir)
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: helpers.assert_version_default("golang", version) directory = prefix.path( helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT), ) with clean_path_on_failure(directory): remote = git.get_remote_url(prefix.prefix_dir) repo_src_dir = os.path.join(directory, "src", guess_go_dir(remote)) # Clone into the goenv we'll create helpers.run_setup_cmd(prefix, ("git", "clone", ".", repo_src_dir)) if sys.platform == "cygwin": # pragma: no cover _, gopath, _ = cmd_output("cygpath", "-w", directory) gopath = gopath.strip() else: gopath = directory env = dict(os.environ, GOPATH=gopath) env.pop("GOBIN", None) cmd_output_b("go", "get", "./...", cwd=repo_src_dir, env=env) for dependency in additional_dependencies: cmd_output_b("go", "get", dependency, cwd=repo_src_dir, env=env) # Same some disk space, we don't need these after installation rmtree(prefix.path(directory, "src")) pkgdir = prefix.path(directory, "pkg") if os.path.exists(pkgdir): # pragma: no cover (go<1.10) rmtree(pkgdir)
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) # Install a virtualenv with clean_path_on_failure(repo_cmd_runner.path(directory)): venv_cmd = [ sys.executable, '-m', 'virtualenv', '{{prefix}}{}'.format(directory) ] if version != 'default': venv_cmd.extend(['-p', norm_version(version)]) else: venv_cmd.extend(['-p', os.path.realpath(sys.executable)]) venv_env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1') repo_cmd_runner.run(venv_cmd, cwd='/', env=venv_env) with in_env(repo_cmd_runner, version): helpers.run_setup_cmd( repo_cmd_runner, ('pip', 'install', '.') + additional_dependencies, )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: additional_dependencies = tuple(additional_dependencies) assert prefix.exists('package.json') envdir = _envdir(prefix, version) # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath if sys.platform == 'win32': # pragma: no cover envdir = fr'\\?\{os.path.normpath(envdir)}' with clean_path_on_failure(envdir): cmd = [ sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir, ] if version != C.DEFAULT: cmd.extend(['-n', version]) cmd_output_b(*cmd) with in_env(prefix, version): # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449 # install as if we installed from git helpers.run_setup_cmd(prefix, ('npm', 'install')) helpers.run_setup_cmd( prefix, ('npm', 'install', '-g', '.', *additional_dependencies), )
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): additional_dependencies = tuple(additional_dependencies) assert repo_cmd_runner.exists('package.json') directory = helpers.environment_dir(ENVIRONMENT_DIR, version) env_dir = repo_cmd_runner.path(directory) with clean_path_on_failure(env_dir): cmd = [ sys.executable, '-m', 'nodeenv', '--prebuilt', '{{prefix}}{}'.format(directory), ] if version != 'default': cmd.extend(['-n', version]) repo_cmd_runner.run(cmd) with in_env(repo_cmd_runner, version): helpers.run_setup_cmd( repo_cmd_runner, ('npm', 'install', '-g', '.') + additional_dependencies, )
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): helpers.assert_version_default('golang', version) directory = repo_cmd_runner.path( helpers.environment_dir(ENVIRONMENT_DIR, 'default'), ) with clean_path_on_failure(directory): remote = git.get_remote_url(repo_cmd_runner.path()) repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote)) # Clone into the goenv we'll create helpers.run_setup_cmd( repo_cmd_runner, ('git', 'clone', '.', repo_src_dir), ) env = dict(os.environ, GOPATH=directory) cmd_output('go', 'get', './...', cwd=repo_src_dir, env=env) for dependency in additional_dependencies: cmd_output('go', 'get', dependency, cwd=repo_src_dir, env=env) # Same some disk space, we don't need these after installation rmtree(repo_cmd_runner.path(directory, 'src')) rmtree(repo_cmd_runner.path(directory, 'pkg'))
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: # pragma: win32 no cover helpers.assert_version_default('coursier', version) helpers.assert_no_additional_deps('coursier', additional_dependencies) envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) channel = prefix.path('.pre-commit-channel') with clean_path_on_failure(envdir): for app_descriptor in os.listdir(channel): _, app_file = os.path.split(app_descriptor) app, _ = os.path.splitext(app_file) helpers.run_setup_cmd( prefix, ( 'cs', 'install', '--default-channels=false', f'--channel={channel}', app, f'--dir={envdir}', ), )
def install_environment( prefix, version, additional_dependencies, ): # pragma: windows no cover additional_dependencies = tuple(additional_dependencies) assert prefix.exists('package.json') envdir = _envdir(prefix, version) # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath if sys.platform == 'win32': # pragma: no cover envdir = '\\\\?\\' + os.path.normpath(envdir) with clean_path_on_failure(envdir): cmd = [ sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir, ] if version != C.DEFAULT: cmd.extend(['-n', version]) cmd_output(*cmd) with in_env(prefix, version): # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449 # install as if we installed from git helpers.run_setup_cmd(prefix, ('npm', 'install')) helpers.run_setup_cmd( prefix, ('npm', 'install', '-g', '.') + additional_dependencies, )
def install_environment(repo_cmd_runner, version, additional_dependencies): helpers.assert_version_default('golang', version) directory = repo_cmd_runner.path( helpers.environment_dir(ENVIRONMENT_DIR, 'default'), ) with clean_path_on_failure(directory): remote = git.get_remote_url(repo_cmd_runner.path()) repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote)) # Clone into the goenv we'll create helpers.run_setup_cmd( repo_cmd_runner, ('git', 'clone', '.', repo_src_dir), ) if sys.platform == 'cygwin': # pragma: no cover _, gopath, _ = cmd_output('cygpath', '-w', directory) gopath = gopath.strip() else: gopath = directory env = dict(os.environ, GOPATH=gopath) cmd_output('go', 'get', './...', cwd=repo_src_dir, env=env) for dependency in additional_dependencies: cmd_output('go', 'get', dependency, cwd=repo_src_dir, env=env) # Same some disk space, we don't need these after installation rmtree(repo_cmd_runner.path(directory, 'src')) rmtree(repo_cmd_runner.path(directory, 'pkg'))
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): # pragma: windows no cover additional_dependencies = tuple(additional_dependencies) assert repo_cmd_runner.exists('package.json') directory = helpers.environment_dir(ENVIRONMENT_DIR, version) env_dir = repo_cmd_runner.path(directory) with clean_path_on_failure(env_dir): cmd = [ sys.executable, '-m', 'nodeenv', '--prebuilt', '{{prefix}}{}'.format(directory), ] if version != 'default': cmd.extend(['-n', version]) repo_cmd_runner.run(cmd) with in_env(repo_cmd_runner, version): helpers.run_setup_cmd( repo_cmd_runner, ('npm', 'install', '-g', '.') + additional_dependencies, )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: # pragma: win32 no cover helpers.assert_version_default('coursier', version) helpers.assert_no_additional_deps('coursier', additional_dependencies) # Support both possible executable names (either "cs" or "coursier") executable = find_executable('cs') or find_executable('coursier') if executable is None: raise AssertionError( 'pre-commit requires system-installed "cs" or "coursier" ' 'executables in the application search path', ) envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) channel = prefix.path('.pre-commit-channel') with clean_path_on_failure(envdir): for app_descriptor in os.listdir(channel): _, app_file = os.path.split(app_descriptor) app, _ = os.path.splitext(app_file) helpers.run_setup_cmd( prefix, ( executable, 'install', '--default-channels=false', f'--channel={channel}', app, f'--dir={envdir}', ), )
def test_failed_setup_command_does_not_unicode_error(): script = ('import sys\n' "sys.stderr.buffer.write(b'\\x81\\xfe')\n" 'raise SystemExit(1)\n') # an assertion that this does not raise `UnicodeError` with pytest.raises(CalledProcessError): helpers.run_setup_cmd(Prefix('.'), (sys.executable, '-c', script))
def _install_ruby( prefix: Prefix, version: str, ) -> None: # pragma: win32 no cover try: helpers.run_setup_cmd(prefix, ('rbenv', 'download', version)) except CalledProcessError: # pragma: no cover (usually find with download) # Failed to download from mirror for some reason, build it instead helpers.run_setup_cmd(prefix, ('rbenv', 'install', version))
def test_failed_setup_command_does_not_unicode_error(): script = ( 'import sys\n' "getattr(sys.stderr, 'buffer', sys.stderr).write(b'\\x81\\xfe')\n" 'exit(1)\n' ) # an assertion that this does not raise `UnicodeError` with pytest.raises(CalledProcessError): helpers.run_setup_cmd(Prefix('.'), (sys.executable, '-c', script))
def build_docker_image(repo_cmd_runner, **kwargs): # pragma: windows no cover pull = kwargs.pop('pull') assert not kwargs, kwargs cmd = ( 'docker', 'build', '.', '--tag', docker_tag(repo_cmd_runner), '--label', PRE_COMMIT_LABEL, ) if pull: cmd += ('--pull',) helpers.run_setup_cmd(repo_cmd_runner, cmd)
def build_docker_image(prefix, **kwargs): # pragma: windows no cover pull = kwargs.pop('pull') assert not kwargs, kwargs cmd = ( 'docker', 'build', '--tag', docker_tag(prefix), '--label', PRE_COMMIT_LABEL, ) if pull: cmd += ('--pull',) # This must come last for old versions of docker. See #477 cmd += ('.',) helpers.run_setup_cmd(prefix, cmd)
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: helpers.assert_version_default('perl', version) with clean_path_on_failure(_envdir(prefix, version)): with in_env(prefix, version): helpers.run_setup_cmd( prefix, ('cpan', '-T', '.', *additional_dependencies), )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: helpers.assert_version_default('dotnet', version) helpers.assert_no_additional_deps('dotnet', additional_dependencies) envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) with clean_path_on_failure(envdir): build_dir = 'pre-commit-build' # Build & pack nupkg file helpers.run_setup_cmd( prefix, ( 'dotnet', 'pack', '--configuration', 'Release', '--output', build_dir, ), ) # Determine tool from the packaged file <tool_name>.<version>.nupkg build_outputs = os.listdir(os.path.join(prefix.prefix_dir, build_dir)) if len(build_outputs) != 1: raise NotImplementedError( f"Can't handle multiple build outputs. Got {build_outputs}", ) tool_name = build_outputs[0].split('.')[0] # Install to bin dir helpers.run_setup_cmd( prefix, ( 'dotnet', 'tool', 'install', '--tool-path', os.path.join(envdir, BIN_DIR), '--add-source', build_dir, tool_name, ), ) # Cleanup build output for d in ('bin', 'obj', build_dir): rmtree(prefix.path(d))
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: # pragma: win32 no cover additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) with clean_path_on_failure(prefix.path(directory)): # TODO: this currently will fail if there's no version specified and # there's no system ruby installed. Is this ok? _install_rbenv(prefix, version=version) with in_env(prefix, version): # Need to call this before installing so rbenv's directories are # set up helpers.run_setup_cmd(prefix, ("rbenv", "init", "-")) if version != C.DEFAULT: _install_ruby(prefix, version) # Need to call this after installing to set up the shims helpers.run_setup_cmd(prefix, ("rbenv", "rehash")) helpers.run_setup_cmd( prefix, ("gem", "build", *prefix.star(".gemspec")), ) helpers.run_setup_cmd( prefix, ( "gem", "install", "--no-document", *prefix.star(".gem"), *additional_dependencies, ), )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) with clean_path_on_failure(prefix.path(directory)): if version != 'system': # pragma: win32 no cover _install_rbenv(prefix, version) with in_env(prefix, version): # Need to call this before installing so rbenv's directories # are set up helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-')) # XXX: this will *always* fail if `version == C.DEFAULT` _install_ruby(prefix, version) # Need to call this after installing to set up the shims helpers.run_setup_cmd(prefix, ('rbenv', 'rehash')) with in_env(prefix, version): helpers.run_setup_cmd( prefix, ('gem', 'build', *prefix.star('.gemspec')), ) helpers.run_setup_cmd( prefix, ( 'gem', 'install', '--no-document', '--no-format-executable', *prefix.star('.gem'), *additional_dependencies, ), )
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): # pragma: windows no cover additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) with clean_path_on_failure(repo_cmd_runner.path(directory)): # TODO: this currently will fail if there's no version specified and # there's no system ruby installed. Is this ok? _install_rbenv(repo_cmd_runner, version=version) with in_env(repo_cmd_runner, version): # Need to call this before installing so rbenv's directories are # set up helpers.run_setup_cmd(repo_cmd_runner, ('rbenv', 'init', '-')) if version != 'default': _install_ruby(repo_cmd_runner, version) # Need to call this after installing to set up the shims helpers.run_setup_cmd(repo_cmd_runner, ('rbenv', 'rehash')) helpers.run_setup_cmd( repo_cmd_runner, ('gem', 'build') + repo_cmd_runner.star('.gemspec'), ) helpers.run_setup_cmd( repo_cmd_runner, ( ('gem', 'install', '--no-ri', '--no-rdoc') + repo_cmd_runner.star('.gem') + additional_dependencies ), )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) with clean_path_on_failure(prefix.path(directory)): if version != "system": # pragma: win32 no cover _install_rbenv(prefix, version) with in_env(prefix, version): # Need to call this before installing so rbenv's directories # are set up helpers.run_setup_cmd(prefix, ("rbenv", "init", "-")) # XXX: this will *always* fail if `version == C.DEFAULT` _install_ruby(prefix, version) # Need to call this after installing to set up the shims helpers.run_setup_cmd(prefix, ("rbenv", "rehash")) with in_env(prefix, version): helpers.run_setup_cmd( prefix, ("gem", "build", *prefix.star(".gemspec")), ) helpers.run_setup_cmd( prefix, ( "gem", "install", "--no-document", *prefix.star(".gem"), *additional_dependencies, ), )
def install_environment( prefix, version, additional_dependencies, ): # pragma: windows no cover additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) with clean_path_on_failure(prefix.path(directory)): # TODO: this currently will fail if there's no version specified and # there's no system ruby installed. Is this ok? _install_rbenv(prefix, version=version) with in_env(prefix, version): # Need to call this before installing so rbenv's directories are # set up helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-')) if version != 'default': _install_ruby(prefix, version) # Need to call this after installing to set up the shims helpers.run_setup_cmd(prefix, ('rbenv', 'rehash')) helpers.run_setup_cmd( prefix, ('gem', 'build') + prefix.star('.gemspec'), ) helpers.run_setup_cmd( prefix, ('gem', 'install', '--no-ri', '--no-rdoc') + prefix.star('.gem') + additional_dependencies, )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) python = norm_version(version) venv_cmd = (sys.executable, '-mvirtualenv', envdir, '-p', python) install_cmd = ('python', '-mpip', 'install', '.', *additional_dependencies) with clean_path_on_failure(envdir): cmd_output_b(*venv_cmd, cwd='/') with in_env(prefix, version): helpers.run_setup_cmd(prefix, install_cmd)
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: additional_dependencies = tuple(additional_dependencies) assert prefix.exists('package.json') envdir = _envdir(prefix, version) # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx?f=255&MSPPError=-2147217396#maxpath if sys.platform == 'win32': # pragma: no cover envdir = fr'\\?\{os.path.normpath(envdir)}' with clean_path_on_failure(envdir): cmd = [ sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir, ] if version != C.DEFAULT: cmd.extend(['-n', version]) cmd_output_b(*cmd) with in_env(prefix, version): # https://npm.community/t/npm-install-g-git-vs-git-clone-cd-npm-install-g/5449 # install as if we installed from git local_install_cmd = ( 'npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save', ) helpers.run_setup_cmd(prefix, local_install_cmd) _, pkg, _ = cmd_output('npm', 'pack', cwd=prefix.prefix_dir) pkg = prefix.path(pkg.strip()) install = ('npm', 'install', '-g', pkg, *additional_dependencies) helpers.run_setup_cmd(prefix, install) # clean these up after installation if prefix.exists('node_modules'): # pragma: win32 no cover rmtree(prefix.path('node_modules')) os.remove(pkg)
def build_docker_image( prefix: Prefix, *, pull: bool, ) -> None: # pragma: win32 no cover cmd: Tuple[str, ...] = ( 'docker', 'build', '--tag', docker_tag(prefix), '--label', PRE_COMMIT_LABEL, ) if pull: cmd += ('--pull',) # This must come last for old versions of docker. See #477 cmd += ('.',) helpers.run_setup_cmd(prefix, cmd)
def install_environment(prefix, version, additional_dependencies): additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(_dir, version) env_dir = prefix.path(directory) with clean_path_on_failure(env_dir): if version != C.DEFAULT: python = norm_version(version) else: python = os.path.realpath(sys.executable) _make_venv(env_dir, python) with in_env(prefix, version): helpers.run_setup_cmd( prefix, ('pip', 'install', '.') + additional_dependencies, )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: directory = helpers.environment_dir(_dir, version) install = ('python', '-mpip', 'install', '.', *additional_dependencies) env_dir = prefix.path(directory) with clean_path_on_failure(env_dir): if version != C.DEFAULT: python = norm_version(version) else: python = os.path.realpath(sys.executable) _make_venv(env_dir, python) with in_env(prefix, version): helpers.run_setup_cmd(prefix, install)
def install_environment(prefix, version, additional_dependencies): additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) # Install a virtualenv env_dir = prefix.path(directory) with clean_path_on_failure(env_dir): venv_cmd = [sys.executable, '-m', 'virtualenv', env_dir] if version != 'default': venv_cmd.extend(['-p', norm_version(version)]) else: venv_cmd.extend(['-p', os.path.realpath(sys.executable)]) venv_env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1') cmd_output(*venv_cmd, cwd='/', env=venv_env) with in_env(prefix, version): helpers.run_setup_cmd( prefix, ('pip', 'install', '.') + additional_dependencies, )
def _install_dir(prefix_p: Prefix, pub_cache: str) -> None: dart_env = {**os.environ, 'PUB_CACHE': pub_cache} with open(prefix_p.path('pubspec.yaml')) as f: pubspec_contents = yaml_load(f) helpers.run_setup_cmd(prefix_p, ('dart', 'pub', 'get'), env=dart_env) for executable in pubspec_contents['executables']: helpers.run_setup_cmd( prefix_p, ( 'dart', 'compile', 'exe', '--output', os.path.join(bin_dir, win_exe(executable)), prefix_p.path('bin', f'{executable}.dart'), ), env=dart_env, )
def install_environment( repo_cmd_runner, version='default', additional_dependencies=(), ): additional_dependencies = tuple(additional_dependencies) directory = helpers.environment_dir(ENVIRONMENT_DIR, version) # Install a virtualenv with clean_path_on_failure(repo_cmd_runner.path(directory)): venv_cmd = [ sys.executable, '-m', 'virtualenv', '{{prefix}}{0}'.format(directory) ] if version != 'default': venv_cmd.extend(['-p', norm_version(version)]) repo_cmd_runner.run(venv_cmd) with in_env(repo_cmd_runner, version): helpers.run_setup_cmd( repo_cmd_runner, ('pip', 'install', '.') + additional_dependencies, )
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: # pragma: win32 no cover helpers.assert_version_default('lua', version) envdir = _envdir(prefix) with clean_path_on_failure(envdir): with in_env(prefix): # luarocks doesn't bootstrap a tree prior to installing # so ensure the directory exists. os.makedirs(envdir, exist_ok=True) # Older luarocks (e.g., 2.4.2) expect the rockspec as an arg for rockspec in prefix.star('.rockspec'): make_cmd = ('luarocks', '--tree', envdir, 'make', rockspec) helpers.run_setup_cmd(prefix, make_cmd) # luarocks can't install multiple packages at once # so install them individually. for dependency in additional_dependencies: cmd = ('luarocks', '--tree', envdir, 'install', dependency) helpers.run_setup_cmd(prefix, cmd)
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: helpers.assert_version_default('dotnet', version) helpers.assert_no_additional_deps('dotnet', additional_dependencies) envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) with clean_path_on_failure(envdir): build_dir = 'pre-commit-build' # Build & pack nupkg file helpers.run_setup_cmd( prefix, ( 'dotnet', 'pack', '--configuration', 'Release', '--output', build_dir, ), ) # Determine tool from the packaged file <tool_name>.<version>.nupkg build_outputs = os.listdir(os.path.join(prefix.prefix_dir, build_dir)) for output in build_outputs: tool_name = output.split('.')[0] # Install to bin dir helpers.run_setup_cmd( prefix, ( 'dotnet', 'tool', 'install', '--tool-path', os.path.join(envdir, BIN_DIR), '--add-source', build_dir, tool_name, ), ) # Clean the git dir, ignoring the environment dir clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*') helpers.run_setup_cmd(prefix, clean_cmd)
def _install_ruby(runner, version): # pragma: windows no cover try: helpers.run_setup_cmd(runner, ('rbenv', 'download', version)) except CalledProcessError: # pragma: no cover (usually find with download) # Failed to download from mirror for some reason, build it instead helpers.run_setup_cmd(runner, ('rbenv', 'install', version))
def install_environment( prefix: Prefix, version: str, additional_dependencies: Sequence[str], ) -> None: helpers.assert_version_default('dart', version) envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) bin_dir = os.path.join(envdir, 'bin') def _install_dir(prefix_p: Prefix, pub_cache: str) -> None: dart_env = {**os.environ, 'PUB_CACHE': pub_cache} with open(prefix_p.path('pubspec.yaml')) as f: pubspec_contents = yaml_load(f) helpers.run_setup_cmd(prefix_p, ('dart', 'pub', 'get'), env=dart_env) for executable in pubspec_contents['executables']: helpers.run_setup_cmd( prefix_p, ( 'dart', 'compile', 'exe', '--output', os.path.join(bin_dir, win_exe(executable)), prefix_p.path('bin', f'{executable}.dart'), ), env=dart_env, ) with clean_path_on_failure(envdir): os.makedirs(bin_dir) with tempfile.TemporaryDirectory() as tmp: _install_dir(prefix, tmp) for dep_s in additional_dependencies: with tempfile.TemporaryDirectory() as dep_tmp: dep, _, version = dep_s.partition(':') if version: dep_cmd: tuple[str, ...] = (dep, '--version', version) else: dep_cmd = (dep, ) helpers.run_setup_cmd( prefix, ('dart', 'pub', 'cache', 'add', *dep_cmd), env={ **os.environ, 'PUB_CACHE': dep_tmp }, ) # try and find the 'pubspec.yaml' that just got added for root, _, filenames in os.walk(dep_tmp): if 'pubspec.yaml' in filenames: with tempfile.TemporaryDirectory() as copied: pkg = os.path.join(copied, 'pkg') shutil.copytree(root, pkg) _install_dir(Prefix(pkg), dep_tmp) break else: raise AssertionError( f'could not find pubspec.yaml for {dep_s}', )