Merge pull request #3204 from xavfernandez/accept_xz_format

Add support for .xz files (with python >=3.3)
This commit is contained in:
Xavier Fernandez 2016-01-14 23:38:39 +01:00
commit c0a79f97df
5 changed files with 37 additions and 4 deletions

View File

@ -113,6 +113,9 @@
* Warn on installation of editable if the provided #egg=name part does not
match the metadata produced by `setup.py egg_info`. :issue:`3143`.
* Add support for .xz files for python versions supporting them (>= 3.3).
:issue:`722`.
**7.1.2 (2015-08-22)**

View File

@ -49,15 +49,24 @@ __all__ = ['rmtree', 'display_path', 'backup_dir',
logger = std_logging.getLogger(__name__)
BZ2_EXTENSIONS = ('.tar.bz2', '.tbz')
XZ_EXTENSIONS = ('.tar.xz', '.txz', '.tlz', '.tar.lz', '.tar.lzma')
ZIP_EXTENSIONS = ('.zip', '.whl')
TAR_EXTENSIONS = ('.tar.gz', '.tgz', '.tar')
ARCHIVE_EXTENSIONS = ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS
ARCHIVE_EXTENSIONS = (
ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS + XZ_EXTENSIONS)
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS
try:
import bz2 # noqa
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS
SUPPORTED_EXTENSIONS += BZ2_EXTENSIONS
except ImportError:
logger.debug('bz2 module is not available')
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS
try:
# Only for Python 3.3+
import lzma # noqa
SUPPORTED_EXTENSIONS += XZ_EXTENSIONS
except ImportError:
logger.debug('lzma module is not available')
def import_or_raise(pkg_or_module_string, ExceptionType, *args, **kwargs):
@ -516,6 +525,8 @@ def untar_file(filename, location):
mode = 'r:gz'
elif filename.lower().endswith(BZ2_EXTENSIONS):
mode = 'r:bz2'
elif filename.lower().endswith(XZ_EXTENSIONS):
mode = 'r:xz'
elif filename.lower().endswith('.tar'):
mode = 'r'
else:
@ -589,7 +600,8 @@ def unpack_file(filename, location, content_type, link):
)
elif (content_type == 'application/x-gzip' or
tarfile.is_tarfile(filename) or
filename.lower().endswith(TAR_EXTENSIONS + BZ2_EXTENSIONS)):
filename.lower().endswith(
TAR_EXTENSIONS + BZ2_EXTENSIONS + XZ_EXTENSIONS)):
untar_file(filename, location)
elif (content_type and content_type.startswith('text/html') and
is_svn_page(file_contents(filename))):

Binary file not shown.

Binary file not shown.

View File

@ -914,3 +914,21 @@ def test_install_editable_with_wrong_egg_name(script):
"for project name pkga. Fix your #egg=pkgb "
"fragments.") in result.stderr
assert "Successfully installed pkga" in str(result), str(result)
def test_install_tar_xz(script, data):
try:
import lzma # noqa
except ImportError:
pytest.skip("No lzma support")
res = script.pip('install', data.packages / 'singlemodule-0.0.1.tar.xz')
assert "Successfully installed singlemodule-0.0.1" in res.stdout, res
def test_install_tar_lzma(script, data):
try:
import lzma # noqa
except ImportError:
pytest.skip("No lzma support")
res = script.pip('install', data.packages / 'singlemodule-0.0.1.tar.lzma')
assert "Successfully installed singlemodule-0.0.1" in res.stdout, res