|
| 1 | +import json |
1 | 2 | import os
|
2 | 3 | import textwrap
|
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 |
|
6 | 7 | from tests.lib import (
|
7 | 8 | _create_test_package_with_subdirectory,
|
| 9 | + create_basic_sdist_for_package, |
8 | 10 | create_basic_wheel_for_package,
|
9 | 11 | need_svn,
|
10 | 12 | path_to_url,
|
|
15 | 17 | from tests.lib.path import Path
|
16 | 18 |
|
17 | 19 |
|
| 20 | +class ArgRecordingSdist(object): |
| 21 | + def __init__(self, sdist_path, args_path): |
| 22 | + self.sdist_path = sdist_path |
| 23 | + self._args_path = args_path |
| 24 | + |
| 25 | + def args(self): |
| 26 | + return json.loads(self._args_path.read_text()) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture() |
| 30 | +def arg_recording_sdist_maker(script): |
| 31 | + arg_writing_setup_py = textwrap.dedent( |
| 32 | + """ |
| 33 | + import io |
| 34 | + import json |
| 35 | + import os |
| 36 | + import sys |
| 37 | +
|
| 38 | + from setuptools import setup |
| 39 | +
|
| 40 | + args_path = os.path.join(os.environ["OUTPUT_DIR"], "{name}.json") |
| 41 | + with open(args_path, 'w') as f: |
| 42 | + json.dump(sys.argv, f) |
| 43 | +
|
| 44 | + setup(name={name!r}, version="0.1.0") |
| 45 | + """ |
| 46 | + ) |
| 47 | + output_dir = script.scratch_path.joinpath( |
| 48 | + "args_recording_sdist_maker_output" |
| 49 | + ) |
| 50 | + output_dir.mkdir(parents=True) |
| 51 | + script.environ["OUTPUT_DIR"] = str(output_dir) |
| 52 | + |
| 53 | + def _arg_recording_sdist_maker(name): |
| 54 | + # type: (str) -> ArgRecordingSdist |
| 55 | + extra_files = {"setup.py": arg_writing_setup_py.format(name=name)} |
| 56 | + sdist_path = create_basic_sdist_for_package( |
| 57 | + script, name, "0.1.0", extra_files |
| 58 | + ) |
| 59 | + args_path = output_dir / "{}.json".format(name) |
| 60 | + return ArgRecordingSdist(sdist_path, args_path) |
| 61 | + |
| 62 | + return _arg_recording_sdist_maker |
| 63 | + |
| 64 | + |
18 | 65 | @pytest.mark.network
|
19 | 66 | def test_requirements_file(script):
|
20 | 67 | """
|
@@ -259,28 +306,21 @@ def test_wheel_user_with_prefix_in_pydistutils_cfg(
|
259 | 306 | assert 'installed requiresupper' in result.stdout
|
260 | 307 |
|
261 | 308 |
|
262 |
| -def test_install_option_in_requirements_file(script, data, virtualenv): |
263 |
| - """ |
264 |
| - Test --install-option in requirements file overrides same option in cli |
265 |
| - """ |
266 |
| - |
267 |
| - script.scratch_path.joinpath("home1").mkdir() |
268 |
| - script.scratch_path.joinpath("home2").mkdir() |
269 |
| - |
270 |
| - script.scratch_path.joinpath("reqs.txt").write_text( |
271 |
| - textwrap.dedent( |
272 |
| - """simple --install-option='--home={home}'""".format( |
273 |
| - home=script.scratch_path.joinpath("home1")))) |
| 309 | +def test_install_option_in_requirements_file_overrides_cli( |
| 310 | + script, arg_recording_sdist_maker |
| 311 | +): |
| 312 | + simple_sdist = arg_recording_sdist_maker("simple") |
274 | 313 |
|
275 |
| - result = script.pip( |
276 |
| - 'install', '--no-index', '-f', data.find_links, '-r', |
277 |
| - script.scratch_path / 'reqs.txt', |
278 |
| - '--install-option=--home={home}'.format( |
279 |
| - home=script.scratch_path.joinpath("home2")), |
280 |
| - expect_stderr=True) |
| 314 | + reqs_file = script.scratch_path.joinpath("reqs.txt") |
| 315 | + reqs_file.write_text("simple --install-option='-O0'") |
281 | 316 |
|
282 |
| - package_dir = script.scratch / 'home1' / 'lib' / 'python' / 'simple' |
283 |
| - result.did_create(package_dir) |
| 317 | + script.pip( |
| 318 | + 'install', '--no-index', '-f', str(simple_sdist.sdist_path.parent), |
| 319 | + '-r', str(reqs_file), '--install-option=-O1', |
| 320 | + ) |
| 321 | + simple_args = simple_sdist.args() |
| 322 | + assert 'install' in simple_args |
| 323 | + assert simple_args.index('-O1') < simple_args.index('-O0') |
284 | 324 |
|
285 | 325 |
|
286 | 326 | def test_constraints_not_installed_by_default(script, data):
|
@@ -605,35 +645,49 @@ def test_install_unsupported_wheel_file(script, data):
|
605 | 645 | assert len(result.files_created) == 0
|
606 | 646 |
|
607 | 647 |
|
608 |
| -def test_install_options_local_to_package(script, data): |
| 648 | +def test_install_options_local_to_package(script, arg_recording_sdist_maker): |
609 | 649 | """Make sure --install-options does not leak across packages.
|
610 | 650 |
|
611 | 651 | A requirements.txt file can have per-package --install-options; these
|
612 | 652 | should be isolated to just the package instead of leaking to subsequent
|
613 | 653 | packages. This needs to be a functional test because the bug was around
|
614 | 654 | cross-contamination at install time.
|
615 | 655 | """
|
616 |
| - home_simple = script.scratch_path.joinpath("for-simple") |
617 |
| - test_simple = script.scratch.joinpath("for-simple") |
618 |
| - home_simple.mkdir() |
| 656 | + |
| 657 | + simple1_sdist = arg_recording_sdist_maker("simple1") |
| 658 | + simple2_sdist = arg_recording_sdist_maker("simple2") |
| 659 | + |
619 | 660 | reqs_file = script.scratch_path.joinpath("reqs.txt")
|
620 | 661 | reqs_file.write_text(
|
621 |
| - textwrap.dedent(""" |
622 |
| - simple --install-option='--home={home_simple}' |
623 |
| - INITools |
624 |
| - """.format(**locals()))) |
625 |
| - result = script.pip( |
| 662 | + textwrap.dedent( |
| 663 | + """ |
| 664 | + simple1 --install-option='-O0' |
| 665 | + simple2 |
| 666 | + """ |
| 667 | + ) |
| 668 | + ) |
| 669 | + script.pip( |
626 | 670 | 'install',
|
627 |
| - '--no-index', '-f', data.find_links, |
| 671 | + '--no-index', '-f', str(simple1_sdist.sdist_path.parent), |
628 | 672 | '-r', reqs_file,
|
629 |
| - expect_stderr=True, |
630 | 673 | )
|
631 | 674 |
|
632 |
| - simple = test_simple / 'lib' / 'python' / 'simple' |
633 |
| - bad = test_simple / 'lib' / 'python' / 'initools' |
634 |
| - good = script.site_packages / 'initools' |
635 |
| - result.did_create(simple) |
636 |
| - assert result.files_created[simple].dir |
637 |
| - result.did_not_create(bad) |
638 |
| - result.did_create(good) |
639 |
| - assert result.files_created[good].dir |
| 675 | + simple1_args = simple1_sdist.args() |
| 676 | + assert 'install' in simple1_args |
| 677 | + assert '-O0' in simple1_args |
| 678 | + simple2_args = simple2_sdist.args() |
| 679 | + assert 'install' in simple2_args |
| 680 | + assert '-O0' not in simple2_args |
| 681 | + |
| 682 | + |
| 683 | +def test_location_related_install_option_fails(script): |
| 684 | + simple_sdist = create_basic_sdist_for_package(script, "simple", "0.1.0") |
| 685 | + reqs_file = script.scratch_path.joinpath("reqs.txt") |
| 686 | + reqs_file.write_text("simple --install-option='--home=/tmp'") |
| 687 | + result = script.pip( |
| 688 | + 'install', |
| 689 | + '--no-index', '-f', str(simple_sdist.parent), |
| 690 | + '-r', reqs_file, |
| 691 | + expect_error=True |
| 692 | + ) |
| 693 | + assert "['--home'] from simple" in result.stderr |
0 commit comments