Skip to content

Commit

Permalink
Merge pull request #1854 from pre-commit/upgrade_ruby_build
Browse files Browse the repository at this point in the history
upgrade ruby-build
  • Loading branch information
asottile committed Mar 23, 2021
2 parents 060b719 + 3bada74 commit e431b2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 58 deletions.
Binary file modified pre_commit/resources/ruby-build.tar.gz
Binary file not shown.
23 changes: 11 additions & 12 deletions pre_commit/make_archives.py → testing/make-archives 100644 → 100755
@@ -1,22 +1,21 @@
#!/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.


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',
Expand All @@ -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

Expand All @@ -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

Expand Down
46 changes: 0 additions & 46 deletions tests/make_archives_test.py

This file was deleted.

0 comments on commit e431b2b

Please sign in to comment.