Skip to content

Commit 1d9d56e

Browse files
committed
Refactor handling of per requirement options
Move the conversion from options to function arguments up the call chain.
1 parent ade3826 commit 1d9d56e

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/pip/_internal/req/constructors.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logging
1212
import os
1313
import re
14-
from typing import Any, Dict, Optional, Set, Tuple, Union
14+
from typing import Dict, List, Optional, Set, Tuple, Union
1515

1616
from pip._vendor.packaging.markers import Marker
1717
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
@@ -201,9 +201,11 @@ def parse_req_from_editable(editable_req: str) -> RequirementParts:
201201
def install_req_from_editable(
202202
editable_req: str,
203203
comes_from: Optional[Union[InstallRequirement, str]] = None,
204+
*,
204205
use_pep517: Optional[bool] = None,
205206
isolated: bool = False,
206-
options: Optional[Dict[str, Any]] = None,
207+
global_options: Optional[List[str]] = None,
208+
hash_options: Optional[Dict[str, List[str]]] = None,
207209
constraint: bool = False,
208210
user_supplied: bool = False,
209211
permit_editable_wheels: bool = False,
@@ -222,8 +224,8 @@ def install_req_from_editable(
222224
constraint=constraint,
223225
use_pep517=use_pep517,
224226
isolated=isolated,
225-
global_options=options.get("global_options", []) if options else [],
226-
hash_options=options.get("hashes", {}) if options else {},
227+
global_options=global_options,
228+
hash_options=hash_options,
227229
config_settings=config_settings,
228230
extras=parts.extras,
229231
)
@@ -375,9 +377,11 @@ def _parse_req_string(req_as_string: str) -> Requirement:
375377
def install_req_from_line(
376378
name: str,
377379
comes_from: Optional[Union[str, InstallRequirement]] = None,
380+
*,
378381
use_pep517: Optional[bool] = None,
379382
isolated: bool = False,
380-
options: Optional[Dict[str, Any]] = None,
383+
global_options: Optional[List[str]] = None,
384+
hash_options: Optional[Dict[str, List[str]]] = None,
381385
constraint: bool = False,
382386
line_source: Optional[str] = None,
383387
user_supplied: bool = False,
@@ -398,8 +402,8 @@ def install_req_from_line(
398402
markers=parts.markers,
399403
use_pep517=use_pep517,
400404
isolated=isolated,
401-
global_options=options.get("global_options", []) if options else [],
402-
hash_options=options.get("hashes", {}) if options else {},
405+
global_options=global_options,
406+
hash_options=hash_options,
403407
config_settings=config_settings,
404408
constraint=constraint,
405409
extras=parts.extras,
@@ -471,11 +475,18 @@ def install_req_from_parsed_requirement(
471475
comes_from=parsed_req.comes_from,
472476
use_pep517=use_pep517,
473477
isolated=isolated,
474-
options=parsed_req.options,
478+
global_options=(
479+
parsed_req.options.get("global_options", [])
480+
if parsed_req.options
481+
else []
482+
),
483+
hash_options=(
484+
parsed_req.options.get("hashes", {}) if parsed_req.options else {}
485+
),
475486
constraint=parsed_req.constraint,
476487
line_source=parsed_req.line_source,
477488
user_supplied=user_supplied,
478-
config_settings=config_settings,
489+
config_settings=config_settings, # TODO get this from parsed_req.options?
479490
)
480491
return req
481492

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ def make_install_req_from_link(
6565
use_pep517=template.use_pep517,
6666
isolated=template.isolated,
6767
constraint=template.constraint,
68-
options=dict(
69-
global_options=template.global_options,
70-
hashes=template.hash_options,
71-
),
68+
global_options=template.global_options,
69+
hash_options=template.hash_options,
7270
config_settings=template.config_settings,
7371
)
7472
ireq.original_link = template.original_link
@@ -88,10 +86,8 @@ def make_install_req_from_editable(
8886
isolated=template.isolated,
8987
constraint=template.constraint,
9088
permit_editable_wheels=template.permit_editable_wheels,
91-
options=dict(
92-
global_options=template.global_options,
93-
hashes=template.hash_options,
94-
),
89+
global_options=template.global_options,
90+
hash_options=template.hash_options,
9591
config_settings=template.config_settings,
9692
)
9793

@@ -112,10 +108,8 @@ def _make_install_req_from_dist(
112108
use_pep517=template.use_pep517,
113109
isolated=template.isolated,
114110
constraint=template.constraint,
115-
options=dict(
116-
global_options=template.global_options,
117-
hashes=template.hash_options,
118-
),
111+
global_options=template.global_options,
112+
hash_options=template.hash_options,
119113
config_settings=template.config_settings,
120114
)
121115
ireq.satisfied_by = dist

0 commit comments

Comments
 (0)