summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x[-rw-r--r--]testing/make-archives (renamed from pre_commit/make_archives.py)26
1 files changed, 14 insertions, 12 deletions
diff --git a/pre_commit/make_archives.py b/testing/make-archives
index d320b83..b2b288c 100644..100755
--- a/pre_commit/make_archives.py
+++ b/testing/make-archives
@@ -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,21 @@ 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:
+ # this ensures that the root directory has umask permissions
+ gitdir = os.path.join(tmpdir, 'root')
+
# 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, 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
- rmtree(os.path.join(tempdir, '.git'))
+ shutil.rmtree(os.path.join(gitdir, '.git'))
with tarfile.open(output_path, 'w|gz') as tf:
- tf.add(tempdir, name)
+ tf.add(gitdir, name)
return output_path
@@ -56,7 +58,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