Skip to content

Commit

Permalink
"Removed support for 'compress="compress"' to archive_util.make_tarba…
Browse files Browse the repository at this point in the history
…ll."
  • Loading branch information
jaraco committed Sep 5, 2024
1 parent e2ab601 commit bcba955
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 55 deletions.
26 changes: 4 additions & 22 deletions distutils/archive_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
that sort of thing)."""

import os
import sys
from warnings import warn

try:
import zipfile
Expand Down Expand Up @@ -67,8 +65,7 @@ def make_tarball(
"""Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
None. ("compress" will be deprecated in Python 3.2)
'compress' must be "gzip" (the default), "bzip2", "xz", or None.
'owner' and 'group' can be used to define an owner and a group for the
archive that is being built. If not provided, the current owner and group
Expand All @@ -84,20 +81,17 @@ def make_tarball(
'bzip2': 'bz2',
'xz': 'xz',
None: '',
'compress': '',
}
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz', 'compress': '.Z'}
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz'}

# flags for compression program, each element of list will be an argument
if compress is not None and compress not in compress_ext.keys():
raise ValueError(
"bad value for 'compress': must be None, 'gzip', 'bzip2', "
"'xz' or 'compress'"
"bad value for 'compress': must be None, 'gzip', 'bzip2', 'xz'"
)

archive_name = base_name + '.tar'
if compress != 'compress':
archive_name += compress_ext.get(compress, '')
archive_name += compress_ext.get(compress, '')

mkpath(os.path.dirname(archive_name), dry_run=dry_run)

Expand Down Expand Up @@ -125,18 +119,6 @@ def _set_uid_gid(tarinfo):
finally:
tar.close()

# compression using `compress`
if compress == 'compress':
warn("'compress' is deprecated.", DeprecationWarning)
# the option varies depending on the platform
compressed_name = archive_name + compress_ext[compress]
if sys.platform == 'win32':
cmd = [compress, archive_name, compressed_name]
else:
cmd = [compress, '-f', archive_name]
spawn(cmd, dry_run=dry_run)
return compressed_name

return archive_name


Expand Down
33 changes: 0 additions & 33 deletions distutils/tests/test_archive_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pathlib
import sys
import tarfile
import warnings
from distutils import archive_util
from distutils.archive_util import (
ARCHIVE_FORMATS,
Expand All @@ -23,7 +22,6 @@
import pytest
from test.support import patch

from .compat.py38 import check_warnings
from .unix_compat import UID_0_SUPPORT, grp, pwd, require_uid_0, require_unix_id


Expand Down Expand Up @@ -190,37 +188,6 @@ def test_tarfile_vs_tar(self):
tarball = base_name + '.tar'
assert os.path.exists(tarball)

@pytest.mark.skipif("not shutil.which('compress')")
def test_compress_deprecated(self):
tmpdir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive')

# using compress and testing the DeprecationWarning
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
with check_warnings() as w:
warnings.simplefilter("always")
make_tarball(base_name, 'dist', compress='compress')
finally:
os.chdir(old_dir)
tarball = base_name + '.tar.Z'
assert os.path.exists(tarball)
assert len(w.warnings) == 1

# same test with dry_run
os.remove(tarball)
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
with check_warnings() as w:
warnings.simplefilter("always")
make_tarball(base_name, 'dist', compress='compress', dry_run=True)
finally:
os.chdir(old_dir)
assert not os.path.exists(tarball)
assert len(w.warnings) == 1

@pytest.mark.usefixtures('needs_zlib')
def test_make_zipfile(self):
zipfile = pytest.importorskip('zipfile')
Expand Down

0 comments on commit bcba955

Please sign in to comment.