Skip to content

Commit 00ece5b

Browse files
committed
simplify: remove filename as it's redundant
1 parent c42b6db commit 00ece5b

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

python/private/pypi/index_sources.bzl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +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; URL if the requirement specifies a direct URL.
36-
* `filename` - str; filename if URL is present, extracted from the URL.
35+
* `url` - str, optional; URL if the requirement specifies a direct URL.
3736
"""
3837
line = line.replace("\\", " ")
3938
head, _, maybe_hashes = line.partition(";")
@@ -58,28 +57,21 @@ def index_sources(line):
5857
" ".join(["--hash=sha256:{}".format(sha) for sha in shas]),
5958
).strip()
6059

61-
# Extract URL if present
6260
if "@" in head:
6361
requirement = requirement_line
6462

65-
# Extract URL from direct URL format
63+
_, _, url_and_rest = requirement.partition("@")
6664
_, _, url_and_rest = requirement.partition("@")
6765
url = url_and_rest.strip().partition(" ")[0].strip()
6866

69-
# Extract filename from URL
7067
if url:
71-
filename = url.rpartition("/")[2]
72-
if not filename:
73-
filename = url.rpartition("/")[0].rpartition("/")[2]
74-
7568
return struct(
7669
requirement = requirement,
7770
requirement_line = requirement_line,
7871
version = version,
7972
shas = sorted(shas),
8073
marker = marker,
8174
url = url,
82-
filename = filename,
8375
)
8476

8577
return struct(

python/private/pypi/parse_requirements.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,16 @@ def _add_dists(*, requirement, index_urls, logger = None):
295295

296296
# Handle direct URLs in requirements
297297
if hasattr(requirement.srcs, "url"):
298-
# Create a struct that matches the expected format for direct URLs
298+
url = requirement.srcs.url
299+
_, _, filename = url.rpartition("/")
299300
direct_url_dist = struct(
300-
url = requirement.srcs.url,
301-
filename = requirement.srcs.filename,
302-
# TODO: if more than one hash is present, we should use all of them
303-
sha256 = requirement.srcs.shas[0] if requirement.srcs.shas else "", # Use hash if provided
301+
url = url,
302+
filename = filename,
303+
sha256 = requirement.srcs.shas[0] if requirement.srcs.shas else "",
304304
yanked = False,
305305
)
306+
307+
# TODO should be able to handle sdist by checking the filename extension
306308
return [direct_url_dist], None
307309

308310
if not index_urls:

tests/pypi/index_sources/index_sources_tests.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,22 @@ def _test_no_simple_api_sources(env):
2929
requirement = "foo==0.0.1 @ https://someurl.org",
3030
marker = "",
3131
url = "https://someurl.org",
32-
filename = "someurl.org",
3332
),
3433
"foo==0.0.1 @ https://someurl.org/package.whl": struct(
3534
requirement = "foo==0.0.1 @ https://someurl.org/package.whl",
3635
marker = "",
3736
url = "https://someurl.org/package.whl",
38-
filename = "package.whl",
3937
),
4038
"foo==0.0.1 @ https://someurl.org/package.whl --hash=sha256:deadbeef": struct(
4139
requirement = "foo==0.0.1 @ https://someurl.org/package.whl --hash=sha256:deadbeef",
4240
marker = "",
4341
url = "https://someurl.org/package.whl",
44-
filename = "package.whl",
4542
shas = ["deadbeef"],
4643
),
4744
"foo==0.0.1 @ https://someurl.org/package.whl; python_version < \"2.7\"\\ --hash=sha256:deadbeef": struct(
4845
requirement = "foo==0.0.1 @ https://someurl.org/package.whl --hash=sha256:deadbeef",
4946
marker = "python_version < \"2.7\"",
5047
url = "https://someurl.org/package.whl",
51-
filename = "package.whl",
5248
shas = ["deadbeef"],
5349
),
5450
}
@@ -61,8 +57,6 @@ def _test_no_simple_api_sources(env):
6157
env.expect.that_str(got.marker).equals(want.marker)
6258
if hasattr(want, "url"):
6359
env.expect.that_str(got.url).equals(want.url)
64-
if hasattr(want, "filename"):
65-
env.expect.that_str(got.filename).equals(want.filename)
6660

6761
_tests.append(_test_no_simple_api_sources)
6862

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def _test_direct_urls(env):
147147
shas = ["deadbeef"],
148148
version = "",
149149
url = "https://example.org/bar-1.0.whl",
150-
filename = "bar-1.0.whl",
151150
),
152151
target_platforms = ["linux_x86_64"],
153152
whls = [struct(
@@ -171,7 +170,6 @@ def _test_direct_urls(env):
171170
shas = ["deadb00f"],
172171
version = "",
173172
url = "https://test.com/baz-2.0.whl",
174-
filename = "baz-2.0.whl",
175173
),
176174
target_platforms = ["linux_x86_64"],
177175
whls = [struct(
@@ -195,7 +193,6 @@ def _test_direct_urls(env):
195193
shas = [],
196194
version = "",
197195
url = "https://some-url/package.whl",
198-
filename = "package.whl",
199196
),
200197
target_platforms = ["linux_x86_64"],
201198
whls = [struct(

0 commit comments

Comments
 (0)