Remove tarfile_open (tarfile open in 2.7+)

This commit is contained in:
Anthony Sottile 2016-08-31 16:24:30 -07:00
parent 0a810249e3
commit 57cc50e0ad
4 changed files with 8 additions and 19 deletions

View file

@ -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')

View file

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

View file

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