mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
improve julia support
This commit is contained in:
parent
a1d7bed86f
commit
a7f8efa2ae
1 changed files with 12 additions and 12 deletions
|
|
@ -37,7 +37,7 @@ def run_hook(
|
||||||
|
|
||||||
cmd = lang_base.hook_cmd(entry, args)
|
cmd = lang_base.hook_cmd(entry, args)
|
||||||
script = cmd[0] if is_local else prefix.path(cmd[0])
|
script = cmd[0] if is_local else prefix.path(cmd[0])
|
||||||
cmd = ('julia', script, *cmd[1:])
|
cmd = ('julia', '--startup-file=no', script, *cmd[1:])
|
||||||
return lang_base.run_xargs(
|
return lang_base.run_xargs(
|
||||||
cmd,
|
cmd,
|
||||||
file_args,
|
file_args,
|
||||||
|
|
@ -45,14 +45,14 @@ def run_hook(
|
||||||
color=color,
|
color=color,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_env_patch(target_dir: str, version: str) -> PatchesT:
|
def get_env_patch(target_dir: str, version: str) -> PatchesT:
|
||||||
return (
|
patches = [
|
||||||
('JULIA_LOAD_PATH', target_dir),
|
('JULIA_LOAD_PATH', target_dir),
|
||||||
# May be set, remove it to not interfer with LOAD_PATH
|
|
||||||
('JULIA_PROJECT', UNSET),
|
('JULIA_PROJECT', UNSET),
|
||||||
)
|
]
|
||||||
|
if version not in ("system", "default"):
|
||||||
|
patches.append(('JULIAUP_CHANNEL', version))
|
||||||
|
return tuple(patches)
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def in_env(prefix: Prefix, version: str) -> Generator[None]:
|
def in_env(prefix: Prefix, version: str) -> Generator[None]:
|
||||||
|
|
@ -60,7 +60,6 @@ def in_env(prefix: Prefix, version: str) -> Generator[None]:
|
||||||
with envcontext(get_env_patch(envdir, version)):
|
with envcontext(get_env_patch(envdir, version)):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
def install_environment(
|
def install_environment(
|
||||||
prefix: Prefix,
|
prefix: Prefix,
|
||||||
version: str,
|
version: str,
|
||||||
|
|
@ -68,10 +67,6 @@ def install_environment(
|
||||||
) -> None:
|
) -> None:
|
||||||
envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||||
with in_env(prefix, version):
|
with in_env(prefix, version):
|
||||||
# TODO: Support language_version with juliaup similar to rust via
|
|
||||||
# rustup
|
|
||||||
# if version != 'system':
|
|
||||||
# ...
|
|
||||||
|
|
||||||
# Copy Project.toml to hook env if it exist
|
# Copy Project.toml to hook env if it exist
|
||||||
os.makedirs(envdir, exist_ok=True)
|
os.makedirs(envdir, exist_ok=True)
|
||||||
|
|
@ -99,6 +94,11 @@ def install_environment(
|
||||||
shutil.copy(manifest_file, envdir)
|
shutil.copy(manifest_file, envdir)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# copy `src` files if they exist
|
||||||
|
src_dir = prefix.path("src")
|
||||||
|
if os.path.isdir(src_dir):
|
||||||
|
shutil.copytree(src_dir, os.path.join(envdir, 'src'))
|
||||||
|
|
||||||
# Julia code to instantiate the hook environment
|
# Julia code to instantiate the hook environment
|
||||||
julia_code = """
|
julia_code = """
|
||||||
@assert length(ARGS) > 0
|
@assert length(ARGS) > 0
|
||||||
|
|
@ -127,6 +127,6 @@ def install_environment(
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
cmd_output_b(
|
cmd_output_b(
|
||||||
'julia', '-e', julia_code, '--', envdir, *additional_dependencies,
|
'julia', '--startup-file=no', '-e', julia_code, '--', envdir, *additional_dependencies,
|
||||||
cwd=prefix.prefix_dir,
|
cwd=prefix.prefix_dir,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue