Skip to content

Commit 69f2278

Browse files
committed
fix(pip): parse the index_url from uv.lock file
This is so that the purl can be generated correctly and we pass the right index_url parameter to the whl_library file. Work towards #1975
1 parent f1db067 commit 69f2278

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

python/private/pypi/parse_requirements.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p
176176
"versions": {},
177177
})
178178
entry["versions"][version] = None
179+
registry = pkg.get("source", {}).get("registry", "")
180+
if registry.rstrip("/").endswith("simple"):
181+
index_url = "{}/{}".format(registry, norm_name.replace("_", "-"))
182+
else:
183+
index_url = ""
184+
entry["index_url"] = index_url
179185

180186
pkg_extras = sorted(extras_map.get(name, []))
181187
extra_str = "[{}]".format(",".join(pkg_extras)) if pkg_extras else ""
@@ -287,7 +293,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p
287293
name = norm_name,
288294
is_exposed = True,
289295
is_multiple_versions = len(versions) > 1,
290-
index_url = "",
296+
index_url = info["index_url"],
291297
srcs = info["resolved_srcs"],
292298
)
293299
ret.append(item)

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ def _test_uv_lock_consistent(env):
10521052
env.expect.that_collection(got).contains_exactly([
10531053
struct(
10541054
name = "foo",
1055-
index_url = "",
1055+
index_url = "https://pypi.org/simple/foo",
10561056
is_exposed = True,
10571057
is_multiple_versions = False,
10581058
srcs = [
@@ -1080,7 +1080,7 @@ def _test_uv_lock_primary_source(env):
10801080
env.expect.that_collection(got).contains_exactly([
10811081
struct(
10821082
name = "foo",
1083-
index_url = "",
1083+
index_url = "https://pypi.org/simple/foo",
10841084
is_exposed = True,
10851085
is_multiple_versions = False,
10861086
srcs = [
@@ -1108,7 +1108,7 @@ def _test_uv_lock_primary_source_multiple_versions(env):
11081108
env.expect.that_collection(got).contains_exactly([
11091109
struct(
11101110
name = "foo",
1111-
index_url = "",
1111+
index_url = "https://pypi.org/simple/foo",
11121112
is_exposed = True,
11131113
is_multiple_versions = True,
11141114
srcs = [
@@ -1146,7 +1146,7 @@ def _test_uv_lock_primary_source_with_extras(env):
11461146
env.expect.that_collection(got).contains_exactly([
11471147
struct(
11481148
name = "foo",
1149-
index_url = "",
1149+
index_url = "https://pypi.org/simple/foo",
11501150
is_exposed = True,
11511151
is_multiple_versions = False,
11521152
srcs = [
@@ -1174,7 +1174,7 @@ def _test_uv_lock_primary_source_includes_virtual(env):
11741174
env.expect.that_collection(got).contains_exactly([
11751175
struct(
11761176
name = "foo",
1177-
index_url = "",
1177+
index_url = "https://pypi.org/simple/foo",
11781178
is_exposed = True,
11791179
is_multiple_versions = False,
11801180
srcs = [
@@ -1212,7 +1212,7 @@ def _test_uv_lock_cross_consistent(env):
12121212
env.expect.that_collection(got).contains_exactly([
12131213
struct(
12141214
name = "foo",
1215-
index_url = "",
1215+
index_url = "https://pypi.org/simple/foo",
12161216
is_exposed = True,
12171217
is_multiple_versions = False,
12181218
srcs = [
@@ -1268,7 +1268,7 @@ def _test_uv_lock_rules_python_pkg_not_skipped(env):
12681268
env.expect.that_collection(got).contains_exactly([
12691269
struct(
12701270
name = "rules_python",
1271-
index_url = "",
1271+
index_url = "https://pypi.org/simple/rules-python",
12721272
is_exposed = True,
12731273
is_multiple_versions = False,
12741274
srcs = [
@@ -1301,7 +1301,7 @@ def _test_uv_lock_no_consistency_check(env):
13011301
env.expect.that_collection(got).contains_exactly([
13021302
struct(
13031303
name = "foo",
1304-
index_url = "",
1304+
index_url = "https://pypi.org/simple/foo",
13051305
is_exposed = True,
13061306
is_multiple_versions = False,
13071307
srcs = [
@@ -1329,7 +1329,7 @@ def _test_uv_lock_multiple_packages(env):
13291329
env.expect.that_collection(got).contains_exactly([
13301330
struct(
13311331
name = "bar",
1332-
index_url = "",
1332+
index_url = "https://pypi.org/simple/bar",
13331333
is_exposed = True,
13341334
is_multiple_versions = False,
13351335
srcs = [
@@ -1347,7 +1347,7 @@ def _test_uv_lock_multiple_packages(env):
13471347
),
13481348
struct(
13491349
name = "foo",
1350-
index_url = "",
1350+
index_url = "https://pypi.org/simple/foo",
13511351
is_exposed = True,
13521352
is_multiple_versions = False,
13531353
srcs = [
@@ -1376,7 +1376,7 @@ def _test_uv_lock_with_extra_pip_args(env):
13761376
env.expect.that_collection(got).contains_exactly([
13771377
struct(
13781378
name = "foo",
1379-
index_url = "",
1379+
index_url = "https://pypi.org/simple/foo",
13801380
is_exposed = True,
13811381
is_multiple_versions = False,
13821382
srcs = [
@@ -1408,7 +1408,7 @@ def _test_uv_lock_multi_os_with_requirements(env):
14081408
env.expect.that_collection(got).contains_exactly([
14091409
struct(
14101410
name = "foo",
1411-
index_url = "",
1411+
index_url = "https://pypi.org/simple/foo",
14121412
is_exposed = True,
14131413
is_multiple_versions = False,
14141414
srcs = [
@@ -1436,7 +1436,7 @@ def _test_uv_lock_extras_optional_deps(env):
14361436
env.expect.that_collection(got).contains_exactly([
14371437
struct(
14381438
name = "foo",
1439-
index_url = "",
1439+
index_url = "https://pypi.org/simple/foo",
14401440
is_exposed = True,
14411441
is_multiple_versions = False,
14421442
srcs = [
@@ -1464,7 +1464,7 @@ def _test_uv_lock_extras_dep_edge(env):
14641464
env.expect.that_collection(got).contains_exactly([
14651465
struct(
14661466
name = "bar",
1467-
index_url = "",
1467+
index_url = "https://pypi.org/simple/bar",
14681468
is_exposed = True,
14691469
is_multiple_versions = False,
14701470
srcs = [
@@ -1482,7 +1482,7 @@ def _test_uv_lock_extras_dep_edge(env):
14821482
),
14831483
struct(
14841484
name = "foo",
1485-
index_url = "",
1485+
index_url = "https://pypi.org/simple/foo",
14861486
is_exposed = True,
14871487
is_multiple_versions = False,
14881488
srcs = [
@@ -1517,7 +1517,7 @@ def _test_uv_lock_wheel_dedup_single_version(env):
15171517
env.expect.that_collection(got).contains_exactly([
15181518
struct(
15191519
name = "foo",
1520-
index_url = "",
1520+
index_url = "https://pypi.org/simple/foo",
15211521
is_exposed = True,
15221522
is_multiple_versions = False,
15231523
srcs = [
@@ -1563,7 +1563,7 @@ def _test_uv_lock_wheel_dedup_resolution_markers(env):
15631563
env.expect.that_collection(got).contains_exactly([
15641564
struct(
15651565
name = "foo",
1566-
index_url = "",
1566+
index_url = "https://pypi.org/simple/foo",
15671567
is_exposed = True,
15681568
is_multiple_versions = True,
15691569
srcs = [
@@ -1601,7 +1601,7 @@ def _test_uv_lock_requires_dist_extras(env):
16011601
env.expect.that_collection(got).contains_exactly([
16021602
struct(
16031603
name = "foo",
1604-
index_url = "",
1604+
index_url = "https://pypi.org/simple/foo",
16051605
is_exposed = True,
16061606
is_multiple_versions = False,
16071607
srcs = [

0 commit comments

Comments
 (0)