diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b5347dfc..dcbe195e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.20.2 + rev: v2.0.0 hooks: - id: mypy additional_dependencies: [types-pyyaml] diff --git a/pre_commit/languages/rust.py b/pre_commit/languages/rust.py index fd77a9d29..4c0a99baf 100644 --- a/pre_commit/languages/rust.py +++ b/pre_commit/languages/rust.py @@ -82,7 +82,7 @@ def _add_dependencies( def install_rust_with_toolchain(toolchain: str, envdir: str) -> None: with tempfile.TemporaryDirectory() as rustup_dir: - with envcontext((('CARGO_HOME', envdir), ('RUSTUP_HOME', rustup_dir))): + with envcontext((('CARGO_HOME', envdir), ('RUSTUP_HOME', envdir))): # acquire `rustup` if not present if parse_shebang.find_executable('rustup') is None: # We did not detect rustup and need to download it first. diff --git a/testing/get-coursier.sh b/testing/get-coursier.sh index 958e73b24..0087feb82 100755 --- a/testing/get-coursier.sh +++ b/testing/get-coursier.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -if [ "$OSTYPE" = msys ]; then +if [ "$OSTYPE" = cygwin ]; then URL='https://github.com/coursier/coursier/releases/download/v2.1.0-RC4/cs-x86_64-pc-win32.zip' SHA256='0d07386ff0f337e3e6264f7dde29d137dda6eaa2385f29741435e0b93ccdb49d' TARGET='/tmp/coursier/cs.zip' diff --git a/testing/get-dart.sh b/testing/get-dart.sh index b4545e71e..ad7f8608a 100755 --- a/testing/get-dart.sh +++ b/testing/get-dart.sh @@ -3,7 +3,7 @@ set -euo pipefail VERSION=2.19.6 -if [ "$OSTYPE" = msys ]; then +if [ "$OSTYPE" = cygwin ]; then URL="https://storage.googleapis.com/dart-archive/channels/stable/release/${VERSION}/sdk/dartsdk-windows-x64-release.zip" cygpath -w /tmp/dart-sdk/bin >> "$GITHUB_PATH" else diff --git a/tests/languages/rust_test.py b/tests/languages/rust_test.py index 52e356134..60e814641 100644 --- a/tests/languages/rust_test.py +++ b/tests/languages/rust_test.py @@ -14,22 +14,38 @@ ACTUAL_GET_DEFAULT_VERSION = rust.get_default_version.__wrapped__ +def requires_locally_installed_cargo(): + return pytest.mark.skipif( + parse_shebang.find_executable('cargo') is None, + reason='Cargo is not installed in the local environment', + ) + +def requires_locally_installed_rustup(): + return pytest.mark.skipif( + parse_shebang.find_executable('rustup') is None, + reason = "Cargo is not installed in the local environment" + ) + + @pytest.fixture def cmd_output_b_mck(): with mock.patch.object(rust, 'cmd_output_b') as mck: yield mck +@requires_locally_installed_cargo() def test_sets_system_when_rust_is_available(cmd_output_b_mck): cmd_output_b_mck.return_value = (0, b'', b'') assert ACTUAL_GET_DEFAULT_VERSION() == 'system' +@requires_locally_installed_cargo() def test_uses_default_when_rust_is_not_available(cmd_output_b_mck): cmd_output_b_mck.return_value = (127, b'', b'error: not found') assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT +@requires_locally_installed_cargo() def test_selects_system_even_if_rust_toolchain_toml(tmp_path): toolchain_toml = '[toolchain]\nchannel = "wtf"\n' tmp_path.joinpath('rust-toolchain.toml').write_text(toolchain_toml) @@ -73,10 +89,9 @@ def mck(exe, env=None): assert calls == ['rustup', 'rustup', 'cargo', 'hello_world'] assert ret == (0, b'Hello, world!\n') - +@requires_locally_installed_rustup() @pytest.mark.parametrize('version', (C.DEFAULT, '1.56.0')) def test_language_version_with_rustup(tmp_path, version): - assert parse_shebang.find_executable('rustup') is not None _make_hello_world(tmp_path) @@ -84,6 +99,7 @@ def test_language_version_with_rustup(tmp_path, version): assert ret == (0, b'Hello, world!\n') +@requires_locally_installed_cargo() @pytest.mark.parametrize('dep', ('cli:shellharden:4.2.0', 'cli:shellharden')) def test_rust_cli_additional_dependencies(tmp_path, dep): _make_local_repo(str(tmp_path)) @@ -102,6 +118,7 @@ def test_rust_cli_additional_dependencies(tmp_path, dep): assert ret == (0, b'echo "$hi"\n') +@requires_locally_installed_cargo() def test_run_lib_additional_dependencies(tmp_path): _make_hello_world(tmp_path)