mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 21:10:27 -06:00
upgrade ruby-build
This commit is contained in:
Binary file not shown.
23
pre_commit/make_archives.py → testing/make-archives
Normal file → Executable file
23
pre_commit/make_archives.py → testing/make-archives
Normal file → Executable file
@@ -1,14 +1,13 @@
|
||||
#!/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
|
||||
|
||||
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.
|
||||
@@ -16,7 +15,7 @@ from pre_commit.util import tmpdir
|
||||
|
||||
REPOS = (
|
||||
('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',
|
||||
'git://github.com/garnieretienne/rvm-download',
|
||||
@@ -35,18 +34,18 @@ def make_archive(name: str, repo: str, ref: str, destdir: str) -> str:
|
||||
:param text destdir: Directory to place archives in.
|
||||
"""
|
||||
output_path = os.path.join(destdir, f'{name}.tar.gz')
|
||||
with tmpdir() as tempdir:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
# Clone the repository to the temporary directory
|
||||
cmd_output_b('git', 'clone', repo, tempdir)
|
||||
cmd_output_b('git', 'checkout', ref, cwd=tempdir)
|
||||
subprocess.check_call(('git', 'clone', repo, tmpdir))
|
||||
subprocess.check_call(('git', '-C', tmpdir, '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
|
||||
rmtree(os.path.join(tempdir, '.git'))
|
||||
shutil.rmtree(os.path.join(tmpdir, '.git'))
|
||||
|
||||
with tarfile.open(output_path, 'w|gz') as tf:
|
||||
tf.add(tempdir, name)
|
||||
tf.add(tmpdir, name)
|
||||
|
||||
return output_path
|
||||
|
||||
@@ -56,7 +55,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||
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}')
|
||||
print(f'Making {archive_name}.tar.gz for {repo}@{ref}')
|
||||
make_archive(archive_name, repo, ref, args.dest)
|
||||
return 0
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user