Skip to content

Commit 9a79332

Browse files
committed
always emit the url attribute
1 parent 00ece5b commit 9a79332

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

python/private/pypi/index_sources.bzl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def index_sources(line):
3232
* `marker` - str; the marker expression, as per PEP508 spec.
3333
* `requirement` - str; a requirement line without the marker. This can
3434
be given to `pip` to install a package.
35-
* `url` - str, optional; URL if the requirement specifies a direct URL.
35+
* `url` - str; URL if the requirement specifies a direct URL, empty string otherwise.
3636
"""
3737
line = line.replace("\\", " ")
3838
head, _, maybe_hashes = line.partition(";")
@@ -57,27 +57,17 @@ def index_sources(line):
5757
" ".join(["--hash=sha256:{}".format(sha) for sha in shas]),
5858
).strip()
5959

60+
url = ""
6061
if "@" in head:
6162
requirement = requirement_line
62-
63-
_, _, url_and_rest = requirement.partition("@")
6463
_, _, url_and_rest = requirement.partition("@")
6564
url = url_and_rest.strip().partition(" ")[0].strip()
6665

67-
if url:
68-
return struct(
69-
requirement = requirement,
70-
requirement_line = requirement_line,
71-
version = version,
72-
shas = sorted(shas),
73-
marker = marker,
74-
url = url,
75-
)
76-
7766
return struct(
7867
requirement = requirement,
7968
requirement_line = requirement_line,
8069
version = version,
8170
shas = sorted(shas),
8271
marker = marker,
72+
url = url,
8373
)

python/private/pypi/parse_requirements.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def _add_dists(*, requirement, index_urls, logger = None):
294294
"""
295295

296296
# Handle direct URLs in requirements
297-
if hasattr(requirement.srcs, "url"):
297+
if requirement.srcs.url:
298298
url = requirement.srcs.url
299299
_, _, filename = url.rpartition("/")
300300
direct_url_dist = struct(

tests/pypi/index_sources/index_sources_tests.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _test_no_simple_api_sources(env):
2424
"foo==0.0.1": struct(
2525
requirement = "foo==0.0.1",
2626
marker = "",
27+
url = "",
2728
),
2829
"foo==0.0.1 @ https://someurl.org": struct(
2930
requirement = "foo==0.0.1 @ https://someurl.org",
@@ -55,8 +56,7 @@ def _test_no_simple_api_sources(env):
5556
env.expect.that_str(got.requirement).equals(want.requirement)
5657
env.expect.that_str(got.requirement_line).equals(got.requirement)
5758
env.expect.that_str(got.marker).equals(want.marker)
58-
if hasattr(want, "url"):
59-
env.expect.that_str(got.url).equals(want.url)
59+
env.expect.that_str(got.url).equals(want.url)
6060

6161
_tests.append(_test_no_simple_api_sources)
6262

@@ -70,6 +70,7 @@ def _test_simple_api_sources(env):
7070
marker = "",
7171
requirement = "foo==0.0.2",
7272
requirement_line = "foo==0.0.2 --hash=sha256:deafbeef --hash=sha256:deadbeef",
73+
url = "",
7374
),
7475
"foo[extra]==0.0.2; (python_version < 2.7 or extra == \"@\") --hash=sha256:deafbeef --hash=sha256:deadbeef": struct(
7576
shas = [
@@ -79,6 +80,7 @@ def _test_simple_api_sources(env):
7980
marker = "(python_version < 2.7 or extra == \"@\")",
8081
requirement = "foo[extra]==0.0.2",
8182
requirement_line = "foo[extra]==0.0.2 --hash=sha256:deafbeef --hash=sha256:deadbeef",
83+
url = "",
8284
),
8385
}
8486
for input, want in tests.items():
@@ -88,6 +90,7 @@ def _test_simple_api_sources(env):
8890
env.expect.that_str(got.requirement).equals(want.requirement)
8991
env.expect.that_str(got.requirement_line).equals(want.requirement_line)
9092
env.expect.that_str(got.marker).equals(want.marker)
93+
env.expect.that_str(got.url).equals(want.url)
9194

9295
_tests.append(_test_simple_api_sources)
9396

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def _test_simple(env):
108108
requirement_line = "foo[extra]==0.0.1 --hash=sha256:deadbeef",
109109
shas = ["deadbeef"],
110110
version = "0.0.1",
111+
url = "",
111112
),
112113
target_platforms = [
113114
"linux_x86_64",
@@ -228,6 +229,7 @@ def _test_extra_pip_args(env):
228229
requirement_line = "foo[extra]==0.0.1 --hash=sha256:deadbeef",
229230
shas = ["deadbeef"],
230231
version = "0.0.1",
232+
url = "",
231233
),
232234
target_platforms = [
233235
"linux_x86_64",
@@ -265,6 +267,7 @@ def _test_dupe_requirements(env):
265267
requirement_line = "foo[extra,extra_2]==0.0.1 --hash=sha256:deadbeef",
266268
shas = ["deadbeef"],
267269
version = "0.0.1",
270+
url = "",
268271
),
269272
target_platforms = ["linux_x86_64"],
270273
whls = [],
@@ -294,6 +297,7 @@ def _test_multi_os(env):
294297
requirement_line = "bar==0.0.1 --hash=sha256:deadb00f",
295298
shas = ["deadb00f"],
296299
version = "0.0.1",
300+
url = "",
297301
),
298302
target_platforms = ["windows_x86_64"],
299303
whls = [],
@@ -311,6 +315,7 @@ def _test_multi_os(env):
311315
requirement_line = "foo==0.0.3 --hash=sha256:deadbaaf",
312316
shas = ["deadbaaf"],
313317
version = "0.0.3",
318+
url = "",
314319
),
315320
target_platforms = ["linux_x86_64"],
316321
whls = [],
@@ -326,6 +331,7 @@ def _test_multi_os(env):
326331
requirement_line = "foo[extra]==0.0.2 --hash=sha256:deadbeef",
327332
shas = ["deadbeef"],
328333
version = "0.0.2",
334+
url = "",
329335
),
330336
target_platforms = ["windows_x86_64"],
331337
whls = [],
@@ -365,6 +371,7 @@ def _test_multi_os_legacy(env):
365371
requirement_line = "bar==0.0.1 --hash=sha256:deadb00f",
366372
shas = ["deadb00f"],
367373
version = "0.0.1",
374+
url = "",
368375
),
369376
target_platforms = ["cp39_linux_x86_64"],
370377
whls = [],
@@ -382,6 +389,7 @@ def _test_multi_os_legacy(env):
382389
requirement_line = "foo==0.0.1 --hash=sha256:deadbeef",
383390
shas = ["deadbeef"],
384391
version = "0.0.1",
392+
url = "",
385393
),
386394
target_platforms = ["cp39_linux_x86_64"],
387395
whls = [],
@@ -397,6 +405,7 @@ def _test_multi_os_legacy(env):
397405
requirement = "foo==0.0.3",
398406
shas = ["deadbaaf"],
399407
version = "0.0.3",
408+
url = "",
400409
),
401410
target_platforms = ["cp39_osx_aarch64"],
402411
whls = [],
@@ -450,6 +459,7 @@ def _test_env_marker_resolution(env):
450459
requirement_line = "bar==0.0.1 --hash=sha256:deadbeef",
451460
shas = ["deadbeef"],
452461
version = "0.0.1",
462+
url = "",
453463
),
454464
target_platforms = ["cp311_linux_super_exotic", "cp311_windows_x86_64"],
455465
whls = [],
@@ -467,6 +477,7 @@ def _test_env_marker_resolution(env):
467477
requirement_line = "foo[extra]==0.0.1 --hash=sha256:deadbeef",
468478
shas = ["deadbeef"],
469479
version = "0.0.1",
480+
url = "",
470481
),
471482
target_platforms = ["cp311_windows_x86_64"],
472483
whls = [],
@@ -502,6 +513,7 @@ def _test_different_package_version(env):
502513
requirement_line = "foo==0.0.1 --hash=sha256:deadb00f",
503514
shas = ["deadb00f"],
504515
version = "0.0.1",
516+
url = "",
505517
),
506518
target_platforms = ["linux_x86_64"],
507519
whls = [],
@@ -517,6 +529,7 @@ def _test_different_package_version(env):
517529
requirement_line = "foo==0.0.1+local --hash=sha256:deadbeef",
518530
shas = ["deadbeef"],
519531
version = "0.0.1+local",
532+
url = "",
520533
),
521534
target_platforms = ["linux_x86_64"],
522535
whls = [],

0 commit comments

Comments
 (0)