ensure coursier hooks are available offline after install

This commit is contained in:
Anthony Sottile 2023-01-25 14:03:39 -05:00
parent 6b88fe577c
commit 83e05e607e

View file

@ -28,45 +28,44 @@ def install_environment(
helpers.assert_version_default('coursier', version) helpers.assert_version_default('coursier', version)
# Support both possible executable names (either "cs" or "coursier") # Support both possible executable names (either "cs" or "coursier")
executable = find_executable('cs') or find_executable('coursier') cs = find_executable('cs') or find_executable('coursier')
if executable is None: if cs is None:
raise AssertionError( raise AssertionError(
'pre-commit requires system-installed "cs" or "coursier" ' 'pre-commit requires system-installed "cs" or "coursier" '
'executables in the application search path', 'executables in the application search path',
) )
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version) envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
channel = prefix.path('.pre-commit-channel')
if os.path.isdir(channel): def _install(*opts: str) -> None:
for app_descriptor in os.listdir(channel): assert cs is not None
_, app_file = os.path.split(app_descriptor) helpers.run_setup_cmd(prefix, (cs, 'fetch', *opts))
app, _ = os.path.splitext(app_file) helpers.run_setup_cmd(prefix, (cs, 'install', '--dir', envdir, *opts))
helpers.run_setup_cmd(
prefix, with in_env(prefix, version):
( channel = prefix.path('.pre-commit-channel')
executable, if os.path.isdir(channel):
'install', for app_descriptor in os.listdir(channel):
_, app_file = os.path.split(app_descriptor)
app, _ = os.path.splitext(app_file)
_install(
'--default-channels=false', '--default-channels=false',
'--channel', channel, '--channel', channel,
'--dir', envdir,
app, app,
), )
elif not additional_dependencies:
raise FatalError(
'expected .pre-commit-channel dir or additional_dependencies',
) )
elif not additional_dependencies:
raise FatalError(
'expected .pre-commit-channel dir or additional_dependencies',
)
if additional_dependencies: if additional_dependencies:
install_cmd = ( _install(*additional_dependencies)
executable, 'install', '--dir', envdir, *additional_dependencies,
)
helpers.run_setup_cmd(prefix, install_cmd)
def get_env_patch(target_dir: str) -> PatchesT: def get_env_patch(target_dir: str) -> PatchesT:
return ( return (
('PATH', (target_dir, os.pathsep, Var('PATH'))), ('PATH', (target_dir, os.pathsep, Var('PATH'))),
('COURSIER_CACHE', os.path.join(target_dir, '.cs-cache')),
) )