Skip to content

Commit f6dd386

Browse files
aignasrickeylev
andauthored
fix(pypi): support properly installing sdists via pypi without index (#3115)
This fixes the subtle bug introduced in #2871, where we were dropping the URL from the requirement, because we can download the sdist directly. We cannot add --no-index because sdists in general may require extra build dependencies and we had already issues previously (see 0.36 release notes). Fixes #2363 Fixes #3131 --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 5c09732 commit f6dd386

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ END_UNRELEASED_TEMPLATE
112112
* (toolchains) use "command -v" to find interpreter in `$PATH`
113113
([#3150](https://github.com/bazel-contrib/rules_python/pull/3150)).
114114
* (pypi) `bazel vendor` now works in `bzlmod` ({gh-issue}`3079`).
115+
* (pypi) Correctly pull `sdist` distributions using `pip`
116+
([#3131](https://github.com/bazel-contrib/rules_python/pull/3131)).
115117
* (core) builds work again on `7.x` `WORKSPACE` configurations
116118
([#3119](https://github.com/bazel-contrib/rules_python/issues/3119)).
117119

python/private/pypi/index_sources.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def index_sources(line):
9393
is_known_ext = True
9494
break
9595

96-
if is_known_ext:
96+
requirement = requirement_line
97+
if filename.endswith(".whl"):
9798
requirement = maybe_requirement.strip()
98-
else:
99+
elif not is_known_ext:
99100
# could not detect filename from the URL
100101
filename = ""
101-
requirement = requirement_line
102102

103103
return struct(
104104
requirement = requirement,

tests/pypi/extension/extension_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ git_dep @ git+https://git.server/repo/project@deadbeefdeadbeef
934934
"extra_pip_args": ["--extra-args-for-sdist-building"],
935935
"filename": "any-name.tar.gz",
936936
"python_interpreter_target": "unit_test_interpreter_target",
937-
"requirement": "direct_sdist_without_sha",
937+
"requirement": "direct_sdist_without_sha @ some-archive/any-name.tar.gz",
938938
"sha256": "",
939939
"urls": ["some-archive/any-name.tar.gz"],
940940
},

tests/pypi/index_sources/index_sources_tests.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def _test_no_simple_api_sources(env):
7373
filename = "package.whl",
7474
),
7575
"foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f": struct(
76-
requirement = "foo[extra]",
76+
# NOTE @aignas 2025-08-03: we need to ensure that sdists continue working
77+
# when we are using pip to install them even if the experimental_index_url
78+
# code path is used.
79+
requirement = "foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f",
7780
requirement_line = "foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f",
7881
marker = "",
7982
url = "https://example.org/foo-1.0.tar.gz",

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ foo==0.0.1 \
2727
""",
2828
"requirements_direct": """\
2929
foo[extra] @ https://some-url/package.whl
30+
""",
31+
"requirements_direct_sdist": """
32+
foo @ https://github.com/org/foo/downloads/foo-1.1.tar.gz
3033
""",
3134
"requirements_extra_args": """\
3235
--index-url=example.org
@@ -131,22 +134,33 @@ def _test_direct_urls_integration(env):
131134
ctx = _mock_ctx(),
132135
requirements_by_platform = {
133136
"requirements_direct": ["linux_x86_64"],
137+
"requirements_direct_sdist": ["osx_x86_64"],
134138
},
135139
)
136140
env.expect.that_collection(got).contains_exactly([
137141
struct(
138142
name = "foo",
139143
is_exposed = True,
140-
is_multiple_versions = False,
144+
is_multiple_versions = True,
141145
srcs = [
142146
struct(
143147
distribution = "foo",
144148
extra_pip_args = [],
149+
filename = "foo-1.1.tar.gz",
150+
requirement_line = "foo @ https://github.com/org/foo/downloads/foo-1.1.tar.gz",
151+
sha256 = "",
152+
target_platforms = ["osx_x86_64"],
153+
url = "https://github.com/org/foo/downloads/foo-1.1.tar.gz",
154+
yanked = False,
155+
),
156+
struct(
157+
distribution = "foo",
158+
extra_pip_args = [],
159+
filename = "package.whl",
145160
requirement_line = "foo[extra]",
161+
sha256 = "",
146162
target_platforms = ["linux_x86_64"],
147163
url = "https://some-url/package.whl",
148-
filename = "package.whl",
149-
sha256 = "",
150164
yanked = False,
151165
),
152166
],

0 commit comments

Comments
 (0)