Skip to content

Support --use-pep517 and --no-use-pep517 inside requirements files #6447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/6438.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Support using ``--use-pep517`` and ``--no-use-pep517`` inside requirements
files.
6 changes: 6 additions & 0 deletions src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
SUPPORTED_OPTIONS = [
cmdoptions.constraints,
cmdoptions.editable,
cmdoptions.use_pep517,
cmdoptions.no_use_pep517,
cmdoptions.requirements,
cmdoptions.no_index,
cmdoptions.index_url,
Expand Down Expand Up @@ -172,6 +174,10 @@ def process_line(
opts, _ = parser.parse_args(
shlex.split(options_str), defaults) # type: ignore

if opts.use_pep517 is not None:
Copy link

@jayvdb jayvdb Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased this for my own needs, and I only needed to change this to if options and options.use_pep517 ... and replace opts with options on the following line.

# Then the requirements line value takes precedence.
use_pep517 = opts.use_pep517

# preserve for the nested code path
line_comes_from = '%s %s (line %s)' % (
'-c' if constraint else '-r', filename, line_number,
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/test_req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,37 @@ def test_yield_editable_requirement(self):
filename = 'filename'
comes_from = '-r %s (line %s)' % (filename, 1)
req = install_req_from_editable(url, comes_from=comes_from)
assert repr(list(process_line(line, filename, 1))[0]) == repr(req)
actual, = process_line(line, filename, 1)
assert repr(actual) == repr(req)
assert actual.use_pep517 is None

@pytest.mark.parametrize('use_pep517, line, expected', [
# Test passing use_pep517=None.
(None, '-e git+https://url#egg=SomeProject', None),
(None, '--use-pep517 -e git+https://url#egg=SomeProject', True),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs have: <requirement specifier> [; markers] [[--option]...], we should test for the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test with a non-editable, non-vcs requirements specifier as mentioned in the original issue?

(None, '--no-use-pep517 -e git+https://url#egg=SomeProject', False),
# Test passing use_pep517=True.
(True, '-e git+https://url#egg=SomeProject', True),
(True, '--use-pep517 -e git+https://url#egg=SomeProject', True),
(True, '--no-use-pep517 -e git+https://url#egg=SomeProject', False),
# Test passing use_pep517=False.
(False, '-e git+https://url#egg=SomeProject', False),
(False, '--use-pep517 -e git+https://url#egg=SomeProject', True),
(False, '--no-use-pep517 -e git+https://url#egg=SomeProject', False),
])
def test_yield_editable_requirement__pep517_options(
self, use_pep517, line, expected,
):
"""
Test --use-pep517 and --no-use-pep517 in a requirements file line.
"""
actual, = process_line(line, 'filename', 1, use_pep517=use_pep517)
assert repr(actual) == (
'<InstallRequirement object: SomeProject from '
'git+https://url#egg=SomeProject (from -r filename (line 1)) '
'editable=True>'
)
assert actual.use_pep517 == expected

def test_yield_editable_constraint(self):
url = 'git+https://url#egg=SomeProject'
Expand Down