2020-05-12 12:34:30 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-07-05 22:20:07 +02:00
|
|
|
import csv
|
2017-10-06 21:51:42 +02:00
|
|
|
import distutils
|
2017-05-16 12:16:30 +02:00
|
|
|
import glob
|
2013-10-29 12:40:30 +01:00
|
|
|
import os
|
2019-12-21 17:14:50 +01:00
|
|
|
import shutil
|
2013-11-22 03:59:31 +01:00
|
|
|
|
2017-05-16 12:16:30 +02:00
|
|
|
import pytest
|
2017-06-13 14:17:00 +02:00
|
|
|
|
2020-01-02 02:29:11 +01:00
|
|
|
from tests.lib import create_basic_wheel_for_package, skip_if_python2
|
2013-05-28 23:58:08 +02:00
|
|
|
from tests.lib.path import Path
|
2020-01-25 17:49:26 +01:00
|
|
|
from tests.lib.wheel import make_wheel
|
2013-05-28 23:58:08 +02:00
|
|
|
|
|
|
|
|
2020-01-25 17:49:26 +01:00
|
|
|
# assert_installed expects a package subdirectory, so give it to them
|
|
|
|
def make_wheel_with_file(name, version, **kwargs):
|
|
|
|
extra_files = kwargs.setdefault("extra_files", {})
|
|
|
|
extra_files["{}/__init__.py".format(name)] = "# example"
|
|
|
|
return make_wheel(name=name, version=version, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def test_install_from_future_wheel_version(script, tmpdir):
|
2014-02-15 07:21:22 +01:00
|
|
|
"""
|
2020-01-25 17:51:29 +01:00
|
|
|
Test installing a wheel with a WHEEL metadata version that is:
|
|
|
|
- a major version ahead of what we expect (not ok), and
|
|
|
|
- a minor version ahead of what we expect (ok)
|
2014-02-15 07:21:22 +01:00
|
|
|
"""
|
2016-07-29 02:36:45 +02:00
|
|
|
from tests.lib import TestFailure
|
2020-01-25 17:49:26 +01:00
|
|
|
package = make_wheel_with_file(
|
|
|
|
name="futurewheel",
|
|
|
|
version="3.0",
|
|
|
|
wheel_metadata_updates={"Wheel-Version": "3.0"},
|
|
|
|
).save_to_dir(tmpdir)
|
2016-07-29 02:36:45 +02:00
|
|
|
|
2014-02-15 07:21:22 +01:00
|
|
|
result = script.pip('install', package, '--no-index', expect_error=True)
|
2014-02-15 07:47:44 +01:00
|
|
|
with pytest.raises(TestFailure):
|
|
|
|
result.assert_installed('futurewheel', without_egg_link=True,
|
|
|
|
editable=False)
|
|
|
|
|
2020-01-25 17:49:26 +01:00
|
|
|
package = make_wheel_with_file(
|
|
|
|
name="futurewheel",
|
|
|
|
version="1.9",
|
|
|
|
wheel_metadata_updates={"Wheel-Version": "1.9"},
|
|
|
|
).save_to_dir(tmpdir)
|
2015-03-16 13:34:52 +01:00
|
|
|
result = script.pip(
|
2020-01-02 23:21:22 +01:00
|
|
|
'install', package, '--no-index', expect_stderr=True
|
2015-03-16 13:34:52 +01:00
|
|
|
)
|
2014-02-15 07:47:44 +01:00
|
|
|
result.assert_installed('futurewheel', without_egg_link=True,
|
|
|
|
editable=False)
|
2014-02-15 07:21:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_install_from_broken_wheel(script, data):
|
|
|
|
"""
|
2014-02-18 05:20:12 +01:00
|
|
|
Test that installing a broken wheel fails properly
|
2014-02-15 07:21:22 +01:00
|
|
|
"""
|
2016-07-29 02:36:45 +02:00
|
|
|
from tests.lib import TestFailure
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("brokenwheel-1.0-py2.py3-none-any.whl")
|
2014-02-15 07:21:22 +01:00
|
|
|
result = script.pip('install', package, '--no-index', expect_error=True)
|
2014-02-15 07:47:44 +01:00
|
|
|
with pytest.raises(TestFailure):
|
|
|
|
result.assert_installed('futurewheel', without_egg_link=True,
|
|
|
|
editable=False)
|
2014-02-15 07:21:22 +01:00
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_basic_install_from_wheel(script, shared_data, tmpdir):
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
2013-08-31 17:17:02 +02:00
|
|
|
Test installing from a wheel (that has a script)
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "has.script-1.0-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'has.script==1.0', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2014-02-24 22:52:23 +01:00
|
|
|
dist_info_folder = script.site_packages / 'has.script-1.0.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2013-09-01 22:15:45 +02:00
|
|
|
script_file = script.bin / 'script.py'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(script_file)
|
2013-05-28 23:58:08 +02:00
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_basic_install_from_wheel_with_extras(script, shared_data, tmpdir):
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
2013-06-07 04:11:43 +02:00
|
|
|
Test installing from a wheel with extras.
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "complex_dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'complex-dist[simple]', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2014-02-24 22:52:23 +01:00
|
|
|
dist_info_folder = script.site_packages / 'complex_dist-0.1.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2014-02-24 22:52:23 +01:00
|
|
|
dist_info_folder = script.site_packages / 'simple.dist-0.1.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2013-05-28 23:58:08 +02:00
|
|
|
|
|
|
|
|
2017-12-16 19:13:46 +01:00
|
|
|
def test_basic_install_from_wheel_file(script, data):
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
|
|
|
Test installing directly from a wheel file.
|
|
|
|
"""
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("simple.dist-0.1-py2.py3-none-any.whl")
|
2020-01-02 23:21:22 +01:00
|
|
|
result = script.pip('install', package, '--no-index')
|
2014-02-24 22:52:23 +01:00
|
|
|
dist_info_folder = script.site_packages / 'simple.dist-0.1.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2015-12-04 10:19:17 +01:00
|
|
|
installer = dist_info_folder / 'INSTALLER'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(installer)
|
2015-12-04 10:19:17 +01:00
|
|
|
with open(script.base_path / installer, 'rb') as installer_file:
|
|
|
|
installer_details = installer_file.read()
|
|
|
|
assert installer_details == b'pip\n'
|
|
|
|
installer_temp = dist_info_folder / 'INSTALLER.pip'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_not_create(installer_temp)
|
2013-12-08 23:05:08 +01:00
|
|
|
|
|
|
|
|
2020-05-13 00:56:20 +02:00
|
|
|
# Installation seems to work, but scripttest fails to check.
|
2020-05-12 15:33:05 +02:00
|
|
|
# I really don't care now since we're desupporting it soon anyway.
|
|
|
|
@skip_if_python2
|
2020-05-12 12:34:30 +02:00
|
|
|
def test_basic_install_from_unicode_wheel(script, data):
|
|
|
|
"""
|
|
|
|
Test installing from a wheel (that has a script)
|
|
|
|
"""
|
|
|
|
make_wheel(
|
|
|
|
'unicode_package',
|
|
|
|
'1.0',
|
|
|
|
extra_files={
|
2020-05-12 15:33:05 +02:00
|
|
|
'வணக்கம்/__init__.py': b'',
|
|
|
|
'வணக்கம்/નમસ્તે.py': b'',
|
2020-05-12 12:34:30 +02:00
|
|
|
},
|
|
|
|
).save_to_dir(script.scratch_path)
|
|
|
|
|
|
|
|
result = script.pip(
|
|
|
|
'install', 'unicode_package==1.0', '--no-index',
|
|
|
|
'--find-links', script.scratch_path,
|
|
|
|
)
|
|
|
|
dist_info_folder = script.site_packages / 'unicode_package-1.0.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2020-05-12 12:34:30 +02:00
|
|
|
|
2020-05-12 15:33:05 +02:00
|
|
|
file1 = script.site_packages.joinpath('வணக்கம்', '__init__.py')
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(file1)
|
2020-05-12 12:34:30 +02:00
|
|
|
|
2020-05-12 15:33:05 +02:00
|
|
|
file2 = script.site_packages.joinpath('வணக்கம்', 'નમસ્તે.py')
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(file2)
|
2020-05-12 12:34:30 +02:00
|
|
|
|
|
|
|
|
2020-07-03 19:42:15 +02:00
|
|
|
def get_header_scheme_path_for_script(script, dist_name):
|
|
|
|
command = (
|
|
|
|
"from pip._internal.locations import get_scheme;"
|
|
|
|
"scheme = get_scheme({!r});"
|
|
|
|
"print(scheme.headers);"
|
|
|
|
).format(dist_name)
|
|
|
|
result = script.run('python', '-c', command).stdout
|
|
|
|
return Path(result.strip())
|
|
|
|
|
|
|
|
|
2020-07-03 19:47:05 +02:00
|
|
|
def test_install_from_wheel_with_headers(script):
|
2013-12-08 23:05:08 +01:00
|
|
|
"""
|
|
|
|
Test installing from a wheel file with headers
|
|
|
|
"""
|
2020-07-04 20:23:10 +02:00
|
|
|
header_text = '/* hello world */\n'
|
2020-07-03 19:47:05 +02:00
|
|
|
package = make_wheel(
|
|
|
|
'headers.dist',
|
|
|
|
'0.1',
|
|
|
|
extra_data_files={
|
2020-07-04 20:23:10 +02:00
|
|
|
'headers/header.h': header_text
|
2020-07-03 19:47:05 +02:00
|
|
|
},
|
|
|
|
).save_to_dir(script.scratch_path)
|
2020-01-02 23:21:22 +01:00
|
|
|
result = script.pip('install', package, '--no-index')
|
2014-02-24 22:52:23 +01:00
|
|
|
dist_info_folder = script.site_packages / 'headers.dist-0.1.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2013-05-28 23:58:08 +02:00
|
|
|
|
2020-07-03 19:42:15 +02:00
|
|
|
header_scheme_path = get_header_scheme_path_for_script(
|
|
|
|
script, 'headers.dist'
|
|
|
|
)
|
|
|
|
header_path = header_scheme_path / 'header.h'
|
2020-07-04 20:23:10 +02:00
|
|
|
assert header_path.read_text() == header_text
|
2020-07-03 19:42:15 +02:00
|
|
|
|
2013-05-28 23:58:08 +02:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_wheel_with_target(script, shared_data, with_wheel, tmpdir):
|
2013-05-28 23:58:08 +02:00
|
|
|
"""
|
|
|
|
Test installing a wheel using pip install --target
|
|
|
|
"""
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2014-02-24 22:52:23 +01:00
|
|
|
target_dir = script.scratch_path / 'target'
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'simple.dist==0.1', '-t', target_dir,
|
2020-01-04 00:05:47 +01:00
|
|
|
'--no-index', '--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(Path('scratch') / 'target' / 'simpledist')
|
2013-06-07 04:11:43 +02:00
|
|
|
|
|
|
|
|
2018-10-08 18:09:53 +02:00
|
|
|
def test_install_wheel_with_target_and_data_files(script, data, with_wheel):
|
2017-03-26 23:55:50 +02:00
|
|
|
"""
|
|
|
|
Test for issue #4092. It will be checked that a data_files specification in
|
|
|
|
setup.py is handled correctly when a wheel is installed with the --target
|
|
|
|
option.
|
|
|
|
|
|
|
|
The setup() for the wheel 'prjwithdatafile-1.0-py2.py3-none-any.whl' is as
|
|
|
|
follows ::
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name='prjwithdatafile',
|
|
|
|
version='1.0',
|
|
|
|
packages=['prjwithdatafile'],
|
|
|
|
data_files=[
|
|
|
|
(r'packages1', ['prjwithdatafile/README.txt']),
|
|
|
|
(r'packages2', ['prjwithdatafile/README.txt'])
|
|
|
|
]
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
target_dir = script.scratch_path / 'prjwithdatafile'
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath(
|
|
|
|
"prjwithdatafile-1.0-py2.py3-none-any.whl"
|
|
|
|
)
|
2017-03-26 23:55:50 +02:00
|
|
|
result = script.pip('install', package,
|
|
|
|
'-t', target_dir,
|
2020-01-02 23:21:22 +01:00
|
|
|
'--no-index')
|
2020-05-28 13:02:07 +02:00
|
|
|
project_path = Path('scratch') / 'prjwithdatafile'
|
|
|
|
result.did_create(project_path / 'packages1' / 'README.txt')
|
|
|
|
result.did_create(project_path / 'packages2' / 'README.txt')
|
|
|
|
result.did_not_create(project_path / 'lib' / 'python')
|
2017-03-26 23:55:50 +02:00
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_wheel_with_root(script, shared_data, tmpdir):
|
2013-10-31 13:49:23 +01:00
|
|
|
"""
|
|
|
|
Test installing a wheel using pip install --root
|
|
|
|
"""
|
2014-02-24 22:52:23 +01:00
|
|
|
root_dir = script.scratch_path / 'root'
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'simple.dist==0.1', '--root', root_dir,
|
2020-01-04 00:05:47 +01:00
|
|
|
'--no-index', '--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(Path('scratch') / 'root')
|
2013-10-31 13:49:23 +01:00
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_wheel_with_prefix(script, shared_data, tmpdir):
|
2015-11-16 17:39:44 +01:00
|
|
|
"""
|
|
|
|
Test installing a wheel using pip install --prefix
|
|
|
|
"""
|
|
|
|
prefix_dir = script.scratch_path / 'prefix'
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2015-11-16 17:39:44 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', 'simple.dist==0.1', '--prefix', prefix_dir,
|
2020-01-04 00:05:47 +01:00
|
|
|
'--no-index', '--find-links', tmpdir,
|
2015-11-16 17:39:44 +01:00
|
|
|
)
|
2017-10-06 21:51:42 +02:00
|
|
|
lib = distutils.sysconfig.get_python_lib(prefix=Path('scratch') / 'prefix')
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(lib)
|
2015-11-16 17:39:44 +01:00
|
|
|
|
|
|
|
|
2020-01-04 00:05:47 +01:00
|
|
|
def test_install_from_wheel_installs_deps(script, data, tmpdir):
|
2013-06-07 04:11:43 +02:00
|
|
|
"""
|
|
|
|
Test can install dependencies of wheels
|
|
|
|
"""
|
|
|
|
# 'requires_source' depends on the 'source' project
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath(
|
|
|
|
"requires_source-1.0-py2.py3-none-any.whl"
|
|
|
|
)
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(data.packages / "source-1.0.tar.gz", tmpdir)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2020-01-04 00:05:47 +01:00
|
|
|
'install', '--no-index', '--find-links', tmpdir, package,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-06-07 04:11:43 +02:00
|
|
|
result.assert_installed('source', editable=False)
|
|
|
|
|
|
|
|
|
2020-01-04 00:05:47 +01:00
|
|
|
def test_install_from_wheel_no_deps(script, data, tmpdir):
|
2013-06-07 04:11:43 +02:00
|
|
|
"""
|
|
|
|
Test --no-deps works with wheel installs
|
|
|
|
"""
|
|
|
|
# 'requires_source' depends on the 'source' project
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath(
|
|
|
|
"requires_source-1.0-py2.py3-none-any.whl"
|
|
|
|
)
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(data.packages / "source-1.0.tar.gz", tmpdir)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2020-01-04 00:05:47 +01:00
|
|
|
'install', '--no-index', '--find-links', tmpdir, '--no-deps',
|
2014-01-28 15:17:51 +01:00
|
|
|
package,
|
|
|
|
)
|
2014-02-24 22:52:23 +01:00
|
|
|
pkg_folder = script.site_packages / 'source'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_not_create(pkg_folder)
|
2013-06-07 04:11:43 +02:00
|
|
|
|
2013-09-01 22:15:45 +02:00
|
|
|
|
2018-06-21 22:05:37 +02:00
|
|
|
def test_wheel_record_lines_in_deterministic_order(script, data):
|
2019-07-02 07:00:32 +02:00
|
|
|
to_install = data.packages.joinpath("simplewheel-1.0-py2.py3-none-any.whl")
|
2018-06-21 22:05:37 +02:00
|
|
|
result = script.pip('install', to_install)
|
|
|
|
|
|
|
|
dist_info_folder = script.site_packages / 'simplewheel-1.0.dist-info'
|
|
|
|
record_path = dist_info_folder / 'RECORD'
|
|
|
|
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
|
|
|
result.did_create(record_path)
|
2018-06-21 22:05:37 +02:00
|
|
|
|
|
|
|
record_path = result.files_created[record_path].full
|
|
|
|
record_lines = [
|
|
|
|
p for p in Path(record_path).read_text().split('\n') if p
|
|
|
|
]
|
|
|
|
assert record_lines == sorted(record_lines)
|
|
|
|
|
|
|
|
|
2020-07-05 22:20:07 +02:00
|
|
|
def test_wheel_record_lines_have_hash_for_data_files(script):
|
|
|
|
package = make_wheel(
|
|
|
|
"simple",
|
|
|
|
"0.1.0",
|
|
|
|
extra_data_files={
|
|
|
|
"purelib/info.txt": "c",
|
|
|
|
},
|
|
|
|
).save_to_dir(script.scratch_path)
|
|
|
|
script.pip("install", package)
|
|
|
|
record_file = (
|
|
|
|
script.site_packages_path / "simple-0.1.0.dist-info" / "RECORD"
|
|
|
|
)
|
|
|
|
record_text = record_file.read_text()
|
|
|
|
record_rows = list(csv.reader(record_text.splitlines()))
|
|
|
|
records = {
|
|
|
|
r[0]: r[1:] for r in record_rows
|
|
|
|
}
|
|
|
|
assert records["info.txt"] == [
|
|
|
|
"sha256=Ln0sA6lQeuJl7PW1NWiFpTOTogKdJBOUmXJloaJa78Y", "1"
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-11-05 16:35:08 +01:00
|
|
|
@pytest.mark.incompatible_with_test_venv
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_user_wheel(script, shared_data, with_wheel, tmpdir):
|
2013-09-01 22:15:45 +02:00
|
|
|
"""
|
|
|
|
Test user install from wheel (that has a script)
|
|
|
|
"""
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "has.script-1.0-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'has.script==1.0', '--user', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-09-01 22:15:45 +02:00
|
|
|
egg_info_folder = script.user_site / 'has.script-1.0.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(egg_info_folder)
|
2013-09-01 22:15:45 +02:00
|
|
|
script_file = script.user_bin / 'script.py'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(script_file)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_from_wheel_gen_entrypoint(script, shared_data, tmpdir):
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
|
|
|
Test installing scripts (entry points are generated)
|
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "script.wheel1a-0.1-py2.py3-none-any.whl",
|
|
|
|
tmpdir,
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'script.wheel1a==0.1', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-10-29 12:40:30 +01:00
|
|
|
if os.name == 'nt':
|
|
|
|
wrapper_file = script.bin / 't1.exe'
|
|
|
|
else:
|
|
|
|
wrapper_file = script.bin / 't1'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(wrapper_file)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
2013-11-02 17:03:29 +01:00
|
|
|
if os.name != "nt":
|
|
|
|
assert bool(os.access(script.base_path / wrapper_file, os.X_OK))
|
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_from_wheel_gen_uppercase_entrypoint(
|
|
|
|
script, shared_data, tmpdir
|
|
|
|
):
|
2016-01-03 23:31:21 +01:00
|
|
|
"""
|
|
|
|
Test installing scripts with uppercase letters in entry point names
|
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages /
|
|
|
|
"console_scripts_uppercase-1.0-py2.py3-none-any.whl",
|
2020-01-04 00:05:47 +01:00
|
|
|
tmpdir,
|
|
|
|
)
|
2016-01-03 23:31:21 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', 'console-scripts-uppercase==1.0', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2016-01-03 23:31:21 +01:00
|
|
|
)
|
|
|
|
if os.name == 'nt':
|
|
|
|
# Case probably doesn't make any difference on NT
|
|
|
|
wrapper_file = script.bin / 'cmdName.exe'
|
|
|
|
else:
|
|
|
|
wrapper_file = script.bin / 'cmdName'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(wrapper_file)
|
2016-01-03 23:31:21 +01:00
|
|
|
|
|
|
|
if os.name != "nt":
|
|
|
|
assert bool(os.access(script.base_path / wrapper_file, os.X_OK))
|
|
|
|
|
|
|
|
|
2020-05-28 10:08:17 +02:00
|
|
|
# pkg_resources.EntryPoint() does not parse unicode correctly on Python 2.
|
|
|
|
@skip_if_python2
|
|
|
|
def test_install_from_wheel_gen_unicode_entrypoint(script):
|
|
|
|
make_wheel(
|
|
|
|
"script_wheel_unicode",
|
|
|
|
"1.0",
|
|
|
|
console_scripts=["進入點 = 模組:函式"],
|
|
|
|
).save_to_dir(script.scratch_path)
|
|
|
|
|
|
|
|
result = script.pip(
|
|
|
|
"install",
|
|
|
|
"--no-index",
|
|
|
|
"--find-links",
|
|
|
|
script.scratch_path,
|
|
|
|
"script_wheel_unicode",
|
|
|
|
)
|
|
|
|
if os.name == "nt":
|
|
|
|
result.did_create(script.bin.joinpath("進入點.exe"))
|
|
|
|
else:
|
|
|
|
result.did_create(script.bin.joinpath("進入點"))
|
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_from_wheel_with_legacy(script, shared_data, tmpdir):
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
|
|
|
Test installing scripts (legacy scripts are preserved)
|
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "script.wheel2a-0.1-py2.py3-none-any.whl",
|
|
|
|
tmpdir,
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'script.wheel2a==0.1', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
|
|
|
legacy_file1 = script.bin / 'testscript1.bat'
|
|
|
|
legacy_file2 = script.bin / 'testscript2'
|
|
|
|
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(legacy_file1)
|
|
|
|
result.did_create(legacy_file2)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_from_wheel_no_setuptools_entrypoint(
|
|
|
|
script, shared_data, tmpdir
|
|
|
|
):
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
2013-11-01 18:28:35 +01:00
|
|
|
Test that when we generate scripts, any existing setuptools wrappers in
|
|
|
|
the wheel are skipped.
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "script.wheel1-0.1-py2.py3-none-any.whl", tmpdir
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'script.wheel1==0.1', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-10-29 12:40:30 +01:00
|
|
|
if os.name == 'nt':
|
|
|
|
wrapper_file = script.bin / 't1.exe'
|
|
|
|
else:
|
|
|
|
wrapper_file = script.bin / 't1'
|
|
|
|
wrapper_helper = script.bin / 't1-script.py'
|
|
|
|
|
2013-11-01 18:28:35 +01:00
|
|
|
# The wheel has t1.exe and t1-script.py. We will be generating t1 or
|
|
|
|
# t1.exe depending on the platform. So we check that the correct wrapper
|
|
|
|
# is present and that the -script.py helper has been skipped. We can't
|
|
|
|
# easily test that the wrapper from the wheel has been skipped /
|
|
|
|
# overwritten without getting very platform-dependent, so omit that.
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(wrapper_file)
|
|
|
|
result.did_not_create(wrapper_helper)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_skipping_setuptools_doesnt_skip_legacy(script, shared_data, tmpdir):
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
Test installing scripts (legacy scripts are preserved even when we skip
|
|
|
|
setuptools wrappers)
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "script.wheel2-0.1-py2.py3-none-any.whl", tmpdir
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'script.wheel2==0.1', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
|
|
|
legacy_file1 = script.bin / 'testscript1.bat'
|
|
|
|
legacy_file2 = script.bin / 'testscript2'
|
|
|
|
wrapper_helper = script.bin / 't1-script.py'
|
|
|
|
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(legacy_file1)
|
|
|
|
result.did_create(legacy_file2)
|
|
|
|
result.did_not_create(wrapper_helper)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_install_from_wheel_gui_entrypoint(script, shared_data, tmpdir):
|
2013-10-29 12:40:30 +01:00
|
|
|
"""
|
|
|
|
Test installing scripts (gui entry points are generated)
|
|
|
|
"""
|
2020-01-04 00:05:47 +01:00
|
|
|
shutil.copy(
|
2020-01-04 00:20:01 +01:00
|
|
|
shared_data.packages / "script.wheel3-0.1-py2.py3-none-any.whl", tmpdir
|
2020-01-04 00:05:47 +01:00
|
|
|
)
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2015-04-20 03:27:27 +02:00
|
|
|
'install', 'script.wheel3==0.1', '--no-index',
|
2020-01-04 00:05:47 +01:00
|
|
|
'--find-links', tmpdir,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2013-10-29 12:40:30 +01:00
|
|
|
if os.name == 'nt':
|
|
|
|
wrapper_file = script.bin / 't1.exe'
|
|
|
|
else:
|
|
|
|
wrapper_file = script.bin / 't1'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(wrapper_file)
|
2013-10-29 12:40:30 +01:00
|
|
|
|
2013-11-22 03:59:31 +01:00
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_wheel_compiles_pyc(script, shared_data, tmpdir):
|
2013-11-22 03:59:31 +01:00
|
|
|
"""
|
|
|
|
Test installing from wheel with --compile on
|
|
|
|
"""
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2013-11-22 03:59:31 +01:00
|
|
|
script.pip(
|
|
|
|
"install", "--compile", "simple.dist==0.1", "--no-index",
|
2020-01-04 00:05:47 +01:00
|
|
|
"--find-links", tmpdir,
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
# There are many locations for the __init__.pyc file so attempt to find
|
|
|
|
# any of them
|
|
|
|
exists = [
|
2014-02-24 22:52:23 +01:00
|
|
|
os.path.exists(script.site_packages_path / "simpledist/__init__.pyc"),
|
2013-11-22 03:59:31 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
exists += glob.glob(
|
2014-02-24 22:52:23 +01:00
|
|
|
script.site_packages_path / "simpledist/__pycache__/__init__*.pyc"
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert any(exists)
|
|
|
|
|
|
|
|
|
2020-01-04 00:20:01 +01:00
|
|
|
def test_wheel_no_compiles_pyc(script, shared_data, tmpdir):
|
2013-11-22 03:59:31 +01:00
|
|
|
"""
|
|
|
|
Test installing from wheel with --compile on
|
|
|
|
"""
|
2020-01-04 00:20:01 +01:00
|
|
|
shutil.copy(
|
|
|
|
shared_data.packages / "simple.dist-0.1-py2.py3-none-any.whl", tmpdir
|
|
|
|
)
|
2013-11-22 03:59:31 +01:00
|
|
|
script.pip(
|
|
|
|
"install", "--no-compile", "simple.dist==0.1", "--no-index",
|
2020-01-04 00:05:47 +01:00
|
|
|
"--find-links", tmpdir,
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
# There are many locations for the __init__.pyc file so attempt to find
|
|
|
|
# any of them
|
|
|
|
exists = [
|
2014-02-24 22:52:23 +01:00
|
|
|
os.path.exists(script.site_packages_path / "simpledist/__init__.pyc"),
|
2013-11-22 03:59:31 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
exists += glob.glob(
|
2014-02-24 22:52:23 +01:00
|
|
|
script.site_packages_path / "simpledist/__pycache__/__init__*.pyc"
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert not any(exists)
|
2014-05-26 06:00:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_install_from_wheel_uninstalls_old_version(script, data):
|
|
|
|
# regression test for https://github.com/pypa/pip/issues/1825
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("simplewheel-1.0-py2.py3-none-any.whl")
|
2019-08-11 04:04:44 +02:00
|
|
|
result = script.pip('install', package, '--no-index')
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("simplewheel-2.0-py2.py3-none-any.whl")
|
2020-01-02 23:21:22 +01:00
|
|
|
result = script.pip('install', package, '--no-index')
|
2014-05-26 06:00:39 +02:00
|
|
|
dist_info_folder = script.site_packages / 'simplewheel-2.0.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2014-05-26 06:00:39 +02:00
|
|
|
dist_info_folder = script.site_packages / 'simplewheel-1.0.dist-info'
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_not_create(dist_info_folder)
|
2014-08-21 15:40:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_compile_syntax_error(script, data):
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("compilewheel-1.0-py2.py3-none-any.whl")
|
2014-08-21 15:40:02 +02:00
|
|
|
result = script.pip('install', '--compile', package, '--no-index')
|
2014-09-29 10:51:04 +02:00
|
|
|
assert 'yield from' not in result.stdout
|
2014-08-21 15:40:02 +02:00
|
|
|
assert 'SyntaxError: ' not in result.stdout
|
2019-01-23 03:31:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_install_with_no_cache_dir(script, tmpdir, data):
|
|
|
|
"""Check wheel installations work, even with no cache.
|
|
|
|
"""
|
2019-07-02 07:00:32 +02:00
|
|
|
package = data.packages.joinpath("simple.dist-0.1-py2.py3-none-any.whl")
|
2019-01-23 03:31:29 +01:00
|
|
|
result = script.pip('install', '--no-cache-dir', '--no-index', package)
|
|
|
|
result.assert_installed('simpledist', editable=False)
|
2019-12-21 04:38:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_install_fails_with_extra_dist_info(script):
|
|
|
|
package = create_basic_wheel_for_package(
|
|
|
|
script,
|
|
|
|
"simple",
|
|
|
|
"0.1.0",
|
|
|
|
extra_files={
|
|
|
|
"unrelated-2.0.0.dist-info/WHEEL": "Wheel-Version: 1.0",
|
|
|
|
"unrelated-2.0.0.dist-info/METADATA": (
|
|
|
|
"Name: unrelated\nVersion: 2.0.0\n"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
result = script.pip(
|
|
|
|
"install", "--no-cache-dir", "--no-index", package, expect_error=True
|
|
|
|
)
|
2019-12-30 16:59:23 +01:00
|
|
|
assert "multiple .dist-info directories" in result.stderr
|
2019-12-21 17:14:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_install_fails_with_unrelated_dist_info(script):
|
|
|
|
package = create_basic_wheel_for_package(script, "simple", "0.1.0")
|
|
|
|
new_name = "unrelated-2.0.0-py2.py3-none-any.whl"
|
|
|
|
new_package = os.path.join(os.path.dirname(package), new_name)
|
|
|
|
shutil.move(package, new_package)
|
|
|
|
|
|
|
|
result = script.pip(
|
|
|
|
"install",
|
|
|
|
"--no-cache-dir",
|
|
|
|
"--no-index",
|
|
|
|
new_package,
|
|
|
|
expect_error=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
"'simple-0.1.0.dist-info' does not start with 'unrelated'"
|
|
|
|
in result.stderr
|
|
|
|
)
|
2019-12-28 21:04:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_installs_ok_with_nested_dist_info(script):
|
|
|
|
package = create_basic_wheel_for_package(
|
|
|
|
script,
|
|
|
|
"simple",
|
|
|
|
"0.1.0",
|
|
|
|
extra_files={
|
|
|
|
"subdir/unrelated-2.0.0.dist-info/WHEEL": "Wheel-Version: 1.0",
|
|
|
|
"subdir/unrelated-2.0.0.dist-info/METADATA": (
|
|
|
|
"Name: unrelated\nVersion: 2.0.0\n"
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
script.pip(
|
|
|
|
"install", "--no-cache-dir", "--no-index", package
|
|
|
|
)
|
2020-01-02 02:29:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wheel_installs_ok_with_badly_encoded_irrelevant_dist_info_file(
|
|
|
|
script
|
|
|
|
):
|
|
|
|
package = create_basic_wheel_for_package(
|
|
|
|
script,
|
|
|
|
"simple",
|
|
|
|
"0.1.0",
|
|
|
|
extra_files={
|
|
|
|
"simple-0.1.0.dist-info/AUTHORS.txt": b"\xff"
|
|
|
|
},
|
|
|
|
)
|
|
|
|
script.pip(
|
|
|
|
"install", "--no-cache-dir", "--no-index", package
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Metadata is not decoded on Python 2.
|
|
|
|
@skip_if_python2
|
|
|
|
def test_wheel_install_fails_with_badly_encoded_metadata(script):
|
|
|
|
package = create_basic_wheel_for_package(
|
|
|
|
script,
|
|
|
|
"simple",
|
|
|
|
"0.1.0",
|
|
|
|
extra_files={
|
|
|
|
"simple-0.1.0.dist-info/METADATA": b"\xff"
|
|
|
|
},
|
|
|
|
)
|
|
|
|
result = script.pip(
|
|
|
|
"install", "--no-cache-dir", "--no-index", package, expect_error=True
|
|
|
|
)
|
|
|
|
assert "Error decoding metadata for" in result.stderr
|
|
|
|
assert "simple-0.1.0-py2.py3-none-any.whl" in result.stderr
|
|
|
|
assert "METADATA" in result.stderr
|
2020-04-17 16:19:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'package_name',
|
|
|
|
['simple-package', 'simple_package'],
|
|
|
|
)
|
|
|
|
def test_correct_package_name_while_creating_wheel_bug(script, package_name):
|
|
|
|
"""Check that the package name is correctly named while creating
|
|
|
|
a .whl file with a given format
|
|
|
|
"""
|
|
|
|
package = create_basic_wheel_for_package(script, package_name, '1.0')
|
|
|
|
wheel_name = os.path.basename(package)
|
|
|
|
assert wheel_name == 'simple_package-1.0-py2.py3-none-any.whl'
|