Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c6484b

Browse files
authored
Merge pull request #407 from pre-commit/nopy26_tarfile_open
Remove tarfile_open (tarfile open in 2.7+)
2 parents f2f3054 + 57cc50e commit 9c6484b

4 files changed

Lines changed: 8 additions & 19 deletions

File tree

pre_commit/languages/ruby.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import io
55
import os.path
66
import shutil
7+
import tarfile
78

89
from pre_commit.envcontext import envcontext
910
from pre_commit.envcontext import Var
1011
from pre_commit.languages import helpers
1112
from pre_commit.util import CalledProcessError
1213
from pre_commit.util import clean_path_on_failure
1314
from pre_commit.util import resource_filename
14-
from pre_commit.util import tarfile_open
1515
from pre_commit.xargs import xargs
1616

1717

@@ -46,7 +46,7 @@ def in_env(repo_cmd_runner, language_version):
4646
def _install_rbenv(repo_cmd_runner, version='default'):
4747
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
4848

49-
with tarfile_open(resource_filename('rbenv.tar.gz')) as tf:
49+
with tarfile.open(resource_filename('rbenv.tar.gz')) as tf:
5050
tf.extractall(repo_cmd_runner.path('.'))
5151
shutil.move(
5252
repo_cmd_runner.path('rbenv'), repo_cmd_runner.path(directory),
@@ -55,11 +55,11 @@ def _install_rbenv(repo_cmd_runner, version='default'):
5555
# Only install ruby-build if the version is specified
5656
if version != 'default':
5757
# ruby-download
58-
with tarfile_open(resource_filename('ruby-download.tar.gz')) as tf:
58+
with tarfile.open(resource_filename('ruby-download.tar.gz')) as tf:
5959
tf.extractall(repo_cmd_runner.path(directory, 'plugins'))
6060

6161
# ruby-build
62-
with tarfile_open(resource_filename('ruby-build.tar.gz')) as tf:
62+
with tarfile.open(resource_filename('ruby-build.tar.gz')) as tf:
6363
tf.extractall(repo_cmd_runner.path(directory, 'plugins'))
6464

6565
activate_path = repo_cmd_runner.path(directory, 'bin', 'activate')

pre_commit/make_archives.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from __future__ import unicode_literals
44

55
import os.path
6+
import tarfile
67

78
from pre_commit import five
89
from pre_commit.util import cmd_output
910
from pre_commit.util import cwd
1011
from pre_commit.util import rmtree
11-
from pre_commit.util import tarfile_open
1212
from pre_commit.util import tmpdir
1313

1414

@@ -53,7 +53,7 @@ def make_archive(name, repo, ref, destdir):
5353
# runtime
5454
rmtree(os.path.join(tempdir, '.git'))
5555

56-
with tarfile_open(five.n(output_path), 'w|gz') as tf:
56+
with tarfile.open(five.n(output_path), 'w|gz') as tf:
5757
tf.add(tempdir, name)
5858

5959
return output_path

pre_commit/util.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import shutil
99
import stat
1010
import subprocess
11-
import tarfile
1211
import tempfile
1312

1413
import pkg_resources
@@ -82,16 +81,6 @@ def no_git_env():
8281
)
8382

8483

85-
@contextlib.contextmanager
86-
def tarfile_open(*args, **kwargs):
87-
"""Compatibility layer because python2.6"""
88-
tf = tarfile.open(*args, **kwargs)
89-
try:
90-
yield tf
91-
finally:
92-
tf.close()
93-
94-
9584
@contextlib.contextmanager
9685
def tmpdir():
9786
"""Contextmanager to create a temporary directory. It will be cleaned up

tests/make_archives_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
from __future__ import unicode_literals
33

44
import os.path
5+
import tarfile
56

67
import mock
78
import pytest
89

910
from pre_commit import make_archives
1011
from pre_commit.util import cmd_output
1112
from pre_commit.util import cwd
12-
from pre_commit.util import tarfile_open
1313
from testing.fixtures import git_dir
1414
from testing.util import get_head_sha
1515
from testing.util import skipif_slowtests_false
@@ -41,7 +41,7 @@ def test_make_archive(tempdir_factory):
4141
extract_dir = tempdir_factory.get()
4242

4343
# Extract the tar
44-
with tarfile_open(archive_path) as tf:
44+
with tarfile.open(archive_path) as tf:
4545
tf.extractall(extract_dir)
4646

4747
# Verify the contents of the tar

0 commit comments

Comments
 (0)