mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
upgrade ruby-build
This commit is contained in:
parent
060b719d44
commit
3bada745ea
3 changed files with 11 additions and 58 deletions
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 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,18 @@ 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:
|
||||||
# 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, tmpdir))
|
||||||
cmd_output_b('git', 'checkout', ref, cwd=tempdir)
|
subprocess.check_call(('git', '-C', tmpdir, '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(tmpdir, '.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(tmpdir, name)
|
||||||
|
|
||||||
return output_path
|
return output_path
|
||||||
|
|
||||||
|
|
@ -56,7 +55,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
|
||||||
|
|
||||||
|
|
@ -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()
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue