Skip to content

Commit 9a4b874

Browse files
committed
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]> (cherry picked from commit f6dd386) Cherry-pick notes: adapted the changelog to mention 1.5.2
1 parent ba2e4f8 commit 9a4b874

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ BEGIN_UNRELEASED_TEMPLATE
4747
END_UNRELEASED_TEMPLATE
4848
-->
4949

50+
{#1-5-2}
51+
## [1.5.2] - 2025-08-11
52+
53+
[1.5.2]: https://github.com/bazel-contrib/rules_python/releases/tag/1.5.2
54+
55+
{#v1-5-2-fixed}
56+
### Fixed
57+
* (pypi) Correctly pull `sdist` distributions using `pip`
58+
([#3131](https://github.com/bazel-contrib/rules_python/pull/3131)).
59+
5060
{#1-5-1}
5161
## [1.5.1] - 2025-07-06
5262

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
@@ -811,7 +811,7 @@ git_dep @ git+https://git.server/repo/project@deadbeefdeadbeef
811811
"extra_pip_args": ["--extra-args-for-sdist-building"],
812812
"filename": "any-name.tar.gz",
813813
"python_interpreter_target": "unit_test_interpreter_target",
814-
"requirement": "direct_sdist_without_sha",
814+
"requirement": "direct_sdist_without_sha @ some-archive/any-name.tar.gz",
815815
"sha256": "",
816816
"urls": ["some-archive/any-name.tar.gz"],
817817
},

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)