From e7509272b31867c1461d983ddbc49b074ac25adf Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Mon, 21 Jul 2025 18:16:15 +0200 Subject: [PATCH 1/2] Julia: support language_version --- .github/workflows/languages.yaml | 7 ++++++- pre_commit/languages/julia.py | 7 ++++++- tests/languages/julia_test.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/languages.yaml b/.github/workflows/languages.yaml index fccf2989..e45332ab 100644 --- a/.github/workflows/languages.yaml +++ b/.github/workflows/languages.yaml @@ -67,7 +67,12 @@ jobs: if: matrix.language == 'haskell' - uses: r-lib/actions/setup-r@v2 if: matrix.os == 'ubuntu-latest' && matrix.language == 'r' - + - uses: julia-actions/install-juliaup@v2 + if: matrix.language == 'julia' + with: + channel: 'release' + - run: juliaup add 1.10.10 + if: matrix.language == 'julia' - name: install deps run: python -mpip install -e . -r requirements-dev.txt - name: run tests diff --git a/pre_commit/languages/julia.py b/pre_commit/languages/julia.py index df91c069..910eb8eb 100644 --- a/pre_commit/languages/julia.py +++ b/pre_commit/languages/julia.py @@ -49,8 +49,13 @@ def run_hook( def get_env_patch(target_dir: str, version: str) -> PatchesT: return ( ('JULIA_LOAD_PATH', target_dir), - # May be set, remove it to not interfer with LOAD_PATH + # May be set, remove it to not interfere with LOAD_PATH ('JULIA_PROJECT', UNSET), + # Only set JULIAUP_CHANNEL if we don't want use the system's default + *( + (('JULIAUP_CHANNEL', version),) + if version not in ('system', 'default') else () + ), ) diff --git a/tests/languages/julia_test.py b/tests/languages/julia_test.py index 4ea3c25b..cefd6833 100644 --- a/tests/languages/julia_test.py +++ b/tests/languages/julia_test.py @@ -28,6 +28,22 @@ def test_julia_hook(tmp_path): assert run_language(tmp_path, julia, 'src/main.jl') == expected +def test_julia_hook_version(tmp_path): + code = """ + using Example + function main() + println("Hello, Julia $(VERSION)!") + end + main() + """ + _make_hook(tmp_path, code) + expected = (0, b'Hello, Julia 1.10.10!\n') + assert run_language( + tmp_path, julia, 'src/main.jl', + version='1.10.10', + ) == expected + + def test_julia_hook_manifest(tmp_path): code = """ using Example From 3957ac86224e30abcf3ad064a8dc3d0b1de5d677 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 17:15:00 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/languages/julia_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/languages/julia_test.py b/tests/languages/julia_test.py index c74bd257..2a5d09e7 100644 --- a/tests/languages/julia_test.py +++ b/tests/languages/julia_test.py @@ -30,6 +30,7 @@ def test_julia_hook(tmp_path): expected = (0, b'Hello, world!\n') assert run_language(tmp_path, julia, 'src/main.jl') == expected + def test_julia_hook_version(tmp_path): code = """ using Example @@ -45,6 +46,7 @@ def test_julia_hook_version(tmp_path): version='1.10.10', ) == expected + def test_julia_hook_with_startup(tmp_path): depot_path = tmp_path.joinpath('depot') depot_path.joinpath('config').mkdir(parents=True) @@ -55,6 +57,7 @@ def test_julia_hook_with_startup(tmp_path): with mock.patch.dict(os.environ, {'JULIA_DEPOT_PATH': depo_path_var}): test_julia_hook(tmp_path) + def test_julia_hook_manifest(tmp_path): code = """ using Example