Merge pull request #2634 from pre-commit/fix-ci

fix CI
This commit is contained in:
Anthony Sottile 2022-12-12 13:02:24 -05:00 committed by GitHub
commit f9b28cc2b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 52 additions and 57 deletions

View file

@ -5,7 +5,6 @@
- The complete test suite depends on having at least the following installed - The complete test suite depends on having at least the following installed
(possibly not a complete list) (possibly not a complete list)
- git (Version 2.24.0 or above is required to run pre-merge-commit tests) - 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) - python3 (Required by a test which checks different python versions)
- tox (or virtualenv) - tox (or virtualenv)
- ruby + gem - ruby + gem

View file

@ -3,7 +3,6 @@ from __future__ import annotations
import contextlib import contextlib
import functools import functools
import os.path import os.path
import platform
import shutil import shutil
import sys import sys
import tempfile import tempfile
@ -99,10 +98,7 @@ def install_rust_with_toolchain(toolchain: str) -> None:
if parse_shebang.find_executable('rustup') is None: if parse_shebang.find_executable('rustup') is None:
# We did not detect rustup and need to download it first. # We did not detect rustup and need to download it first.
if sys.platform == 'win32': # pragma: win32 cover if sys.platform == 'win32': # pragma: win32 cover
if platform.machine() == 'x86_64': url = 'https://win.rustup.rs/x86_64'
url = 'https://win.rustup.rs/x86_64'
else:
url = 'https://win.rustup.rs/i686'
else: # pragma: win32 no cover else: # pragma: win32 no cover
url = 'https://sh.rustup.rs' url = 'https://sh.rustup.rs'

View file

@ -3,9 +3,9 @@
set -euo pipefail set -euo pipefail
. /etc/lsb-release . /etc/lsb-release
if [ "$DISTRIB_CODENAME" = "focal" ]; then if [ "$DISTRIB_CODENAME" = "jammy" ]; 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_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='2b4f22d4a8b59fe8e050f0b7f020f8d8f12553cbda56709b2340a4a3bb90cfea' SWIFT_HASH='7f60291f5088d3e77b0c2364beaabd29616ee7b37260b7b06bdbeb891a7fe161'
else else
echo "unknown dist: ${DISTRIB_CODENAME}" 1>&2 echo "unknown dist: ${DISTRIB_CODENAME}" 1>&2
exit 1 exit 1

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6</TargetFramework>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>proj1</ToolCommandName> <ToolCommandName>proj1</ToolCommandName>

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6</TargetFramework>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>proj2</ToolCommandName> <ToolCommandName>proj2</ToolCommandName>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net6</TargetFramework>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>testeroni</ToolCommandName> <ToolCommandName>testeroni</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath> <PackageOutputPath>./nupkg</PackageOutputPath>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net6</TargetFramework>
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<ToolCommandName>testeroni</ToolCommandName> <ToolCommandName>testeroni</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath> <PackageOutputPath>./nupkg</PackageOutputPath>

View file

@ -2,4 +2,5 @@
name: Python 3 Hook name: Python 3 Hook
entry: python3-hook entry: python3-hook
language: python language: python
language_version: python3
files: \.py$ files: \.py$

View file

@ -2,5 +2,5 @@
name: Ruby Hook name: Ruby Hook
entry: ruby_hook entry: ruby_hook
language: ruby language: ruby
language_version: 2.5.1 language_version: 3.1.0
files: \.rb$ files: \.rb$

View file

@ -71,10 +71,10 @@ def test_install_ruby_default(fake_gem_prefix):
@xfailif_windows # pragma: win32 no cover @xfailif_windows # pragma: win32 no cover
def test_install_ruby_with_version(fake_gem_prefix): 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 # 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') cmd_output('rbenv', 'install', '--help')

View file

@ -68,3 +68,23 @@ def test_installs_with_bootstrapped_rustup(tmpdir, language_version):
with rust.in_env(prefix, language_version): with rust.in_env(prefix, language_version):
assert cmd_output('hello_world')[1] == 'Hello, world!\n' 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'

View file

@ -173,30 +173,20 @@ def test_python_venv(tempdir_factory, store):
) )
@xfailif_windows # pragma: win32 no cover # no python 2 in GHA def test_language_versioned_python_hook(tempdir_factory, store):
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store): # we patch this force virtualenv executing with `-p` since we can't
# We're using the python3 repo because it prints the python version # reliably have multiple pythons available in CI
path = make_repo(tempdir_factory, 'python3_hooks_repo') with mock.patch.object(
python,
def run_on_version(version, expected_output): '_sys_executable_matches',
config = make_config_from_repo(path) return_value=False,
config['hooks'][0]['language_version'] = version ):
hook = _get_hook(config, store, 'python3-hook') _test_hook_repo(
ret, out = _hook_run(hook, [], color=False) tempdir_factory, store, 'python3_hooks_repo',
assert ret == 0 'python3-hook',
assert _norm_out(out) == expected_output [os.devnull],
f'3\n[{os.devnull!r}]\nHello World\n'.encode(),
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(),
)
@skipif_cant_run_coursier # pragma: win32 no cover @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', tempdir_factory, store, 'ruby_versioned_hooks_repo',
'ruby_hook', 'ruby_hook',
[os.devnull], [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', tempdir_factory, store, 'ruby_versioned_hooks_repo',
'ruby_hook', 'ruby_hook',
[os.devnull], [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 @pytest.fixture
def local_python_config(): def local_python_config():
# Make a "local" hooks repo that just installs our other hooks repo # 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)) manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
hooks = [ hooks = [
dict(hook, additional_dependencies=[repo_path]) for hook in manifest 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): 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 # language_version should have been adjusted to the interpreter version
assert hook.language_version != C.DEFAULT assert hook.language_version != C.DEFAULT
ret, out = _hook_run(hook, ('filename',), color=False) ret, out = _hook_run(hook, ('filename',), color=False)
assert ret == 0 assert ret == 0
assert _norm_out(out) == b"3\n['filename']\nHello World\n" assert _norm_out(out) == b"['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"
def test_default_language_version(store, local_python_config): def test_default_language_version(store, local_python_config):

View file

@ -3,7 +3,7 @@ envlist = py37,py38,pypy3,pre-commit
[testenv] [testenv]
deps = -rrequirements-dev.txt deps = -rrequirements-dev.txt
passenv = APPDATA HOME LOCALAPPDATA PROGRAMFILES RUSTUP_HOME passenv = *
commands = commands =
coverage erase coverage erase
coverage run -m pytest {posargs:tests} coverage run -m pytest {posargs:tests}