1
0
Fork 0

Merging upstream version 2.12.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:26:51 +01:00
parent 4664708450
commit 9b2e8c29eb
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
10 changed files with 58 additions and 71 deletions

View file

@ -11,21 +11,21 @@ repos:
- id: name-tests-test - id: name-tests-test
- id: requirements-txt-fixer - id: requirements-txt-fixer
- id: double-quote-string-fixer - id: double-quote-string-fixer
- repo: https://gitlab.com/pycqa/flake8 - repo: https://github.com/PyCQA/flake8
rev: 3.8.4 rev: 3.9.0
hooks: hooks:
- id: flake8 - id: flake8
additional_dependencies: [flake8-typing-imports==1.10.0] additional_dependencies: [flake8-typing-imports==1.10.0]
- repo: https://github.com/pre-commit/mirrors-autopep8 - repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.4 rev: v1.5.6
hooks: hooks:
- id: autopep8 - id: autopep8
- repo: https://github.com/pre-commit/pre-commit - repo: https://github.com/pre-commit/pre-commit
rev: v2.11.1 rev: v2.12.0
hooks: hooks:
- id: validate_manifest - id: validate_manifest
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.10.0 rev: v2.11.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py36-plus] args: [--py36-plus]
@ -40,7 +40,7 @@ repos:
- id: add-trailing-comma - id: add-trailing-comma
args: [--py36-plus] args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt - repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.16.0 rev: v1.17.0
hooks: hooks:
- id: setup-cfg-fmt - id: setup-cfg-fmt
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy

View file

@ -1,3 +1,19 @@
2.12.0 - 2021-04-06
===================
### Features
- Upgrade rbenv.
- #1854 PR by @asottile.
- #1848 issue by @sirosen.
### Fixes
- Give command length a little more room when running batch files on windows
so underlying commands can expand further.
- #1864 PR by @asottile.
- pre-commit/mirrors-prettier#7 issue by @DeltaXWizard.
- Fix permissions of root folder in ruby archives.
- #1868 PR by @asottile.
2.11.1 - 2021-03-09 2.11.1 - 2021-03-09
=================== ===================

Binary file not shown.

View file

@ -145,7 +145,9 @@ def xargs(
# this is implementation details but the command gets translated into # this is implementation details but the command gets translated into
# full/path/to/cmd.exe /c *cmd # full/path/to/cmd.exe /c *cmd
cmd_exe = parse_shebang.find_executable('cmd.exe') cmd_exe = parse_shebang.find_executable('cmd.exe')
_max_length = 8192 - len(cmd_exe) - len(' /c ') # 1024 is additionally subtracted to give headroom for further
# expansion inside the batch file
_max_length = 8192 - len(cmd_exe) - len(' /c ') - 1024
partitions = partition(cmd, varargs, target_concurrency, _max_length) partitions = partition(cmd, varargs, target_concurrency, _max_length)

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = pre_commit name = pre_commit
version = 2.11.1 version = 2.12.0
description = A framework for managing and maintaining multi-language pre-commit hooks. description = A framework for managing and maintaining multi-language pre-commit hooks.
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
@ -33,6 +33,11 @@ install_requires =
importlib-resources;python_version<"3.7" importlib-resources;python_version<"3.7"
python_requires = >=3.6.1 python_requires = >=3.6.1
[options.packages.find]
exclude =
tests*
testing*
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
pre-commit = pre_commit.main:main pre-commit = pre_commit.main:main
@ -45,11 +50,6 @@ pre_commit.resources =
empty_template_* empty_template_*
hook-tmpl hook-tmpl
[options.packages.find]
exclude =
tests*
testing*
[bdist_wheel] [bdist_wheel]
universal = True universal = True

26
pre_commit/make_archives.py → testing/make-archives Normal file → Executable file
View file

@ -1,14 +1,13 @@
#!/usr/bin/env python3
import argparse import argparse
import os.path import os.path
import shutil
import subprocess
import tarfile import tarfile
import tempfile
from typing import Optional from typing import Optional
from typing import Sequence from typing import Sequence
from pre_commit import output
from pre_commit.util import cmd_output_b
from pre_commit.util import rmtree
from pre_commit.util import tmpdir
# This is a script for generating the tarred resources for git repo # This is a script for generating the tarred resources for git repo
# dependencies. Currently it's just for "vendoring" ruby support packages. # dependencies. Currently it's just for "vendoring" ruby support packages.
@ -16,7 +15,7 @@ from pre_commit.util import tmpdir
REPOS = ( REPOS = (
('rbenv', 'git://github.com/rbenv/rbenv', '0843745'), ('rbenv', 'git://github.com/rbenv/rbenv', '0843745'),
('ruby-build', 'git://github.com/rbenv/ruby-build', '258455e'), ('ruby-build', 'git://github.com/rbenv/ruby-build', '500863c'),
( (
'ruby-download', 'ruby-download',
'git://github.com/garnieretienne/rvm-download', 'git://github.com/garnieretienne/rvm-download',
@ -35,18 +34,21 @@ def make_archive(name: str, repo: str, ref: str, destdir: str) -> str:
:param text destdir: Directory to place archives in. :param text destdir: Directory to place archives in.
""" """
output_path = os.path.join(destdir, f'{name}.tar.gz') output_path = os.path.join(destdir, f'{name}.tar.gz')
with tmpdir() as tempdir: with tempfile.TemporaryDirectory() as tmpdir:
# this ensures that the root directory has umask permissions
gitdir = os.path.join(tmpdir, 'root')
# Clone the repository to the temporary directory # Clone the repository to the temporary directory
cmd_output_b('git', 'clone', repo, tempdir) subprocess.check_call(('git', 'clone', repo, gitdir))
cmd_output_b('git', 'checkout', ref, cwd=tempdir) subprocess.check_call(('git', '-C', gitdir, 'checkout', ref))
# We don't want the '.git' directory # We don't want the '.git' directory
# It adds a bunch of size to the archive and we don't use it at # It adds a bunch of size to the archive and we don't use it at
# runtime # runtime
rmtree(os.path.join(tempdir, '.git')) shutil.rmtree(os.path.join(gitdir, '.git'))
with tarfile.open(output_path, 'w|gz') as tf: with tarfile.open(output_path, 'w|gz') as tf:
tf.add(tempdir, name) tf.add(gitdir, name)
return output_path return output_path
@ -56,7 +58,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
parser.add_argument('--dest', default='pre_commit/resources') parser.add_argument('--dest', default='pre_commit/resources')
args = parser.parse_args(argv) args = parser.parse_args(argv)
for archive_name, repo, ref in REPOS: for archive_name, repo, ref in REPOS:
output.write_line(f'Making {archive_name}.tar.gz for {repo}@{ref}') print(f'Making {archive_name}.tar.gz for {repo}@{ref}')
make_archive(archive_name, repo, ref, args.dest) make_archive(archive_name, repo, ref, args.dest)
return 0 return 0

View file

@ -1,4 +1,5 @@
import os.path import os.path
import tarfile
from unittest import mock from unittest import mock
import pytest import pytest
@ -8,6 +9,7 @@ from pre_commit import parse_shebang
from pre_commit.languages import ruby from pre_commit.languages import ruby
from pre_commit.prefix import Prefix from pre_commit.prefix import Prefix
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.util import resource_bytesio
from testing.util import xfailif_windows from testing.util import xfailif_windows
@ -72,3 +74,14 @@ def test_install_ruby_with_version(fake_gem_prefix):
# 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, '2.7.2'):
cmd_output('rbenv', 'install', '--help') cmd_output('rbenv', 'install', '--help')
@pytest.mark.parametrize(
'filename',
('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'),
)
def test_archive_root_stat(filename):
with resource_bytesio(filename) as f:
with tarfile.open(fileobj=f) as tarf:
root, _, _ = filename.partition('.')
assert oct(tarf.getmember(root).mode) == '0o755'

View file

@ -1,46 +0,0 @@
import tarfile
from pre_commit import git
from pre_commit import make_archives
from pre_commit.util import cmd_output
from testing.util import git_commit
def test_make_archive(in_git_dir, tmpdir):
output_dir = tmpdir.join('output').ensure_dir()
# Add a files to the git directory
in_git_dir.join('foo').ensure()
cmd_output('git', 'add', '.')
git_commit()
# We'll use this rev
head_rev = git.head_rev('.')
# And check that this file doesn't exist
in_git_dir.join('bar').ensure()
cmd_output('git', 'add', '.')
git_commit()
# Do the thing
archive_path = make_archives.make_archive(
'foo', in_git_dir.strpath, head_rev, output_dir.strpath,
)
expected = output_dir.join('foo.tar.gz')
assert archive_path == expected.strpath
assert expected.exists()
extract_dir = tmpdir.join('extract').ensure_dir()
with tarfile.open(archive_path) as tf:
tf.extractall(extract_dir.strpath)
# Verify the contents of the tar
assert extract_dir.join('foo').isdir()
assert extract_dir.join('foo/foo').exists()
assert not extract_dir.join('foo/.git').exists()
assert not extract_dir.join('foo/bar').exists()
def test_main(tmpdir):
make_archives.main(('--dest', tmpdir.strpath))
for archive, _, _ in make_archives.REPOS:
assert tmpdir.join(f'{archive}.tar.gz').exists()