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

Skip to content

Commit b9cec6a

Browse files
Issue #16314: Added support for the LZMA compression in distutils.
1 parent b8cd3e4 commit b9cec6a

10 files changed

Lines changed: 181 additions & 94 deletions

File tree

Doc/distutils/apiref.rst

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -868,23 +868,31 @@ tarballs or zipfiles.
868868

869869
Create an archive file (eg. ``zip`` or ``tar``). *base_name* is the name of
870870
the file to create, minus any format-specific extension; *format* is the
871-
archive format: one of ``zip``, ``tar``, ``ztar``, or ``gztar``. *root_dir* is
872-
a directory that will be the root directory of the archive; ie. we typically
873-
``chdir`` into *root_dir* before creating the archive. *base_dir* is the
874-
directory where we start archiving from; ie. *base_dir* will be the common
875-
prefix of all files and directories in the archive. *root_dir* and *base_dir*
876-
both default to the current directory. Returns the name of the archive file.
871+
archive format: one of ``zip``, ``tar``, ``gztar``, ``bztar``, ``xztar``, or
872+
``ztar``. *root_dir* is a directory that will be the root directory of the
873+
archive; ie. we typically ``chdir`` into *root_dir* before creating the
874+
archive. *base_dir* is the directory where we start archiving from; ie.
875+
*base_dir* will be the common prefix of all files and directories in the
876+
archive. *root_dir* and *base_dir* both default to the current directory.
877+
Returns the name of the archive file.
878+
879+
.. versionchanged: 3.5
880+
Added support for the ``xztar`` format.
877881
878882
879883
.. function:: make_tarball(base_name, base_dir[, compress='gzip', verbose=0, dry_run=0])
880884

881885
'Create an (optional compressed) archive as a tar file from all files in and
882-
under *base_dir*. *compress* must be ``'gzip'`` (the default), ``'compress'``,
883-
``'bzip2'``, or ``None``. Both :program:`tar` and the compression utility named
884-
by *compress* must be on the default program search path, so this is probably
885-
Unix-specific. The output tar file will be named :file:`base_dir.tar`,
886-
possibly plus the appropriate compression extension (:file:`.gz`, :file:`.bz2`
887-
or :file:`.Z`). Return the output filename.
886+
under *base_dir*. *compress* must be ``'gzip'`` (the default),
887+
``'bzip2'``, ``'xz'``, ``'compress'``, or ``None``. For the ``'compress'``
888+
method the compression utility named by :program:`compress` must be on the
889+
default program search path, so this is probably Unix-specific. The output
890+
tar file will be named :file:`base_dir.tar`, possibly plus the appropriate
891+
compression extension (``.gz``, ``.bz2``, ``.xz`` or ``.Z``). Return the
892+
output filename.
893+
894+
.. versionchanged: 3.5
895+
Added support for the ``xz`` compression.
888896
889897
890898
.. function:: make_zipfile(base_name, base_dir[, verbose=0, dry_run=0])

Doc/distutils/builtdist.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ The available formats for built distributions are:
7272
+-------------+------------------------------+---------+
7373
| Format | Description | Notes |
7474
+=============+==============================+=========+
75-
| ``gztar`` | gzipped tar file | (1),(3) |
75+
| ``gztar`` | gzipped tar file | \(1) |
7676
| | (:file:`.tar.gz`) | |
7777
+-------------+------------------------------+---------+
78+
| ``bztar`` | bzipped tar file | |
79+
| | (:file:`.tar.bz2`) | |
80+
+-------------+------------------------------+---------+
81+
| ``xztar`` | xzipped tar file | |
82+
| | (:file:`.tar.xz`) | |
83+
+-------------+------------------------------+---------+
7884
| ``ztar`` | compressed tar file | \(3) |
7985
| | (:file:`.tar.Z`) | |
8086
+-------------+------------------------------+---------+
81-
| ``tar`` | tar file (:file:`.tar`) | \(3) |
87+
| ``tar`` | tar file (:file:`.tar`) | |
8288
+-------------+------------------------------+---------+
8389
| ``zip`` | zip file (:file:`.zip`) | (2),(4) |
8490
+-------------+------------------------------+---------+
@@ -94,6 +100,9 @@ The available formats for built distributions are:
94100
| ``msi`` | Microsoft Installer. | |
95101
+-------------+------------------------------+---------+
96102

103+
.. versionchanged: 3.5
104+
Added support for the ``xztar`` format.
105+
97106
98107
Notes:
99108

@@ -104,8 +113,7 @@ Notes:
104113
default on Windows
105114

106115
(3)
107-
requires external utilities: :program:`tar` and possibly one of :program:`gzip`,
108-
:program:`bzip2`, or :program:`compress`
116+
requires external :program:`compress` utility.
109117

110118
(4)
111119
requires either external :program:`zip` utility or :mod:`zipfile` module (part
@@ -119,21 +127,22 @@ You don't have to use the :command:`bdist` command with the :option:`--formats`
119127
option; you can also use the command that directly implements the format you're
120128
interested in. Some of these :command:`bdist` "sub-commands" actually generate
121129
several similar formats; for instance, the :command:`bdist_dumb` command
122-
generates all the "dumb" archive formats (``tar``, ``ztar``, ``gztar``, and
123-
``zip``), and :command:`bdist_rpm` generates both binary and source RPMs. The
124-
:command:`bdist` sub-commands, and the formats generated by each, are:
125-
126-
+--------------------------+-----------------------+
127-
| Command | Formats |
128-
+==========================+=======================+
129-
| :command:`bdist_dumb` | tar, ztar, gztar, zip |
130-
+--------------------------+-----------------------+
131-
| :command:`bdist_rpm` | rpm, srpm |
132-
+--------------------------+-----------------------+
133-
| :command:`bdist_wininst` | wininst |
134-
+--------------------------+-----------------------+
135-
| :command:`bdist_msi` | msi |
136-
+--------------------------+-----------------------+
130+
generates all the "dumb" archive formats (``tar``, ``gztar``, ``bztar``,
131+
``xztar``, ``ztar``, and ``zip``), and :command:`bdist_rpm` generates both
132+
binary and source RPMs. The :command:`bdist` sub-commands, and the formats
133+
generated by each, are:
134+
135+
+--------------------------+-------------------------------------+
136+
| Command | Formats |
137+
+==========================+=====================================+
138+
| :command:`bdist_dumb` | tar, gztar, bztar, xztar, ztar, zip |
139+
+--------------------------+-------------------------------------+
140+
| :command:`bdist_rpm` | rpm, srpm |
141+
+--------------------------+-------------------------------------+
142+
| :command:`bdist_wininst` | wininst |
143+
+--------------------------+-------------------------------------+
144+
| :command:`bdist_msi` | msi |
145+
+--------------------------+-------------------------------------+
137146

138147
The following sections give details on the individual :command:`bdist_\*`
139148
commands.

Doc/distutils/sourcedist.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ to create a gzipped tarball and a zip file. The available formats are:
3232
| ``bztar`` | bzip2'ed tar file | |
3333
| | (:file:`.tar.bz2`) | |
3434
+-----------+-------------------------+---------+
35+
| ``xztar`` | xz'ed tar file | |
36+
| | (:file:`.tar.xz`) | |
37+
+-----------+-------------------------+---------+
3538
| ``ztar`` | compressed tar file | \(4) |
3639
| | (:file:`.tar.Z`) | |
3740
+-----------+-------------------------+---------+
3841
| ``tar`` | tar file (:file:`.tar`) | |
3942
+-----------+-------------------------+---------+
4043

44+
.. versionchanged: 3.5
45+
Added support for the ``xztar`` format.
46+
4147
Notes:
4248

4349
(1)
@@ -54,7 +60,7 @@ Notes:
5460
requires the :program:`compress` program. Notice that this format is now
5561
pending for deprecation and will be removed in the future versions of Python.
5662

57-
When using any ``tar`` format (``gztar``, ``bztar``, ``ztar`` or
63+
When using any ``tar`` format (``gztar``, ``bztar``, ``xztar``, ``ztar`` or
5864
``tar``), under Unix you can specify the ``owner`` and ``group`` names
5965
that will be set for each member of the archive.
6066

Doc/whatsnew/3.5.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ distutils
338338
option to enable parallel building of extension modules.
339339
(Contributed by Antoine Pitrou in :issue:`5309`.)
340340

341+
* Added support for the LZMA compression.
342+
(Contributed by Serhiy Storchaka in :issue:`16314`.)
343+
341344
doctest
342345
-------
343346

Lib/distutils/archive_util.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,28 @@ def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
5757
"""Create a (possibly compressed) tar file from all the files under
5858
'base_dir'.
5959
60-
'compress' must be "gzip" (the default), "compress", "bzip2", or None.
61-
(compress will be deprecated in Python 3.2)
60+
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
61+
None. ("compress" will be deprecated in Python 3.2)
6262
6363
'owner' and 'group' can be used to define an owner and a group for the
6464
archive that is being built. If not provided, the current owner and group
6565
will be used.
6666
6767
The output tar file will be named 'base_dir' + ".tar", possibly plus
68-
the appropriate compression extension (".gz", ".bz2" or ".Z").
68+
the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
6969
7070
Returns the output filename.
7171
"""
72-
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: '', 'compress': ''}
73-
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'compress': '.Z'}
72+
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', 'xz': 'xz', None: '',
73+
'compress': ''}
74+
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz',
75+
'compress': '.Z'}
7476

7577
# flags for compression program, each element of list will be an argument
7678
if compress is not None and compress not in compress_ext.keys():
7779
raise ValueError(
78-
"bad value for 'compress': must be None, 'gzip', 'bzip2' "
79-
"or 'compress'")
80+
"bad value for 'compress': must be None, 'gzip', 'bzip2', "
81+
"'xz' or 'compress'")
8082

8183
archive_name = base_name + '.tar'
8284
if compress != 'compress':
@@ -177,6 +179,7 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
177179
ARCHIVE_FORMATS = {
178180
'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
179181
'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
182+
'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
180183
'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
181184
'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
182185
'zip': (make_zipfile, [],"ZIP file")
@@ -197,8 +200,8 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
197200
"""Create an archive file (eg. zip or tar).
198201
199202
'base_name' is the name of the file to create, minus any format-specific
200-
extension; 'format' is the archive format: one of "zip", "tar", "ztar",
201-
or "gztar".
203+
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
204+
"bztar", "xztar", or "ztar".
202205
203206
'root_dir' is a directory that will be the root directory of the
204207
archive; ie. we typically chdir into 'root_dir' before creating the

Lib/distutils/command/bdist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ class bdist(Command):
6161
'nt': 'zip'}
6262

6363
# Establish the preferred order (for the --help-formats option).
64-
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
64+
format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar',
6565
'wininst', 'zip', 'msi']
6666

6767
# And the real information.
6868
format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
6969
'gztar': ('bdist_dumb', "gzip'ed tar file"),
7070
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
71+
'xztar': ('bdist_dumb', "xz'ed tar file"),
7172
'ztar': ('bdist_dumb', "compressed tar file"),
7273
'tar': ('bdist_dumb', "tar file"),
7374
'wininst': ('bdist_wininst',

Lib/distutils/command/bdist_dumb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class bdist_dumb(Command):
2222
"platform name to embed in generated filenames "
2323
"(default: %s)" % get_platform()),
2424
('format=', 'f',
25-
"archive format to create (tar, ztar, gztar, zip)"),
25+
"archive format to create (tar, gztar, bztar, xztar, "
26+
"ztar, zip)"),
2627
('keep-temp', 'k',
2728
"keep the pseudo-installation tree around after " +
2829
"creating the distribution archive"),

0 commit comments

Comments
 (0)