Skip to content

Commit

Permalink
Add an option to allow enabling/disabling build isolation (#758)
Browse files Browse the repository at this point in the history
Co-Authored-By: Daniel Hahler <[email protected]>
  • Loading branch information
atugushev and blueyed authored Mar 11, 2019
1 parent cb83ccf commit 25ac090
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 3 additions & 2 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,21 @@ 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 option in PyPIRepository has the expected value.
assert [call[0][2] for call in MockPyPIRepository.call_args_list] == [expected]

0 comments on commit 25ac090

Please sign in to comment.