diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0817681a..a9bcb79e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,6 @@ - The complete test suite depends on having at least the following installed (possibly not a complete list) - git (Version 2.24.0 or above is required to run pre-merge-commit tests) - - python2 (Required by a test which checks different python versions) - python3 (Required by a test which checks different python versions) - tox (or virtualenv) - ruby + gem diff --git a/pre_commit/languages/rust.py b/pre_commit/languages/rust.py index ef603bc0..204f2aa7 100644 --- a/pre_commit/languages/rust.py +++ b/pre_commit/languages/rust.py @@ -3,7 +3,6 @@ from __future__ import annotations import contextlib import functools import os.path -import platform import shutil import sys import tempfile @@ -99,10 +98,7 @@ def install_rust_with_toolchain(toolchain: str) -> None: if parse_shebang.find_executable('rustup') is None: # We did not detect rustup and need to download it first. if sys.platform == 'win32': # pragma: win32 cover - if platform.machine() == 'x86_64': - url = 'https://win.rustup.rs/x86_64' - else: - url = 'https://win.rustup.rs/i686' + url = 'https://win.rustup.rs/x86_64' else: # pragma: win32 no cover url = 'https://sh.rustup.rs' diff --git a/testing/get-swift.sh b/testing/get-swift.sh index b77e18c0..3e780824 100755 --- a/testing/get-swift.sh +++ b/testing/get-swift.sh @@ -3,9 +3,9 @@ set -euo pipefail . /etc/lsb-release -if [ "$DISTRIB_CODENAME" = "focal" ]; then - SWIFT_URL='https://download.swift.org/swift-5.6.1-release/ubuntu2004/swift-5.6.1-RELEASE/swift-5.6.1-RELEASE-ubuntu20.04.tar.gz' - SWIFT_HASH='2b4f22d4a8b59fe8e050f0b7f020f8d8f12553cbda56709b2340a4a3bb90cfea' +if [ "$DISTRIB_CODENAME" = "jammy" ]; then + SWIFT_URL='https://download.swift.org/swift-5.7.1-release/ubuntu2204/swift-5.7.1-RELEASE/swift-5.7.1-RELEASE-ubuntu22.04.tar.gz' + SWIFT_HASH='7f60291f5088d3e77b0c2364beaabd29616ee7b37260b7b06bdbeb891a7fe161' else echo "unknown dist: ${DISTRIB_CODENAME}" 1>&2 exit 1 diff --git a/testing/resources/dotnet_hooks_combo_repo/proj1/proj1.csproj b/testing/resources/dotnet_hooks_combo_repo/proj1/proj1.csproj index 4f714d33..861ced6d 100644 --- a/testing/resources/dotnet_hooks_combo_repo/proj1/proj1.csproj +++ b/testing/resources/dotnet_hooks_combo_repo/proj1/proj1.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6 true proj1 diff --git a/testing/resources/dotnet_hooks_combo_repo/proj2/proj2.csproj b/testing/resources/dotnet_hooks_combo_repo/proj2/proj2.csproj index da451f7c..dfce2cad 100644 --- a/testing/resources/dotnet_hooks_combo_repo/proj2/proj2.csproj +++ b/testing/resources/dotnet_hooks_combo_repo/proj2/proj2.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6 true proj2 diff --git a/testing/resources/dotnet_hooks_csproj_repo/dotnet_hooks_csproj_repo.csproj b/testing/resources/dotnet_hooks_csproj_repo/dotnet_hooks_csproj_repo.csproj index d2e556ac..fa9879b0 100644 --- a/testing/resources/dotnet_hooks_csproj_repo/dotnet_hooks_csproj_repo.csproj +++ b/testing/resources/dotnet_hooks_csproj_repo/dotnet_hooks_csproj_repo.csproj @@ -1,7 +1,7 @@ Exe - netcoreapp3.1 + net6 true testeroni ./nupkg diff --git a/testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.csproj b/testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.csproj index e3729648..a4e2d005 100644 --- a/testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.csproj +++ b/testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.csproj @@ -1,7 +1,7 @@ Exe - netcoreapp3.1 + net6 true testeroni ./nupkg diff --git a/testing/resources/python3_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/python3_hooks_repo/.pre-commit-hooks.yaml index 964cf836..2c237009 100644 --- a/testing/resources/python3_hooks_repo/.pre-commit-hooks.yaml +++ b/testing/resources/python3_hooks_repo/.pre-commit-hooks.yaml @@ -2,4 +2,5 @@ name: Python 3 Hook entry: python3-hook language: python + language_version: python3 files: \.py$ diff --git a/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml b/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml index 63e1dd4c..364d47d8 100644 --- a/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml +++ b/testing/resources/ruby_versioned_hooks_repo/.pre-commit-hooks.yaml @@ -2,5 +2,5 @@ name: Ruby Hook entry: ruby_hook language: ruby - language_version: 2.5.1 + language_version: 3.1.0 files: \.rb$ diff --git a/tests/languages/ruby_test.py b/tests/languages/ruby_test.py index dc55456e..29f3c802 100644 --- a/tests/languages/ruby_test.py +++ b/tests/languages/ruby_test.py @@ -71,10 +71,10 @@ def test_install_ruby_default(fake_gem_prefix): @xfailif_windows # pragma: win32 no cover def test_install_ruby_with_version(fake_gem_prefix): - ruby.install_environment(fake_gem_prefix, '2.7.2', ()) + ruby.install_environment(fake_gem_prefix, '3.1.0', ()) # Should be able to activate and use rbenv install - with ruby.in_env(fake_gem_prefix, '2.7.2'): + with ruby.in_env(fake_gem_prefix, '3.1.0'): cmd_output('rbenv', 'install', '--help') diff --git a/tests/languages/rust_test.py b/tests/languages/rust_test.py index 9bf97830..f011e719 100644 --- a/tests/languages/rust_test.py +++ b/tests/languages/rust_test.py @@ -68,3 +68,23 @@ def test_installs_with_bootstrapped_rustup(tmpdir, language_version): with rust.in_env(prefix, language_version): assert cmd_output('hello_world')[1] == 'Hello, world!\n' + + +def test_installs_with_existing_rustup(tmpdir): + tmpdir.join('src', 'main.rs').ensure().write( + 'fn main() {\n' + ' println!("Hello, world!");\n' + '}\n', + ) + tmpdir.join('Cargo.toml').ensure().write( + '[package]\n' + 'name = "hello_world"\n' + 'version = "0.1.0"\n' + 'edition = "2021"\n', + ) + prefix = Prefix(str(tmpdir)) + + assert parse_shebang.find_executable('rustup') is not None + rust.install_environment(prefix, '1.56.0', ()) + with rust.in_env(prefix, '1.56.0'): + assert cmd_output('hello_world')[1] == 'Hello, world!\n' diff --git a/tests/repository_test.py b/tests/repository_test.py index 252c126c..8705d886 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -173,30 +173,20 @@ def test_python_venv(tempdir_factory, store): ) -@xfailif_windows # pragma: win32 no cover # no python 2 in GHA -def test_switch_language_versions_doesnt_clobber(tempdir_factory, store): - # We're using the python3 repo because it prints the python version - path = make_repo(tempdir_factory, 'python3_hooks_repo') - - def run_on_version(version, expected_output): - config = make_config_from_repo(path) - config['hooks'][0]['language_version'] = version - hook = _get_hook(config, store, 'python3-hook') - ret, out = _hook_run(hook, [], color=False) - assert ret == 0 - assert _norm_out(out) == expected_output - - run_on_version('python2', b'2\n[]\nHello World\n') - run_on_version('python3', b'3\n[]\nHello World\n') - - -def test_versioned_python_hook(tempdir_factory, store): - _test_hook_repo( - tempdir_factory, store, 'python3_hooks_repo', - 'python3-hook', - [os.devnull], - f'3\n[{os.devnull!r}]\nHello World\n'.encode(), - ) +def test_language_versioned_python_hook(tempdir_factory, store): + # we patch this force virtualenv executing with `-p` since we can't + # reliably have multiple pythons available in CI + with mock.patch.object( + python, + '_sys_executable_matches', + return_value=False, + ): + _test_hook_repo( + tempdir_factory, store, 'python3_hooks_repo', + 'python3-hook', + [os.devnull], + f'3\n[{os.devnull!r}]\nHello World\n'.encode(), + ) @skipif_cant_run_coursier # pragma: win32 no cover @@ -345,7 +335,7 @@ def test_run_versioned_ruby_hook(tempdir_factory, store): tempdir_factory, store, 'ruby_versioned_hooks_repo', 'ruby_hook', [os.devnull], - b'2.5.1\nHello world from a ruby hook\n', + b'3.1.0\nHello world from a ruby hook\n', ) @@ -367,7 +357,7 @@ def test_run_ruby_hook_with_disable_shared_gems( tempdir_factory, store, 'ruby_versioned_hooks_repo', 'ruby_hook', [os.devnull], - b'2.5.1\nHello world from a ruby hook\n', + b'3.1.0\nHello world from a ruby hook\n', ) @@ -883,7 +873,7 @@ def test_tags_on_repositories(in_tmpdir, tempdir_factory, store): @pytest.fixture def local_python_config(): # Make a "local" hooks repo that just installs our other hooks repo - repo_path = get_resource_path('python3_hooks_repo') + repo_path = get_resource_path('python_hooks_repo') manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE)) hooks = [ dict(hook, additional_dependencies=[repo_path]) for hook in manifest @@ -892,23 +882,12 @@ def local_python_config(): def test_local_python_repo(store, local_python_config): - hook = _get_hook(local_python_config, store, 'python3-hook') + hook = _get_hook(local_python_config, store, 'foo') # language_version should have been adjusted to the interpreter version assert hook.language_version != C.DEFAULT ret, out = _hook_run(hook, ('filename',), color=False) assert ret == 0 - assert _norm_out(out) == b"3\n['filename']\nHello World\n" - - -@xfailif_windows # pragma: win32 no cover # no python2 in GHA -def test_local_python_repo_python2(store, local_python_config): - local_python_config['hooks'][0]['language_version'] = 'python2' - hook = _get_hook(local_python_config, store, 'python3-hook') - # language_version should have been adjusted to the interpreter version - assert hook.language_version != C.DEFAULT - ret, out = _hook_run(hook, ('filename',), color=False) - assert ret == 0 - assert _norm_out(out) == b"2\n['filename']\nHello World\n" + assert _norm_out(out) == b"['filename']\nHello World\n" def test_default_language_version(store, local_python_config): diff --git a/tox.ini b/tox.ini index 463b72f3..e06be115 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py37,py38,pypy3,pre-commit [testenv] deps = -rrequirements-dev.txt -passenv = APPDATA HOME LOCALAPPDATA PROGRAMFILES RUSTUP_HOME +passenv = * commands = coverage erase coverage run -m pytest {posargs:tests}