diff --git a/pre_commit/languages/julia.py b/pre_commit/languages/julia.py index 7559b5ba6..5122c3fc2 100644 --- a/pre_commit/languages/julia.py +++ b/pre_commit/languages/julia.py @@ -51,6 +51,13 @@ def get_env_patch(target_dir: str, version: str) -> PatchesT: ('JULIA_LOAD_PATH', target_dir), # May be set, remove it to not interfer with LOAD_PATH ('JULIA_PROJECT', UNSET), + # Keep the package depot inside the hook environment so installed + # packages and precompile caches persist with the env instead of + # leaking into a shared depot. The trailing separator leaves an empty + # entry, which julia expands to its default depots. This keeps the + # bundled stdlib resources (and their precompile caches) available so + # hooks don't recompile from scratch on first run. + ('JULIA_DEPOT_PATH', os.path.join(target_dir, 'depot') + os.pathsep), ) diff --git a/tests/languages/julia_test.py b/tests/languages/julia_test.py index 175622d65..aa7098cfb 100644 --- a/tests/languages/julia_test.py +++ b/tests/languages/julia_test.py @@ -3,7 +3,9 @@ import os from unittest import mock +from pre_commit import constants as C from pre_commit.languages import julia +from pre_commit.prefix import Prefix from testing.language_helpers import run_language from testing.util import cwd @@ -42,6 +44,19 @@ def test_julia_hook_with_startup(tmp_path): test_julia_hook(tmp_path) +def test_julia_hook_installs_into_env_local_depot(tmp_path): + code = """ + using Example + println("Hello, world!") + """ + _make_hook(tmp_path, code) + + julia.install_environment(Prefix(str(tmp_path)), C.DEFAULT, ()) + + d = tmp_path.joinpath('juliaenv-default', 'depot', 'packages', 'Example') + assert d.is_dir() + + def test_julia_hook_manifest(tmp_path): code = """ using Example