From 35f0c72f09eaa652cb468ed1b4ad7c707ed83c5e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 10 Apr 2021 16:27:54 +0200 Subject: Merging upstream version 2.12.0. Signed-off-by: Daniel Baumann --- .pre-commit-config.yaml | 12 +++--- CHANGELOG.md | 16 +++++++ pre_commit/make_archives.py | 65 ----------------------------- pre_commit/resources/rbenv.tar.gz | Bin 34224 -> 34250 bytes pre_commit/resources/ruby-build.tar.gz | Bin 72807 -> 74218 bytes pre_commit/resources/ruby-download.tar.gz | Bin 5343 -> 5533 bytes pre_commit/xargs.py | 4 +- setup.cfg | 12 +++--- testing/make-archives | 67 ++++++++++++++++++++++++++++++ tests/languages/ruby_test.py | 13 ++++++ tests/make_archives_test.py | 46 -------------------- 11 files changed, 111 insertions(+), 124 deletions(-) delete mode 100644 pre_commit/make_archives.py create mode 100755 testing/make-archives delete mode 100644 tests/make_archives_test.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bcfde90..0c6d636 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,21 +11,21 @@ repos: - id: name-tests-test - id: requirements-txt-fixer - id: double-quote-string-fixer -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 +- repo: https://github.com/PyCQA/flake8 + rev: 3.9.0 hooks: - id: flake8 additional_dependencies: [flake8-typing-imports==1.10.0] - repo: https://github.com/pre-commit/mirrors-autopep8 - rev: v1.5.4 + rev: v1.5.6 hooks: - id: autopep8 - repo: https://github.com/pre-commit/pre-commit - rev: v2.11.1 + rev: v2.12.0 hooks: - id: validate_manifest - repo: https://github.com/asottile/pyupgrade - rev: v2.10.0 + rev: v2.11.0 hooks: - id: pyupgrade args: [--py36-plus] @@ -40,7 +40,7 @@ repos: - id: add-trailing-comma args: [--py36-plus] - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.16.0 + rev: v1.17.0 hooks: - id: setup-cfg-fmt - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/CHANGELOG.md b/CHANGELOG.md index 5da7866..2d6a35d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 =================== diff --git a/pre_commit/make_archives.py b/pre_commit/make_archives.py deleted file mode 100644 index d320b83..0000000 --- a/pre_commit/make_archives.py +++ /dev/null @@ -1,65 +0,0 @@ -import argparse -import os.path -import tarfile -from typing import Optional -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 -# dependencies. Currently it's just for "vendoring" ruby support packages. - - -REPOS = ( - ('rbenv', 'git://github.com/rbenv/rbenv', '0843745'), - ('ruby-build', 'git://github.com/rbenv/ruby-build', '258455e'), - ( - 'ruby-download', - 'git://github.com/garnieretienne/rvm-download', - '09bd7c6', - ), -) - - -def make_archive(name: str, repo: str, ref: str, destdir: str) -> str: - """Makes an archive of a repository in the given destdir. - - :param text name: Name to give the archive. For instance foo. The file - that is created will be called foo.tar.gz. - :param text repo: Repository to clone. - :param text ref: Tag/SHA/branch to check out. - :param text destdir: Directory to place archives in. - """ - output_path = os.path.join(destdir, f'{name}.tar.gz') - with tmpdir() as tempdir: - # Clone the repository to the temporary directory - cmd_output_b('git', 'clone', repo, tempdir) - cmd_output_b('git', 'checkout', ref, cwd=tempdir) - - # We don't want the '.git' directory - # It adds a bunch of size to the archive and we don't use it at - # runtime - rmtree(os.path.join(tempdir, '.git')) - - with tarfile.open(output_path, 'w|gz') as tf: - tf.add(tempdir, name) - - return output_path - - -def main(argv: Optional[Sequence[str]] = None) -> int: - parser = argparse.ArgumentParser() - parser.add_argument('--dest', default='pre_commit/resources') - args = parser.parse_args(argv) - for archive_name, repo, ref in REPOS: - output.write_line(f'Making {archive_name}.tar.gz for {repo}@{ref}') - make_archive(archive_name, repo, ref, args.dest) - return 0 - - -if __name__ == '__main__': - exit(main()) diff --git a/pre_commit/resources/rbenv.tar.gz b/pre_commit/resources/rbenv.tar.gz index 97ac469..95b5a36 100644 Binary files a/pre_commit/resources/rbenv.tar.gz and b/pre_commit/resources/rbenv.tar.gz differ diff --git a/pre_commit/resources/ruby-build.tar.gz b/pre_commit/resources/ruby-build.tar.gz index 4412ed4..ef82e2f 100644 Binary files a/pre_commit/resources/ruby-build.tar.gz and b/pre_commit/resources/ruby-build.tar.gz differ diff --git a/pre_commit/resources/ruby-download.tar.gz b/pre_commit/resources/ruby-download.tar.gz index 7ccfb6c..2e19507 100644 Binary files a/pre_commit/resources/ruby-download.tar.gz and b/pre_commit/resources/ruby-download.tar.gz differ diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py index 60a057c..6b0fa20 100644 --- a/pre_commit/xargs.py +++ b/pre_commit/xargs.py @@ -145,7 +145,9 @@ def xargs( # this is implementation details but the command gets translated into # full/path/to/cmd.exe /c *cmd 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) diff --git a/setup.cfg b/setup.cfg index a14e95d..b336e58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pre_commit -version = 2.11.1 +version = 2.12.0 description = A framework for managing and maintaining multi-language pre-commit hooks. long_description = file: README.md long_description_content_type = text/markdown @@ -33,6 +33,11 @@ install_requires = importlib-resources;python_version<"3.7" python_requires = >=3.6.1 +[options.packages.find] +exclude = + tests* + testing* + [options.entry_points] console_scripts = pre-commit = pre_commit.main:main @@ -45,11 +50,6 @@ pre_commit.resources = empty_template_* hook-tmpl -[options.packages.find] -exclude = - tests* - testing* - [bdist_wheel] universal = True diff --git a/testing/make-archives b/testing/make-archives new file mode 100755 index 0000000..b2b288c --- /dev/null +++ b/testing/make-archives @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import argparse +import os.path +import shutil +import subprocess +import tarfile +import tempfile +from typing import Optional +from typing import Sequence + + +# This is a script for generating the tarred resources for git repo +# dependencies. Currently it's just for "vendoring" ruby support packages. + + +REPOS = ( + ('rbenv', 'git://github.com/rbenv/rbenv', '0843745'), + ('ruby-build', 'git://github.com/rbenv/ruby-build', '500863c'), + ( + 'ruby-download', + 'git://github.com/garnieretienne/rvm-download', + '09bd7c6', + ), +) + + +def make_archive(name: str, repo: str, ref: str, destdir: str) -> str: + """Makes an archive of a repository in the given destdir. + + :param text name: Name to give the archive. For instance foo. The file + that is created will be called foo.tar.gz. + :param text repo: Repository to clone. + :param text ref: Tag/SHA/branch to check out. + :param text destdir: Directory to place archives in. + """ + output_path = os.path.join(destdir, f'{name}.tar.gz') + 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 + subprocess.check_call(('git', 'clone', repo, gitdir)) + subprocess.check_call(('git', '-C', gitdir, 'checkout', ref)) + + # We don't want the '.git' directory + # It adds a bunch of size to the archive and we don't use it at + # runtime + shutil.rmtree(os.path.join(gitdir, '.git')) + + with tarfile.open(output_path, 'w|gz') as tf: + tf.add(gitdir, name) + + return output_path + + +def main(argv: Optional[Sequence[str]] = None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument('--dest', default='pre_commit/resources') + args = parser.parse_args(argv) + for archive_name, repo, ref in REPOS: + print(f'Making {archive_name}.tar.gz for {repo}@{ref}') + make_archive(archive_name, repo, ref, args.dest) + return 0 + + +if __name__ == '__main__': + exit(main()) diff --git a/tests/languages/ruby_test.py b/tests/languages/ruby_test.py index 6c0c9e5..0c6cfed 100644 --- a/tests/languages/ruby_test.py +++ b/tests/languages/ruby_test.py @@ -1,4 +1,5 @@ import os.path +import tarfile from unittest import mock import pytest @@ -8,6 +9,7 @@ from pre_commit import parse_shebang from pre_commit.languages import ruby from pre_commit.prefix import Prefix from pre_commit.util import cmd_output +from pre_commit.util import resource_bytesio 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 with ruby.in_env(fake_gem_prefix, '2.7.2'): 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' diff --git a/tests/make_archives_test.py b/tests/make_archives_test.py deleted file mode 100644 index 6ae2f8e..0000000 --- a/tests/make_archives_test.py +++ /dev/null @@ -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() -- cgit v1.2.3