mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
Merge pull request #407 from pre-commit/nopy26_tarfile_open
Remove tarfile_open (tarfile open in 2.7+)
This commit is contained in:
@@ -4,6 +4,7 @@ import contextlib
|
||||
import io
|
||||
import os.path
|
||||
import shutil
|
||||
import tarfile
|
||||
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import Var
|
||||
@@ -11,7 +12,6 @@ from pre_commit.languages import helpers
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import resource_filename
|
||||
from pre_commit.util import tarfile_open
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ def in_env(repo_cmd_runner, language_version):
|
||||
def _install_rbenv(repo_cmd_runner, version='default'):
|
||||
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
||||
|
||||
with tarfile_open(resource_filename('rbenv.tar.gz')) as tf:
|
||||
with tarfile.open(resource_filename('rbenv.tar.gz')) as tf:
|
||||
tf.extractall(repo_cmd_runner.path('.'))
|
||||
shutil.move(
|
||||
repo_cmd_runner.path('rbenv'), repo_cmd_runner.path(directory),
|
||||
@@ -55,11 +55,11 @@ def _install_rbenv(repo_cmd_runner, version='default'):
|
||||
# Only install ruby-build if the version is specified
|
||||
if version != 'default':
|
||||
# ruby-download
|
||||
with tarfile_open(resource_filename('ruby-download.tar.gz')) as tf:
|
||||
with tarfile.open(resource_filename('ruby-download.tar.gz')) as tf:
|
||||
tf.extractall(repo_cmd_runner.path(directory, 'plugins'))
|
||||
|
||||
# ruby-build
|
||||
with tarfile_open(resource_filename('ruby-build.tar.gz')) as tf:
|
||||
with tarfile.open(resource_filename('ruby-build.tar.gz')) as tf:
|
||||
tf.extractall(repo_cmd_runner.path(directory, 'plugins'))
|
||||
|
||||
activate_path = repo_cmd_runner.path(directory, 'bin', 'activate')
|
||||
|
||||
@@ -3,12 +3,12 @@ from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import tarfile
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import rmtree
|
||||
from pre_commit.util import tarfile_open
|
||||
from pre_commit.util import tmpdir
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ def make_archive(name, repo, ref, destdir):
|
||||
# runtime
|
||||
rmtree(os.path.join(tempdir, '.git'))
|
||||
|
||||
with tarfile_open(five.n(output_path), 'w|gz') as tf:
|
||||
with tarfile.open(five.n(output_path), 'w|gz') as tf:
|
||||
tf.add(tempdir, name)
|
||||
|
||||
return output_path
|
||||
|
||||
@@ -8,7 +8,6 @@ import os.path
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
import pkg_resources
|
||||
@@ -82,16 +81,6 @@ def no_git_env():
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tarfile_open(*args, **kwargs):
|
||||
"""Compatibility layer because python2.6"""
|
||||
tf = tarfile.open(*args, **kwargs)
|
||||
try:
|
||||
yield tf
|
||||
finally:
|
||||
tf.close()
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tmpdir():
|
||||
"""Contextmanager to create a temporary directory. It will be cleaned up
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import tarfile
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
@@ -9,7 +10,6 @@ import pytest
|
||||
from pre_commit import make_archives
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import tarfile_open
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import get_head_sha
|
||||
from testing.util import skipif_slowtests_false
|
||||
@@ -41,7 +41,7 @@ def test_make_archive(tempdir_factory):
|
||||
extract_dir = tempdir_factory.get()
|
||||
|
||||
# Extract the tar
|
||||
with tarfile_open(archive_path) as tf:
|
||||
with tarfile.open(archive_path) as tf:
|
||||
tf.extractall(extract_dir)
|
||||
|
||||
# Verify the contents of the tar
|
||||
|
||||
Reference in New Issue
Block a user