From fb68051a2f8f143aeace28f6a253033638465d34 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 7 Mar 2019 15:54:44 +0300 Subject: [PATCH 1/3] Add an option to allow enabling/disabling build isolation --- piptools/repositories/pypi.py | 5 +++-- piptools/scripts/compile.py | 8 ++++++-- tests/test_cli_compile.py | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 7a2bd85fa..e54ae0805 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -49,9 +49,10 @@ class PyPIRepository(BaseRepository): config), but any other PyPI mirror can be used if index_urls is changed/configured on the Finder. """ - def __init__(self, pip_options, session): + def __init__(self, pip_options, session, build_isolation=False): self.session = session self.pip_options = pip_options + self.build_isolation = build_isolation index_urls = [pip_options.index_url] + pip_options.extra_index_urls if pip_options.no_index: @@ -161,7 +162,7 @@ def resolve_reqs(self, download_dir, ireq, wheel_cache): 'download_dir': download_dir, 'wheel_download_dir': self._wheel_download_dir, 'progress_bar': 'off', - 'build_isolation': False + 'build_isolation': self.build_isolation, } resolver_kwargs = { 'finder': self.finder, diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 0d4a6f55b..2eaea9b3b 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -61,10 +61,14 @@ @click.option('--max-rounds', default=10, help="Maximum number of rounds before resolving the requirements aborts.") @click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True)) +@click.option('--build-isolation/--no-build-isolation', is_flag=True, default=False, + help="Enable isolation when building a modern source distribution. " + "Build dependencies specified by PEP 518 must be already installed " + "if build isolation is disabled.") def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_index_url, cert, client_cert, trusted_host, header, index, emit_trusted_host, annotate, upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes, - src_files, max_rounds): + src_files, max_rounds, build_isolation): """Compiles requirements.txt from requirements.in specs.""" log.verbosity = verbose - quiet @@ -122,7 +126,7 @@ def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_inde pip_options, _ = pip_command.parse_args(pip_args) session = pip_command._build_session(pip_options) - repository = PyPIRepository(pip_options, session) + repository = PyPIRepository(pip_options, session, build_isolation) upgrade_install_reqs = {} # Proxy with a LocalRequirementsRepository if --upgrade is not specified diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index e74b45f2b..ab72e3e2b 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -534,3 +534,23 @@ def test_cert_option(MockPyPIRepository, runner, option, attr, expected): for call in MockPyPIRepository.call_args_list: pip_options = call[0][0] assert getattr(pip_options, attr) == expected + + +@pytest.mark.parametrize('option, expected', [ + ('--build-isolation', True), + ('--no-build-isolation', False), +]) +@mock.patch('piptools.scripts.compile.PyPIRepository') +def test_build_isolation_option(MockPyPIRepository, runner, option, expected): + """ + A value of the --build-isolation/--no-build-isolation flag must be passed to the PyPIRepository. + """ + with open('requirements.in', 'w'): + pass + + runner.invoke(cli, [option]) + + # Ensure the build_isolation in PyPIRepository has have the expected option + for call in MockPyPIRepository.call_args_list: + build_isolation = call[0][2] + assert build_isolation is expected From bf48ad465e93115b00498720e916ac7d438cc06d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 7 Mar 2019 16:49:46 +0300 Subject: [PATCH 2/3] Fix grammar Co-Authored-By: atugushev --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index ab72e3e2b..8b4ad43b0 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -550,7 +550,7 @@ def test_build_isolation_option(MockPyPIRepository, runner, option, expected): runner.invoke(cli, [option]) - # Ensure the build_isolation in PyPIRepository has have the expected option + # Ensure the build_isolation option in PyPIRepository has the expected value. for call in MockPyPIRepository.call_args_list: build_isolation = call[0][2] assert build_isolation is expected From 4ab052f5dcdce71a8cfb3368f30ef120e42bdbaf Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 7 Mar 2019 17:23:48 +0300 Subject: [PATCH 3/3] Ensure MockPyPIRepository called once --- tests/test_cli_compile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 8b4ad43b0..750c40da4 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -551,6 +551,4 @@ def test_build_isolation_option(MockPyPIRepository, runner, option, expected): runner.invoke(cli, [option]) # Ensure the build_isolation option in PyPIRepository has the expected value. - for call in MockPyPIRepository.call_args_list: - build_isolation = call[0][2] - assert build_isolation is expected + assert [call[0][2] for call in MockPyPIRepository.call_args_list] == [expected]