Skip to content

fix(pypi): support properly installing sdists via pypi without index #3115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ END_UNRELEASED_TEMPLATE
* (toolchains) use "command -v" to find interpreter in `$PATH`
([#3150](https://github.com/bazel-contrib/rules_python/pull/3150)).
* (pypi) `bazel vendor` now works in `bzlmod` ({gh-issue}`3079`).
* (pypi) Correctly pull `sdist` distributions using `pip`
([#3131](https://github.com/bazel-contrib/rules_python/pull/3131)).

{#v0-0-0-added}
### Added
Expand Down
6 changes: 3 additions & 3 deletions python/private/pypi/index_sources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def index_sources(line):
is_known_ext = True
break

if is_known_ext:
requirement = requirement_line
if filename.endswith(".whl"):
requirement = maybe_requirement.strip()
else:
elif not is_known_ext:
# could not detect filename from the URL
filename = ""
requirement = requirement_line

return struct(
requirement = requirement,
Expand Down
2 changes: 1 addition & 1 deletion tests/pypi/extension/extension_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ git_dep @ git+https://git.server/repo/project@deadbeefdeadbeef
"extra_pip_args": ["--extra-args-for-sdist-building"],
"filename": "any-name.tar.gz",
"python_interpreter_target": "unit_test_interpreter_target",
"requirement": "direct_sdist_without_sha",
"requirement": "direct_sdist_without_sha @ some-archive/any-name.tar.gz",
"sha256": "",
"urls": ["some-archive/any-name.tar.gz"],
},
Expand Down
5 changes: 4 additions & 1 deletion tests/pypi/index_sources/index_sources_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def _test_no_simple_api_sources(env):
filename = "package.whl",
),
"foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f": struct(
requirement = "foo[extra]",
# NOTE @aignas 2025-08-03: we need to ensure that sdists continue working
# when we are using pip to install them even if the experimental_index_url
# code path is used.
requirement = "foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f",
requirement_line = "foo[extra] @ https://example.org/foo-1.0.tar.gz --hash=sha256:deadbe0f",
marker = "",
url = "https://example.org/foo-1.0.tar.gz",
Expand Down
20 changes: 17 additions & 3 deletions tests/pypi/parse_requirements/parse_requirements_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ foo==0.0.1 \
""",
"requirements_direct": """\
foo[extra] @ https://some-url/package.whl
""",
"requirements_direct_sdist": """
foo @ https://github.com/org/foo/downloads/foo-1.1.tar.gz
""",
"requirements_extra_args": """\
--index-url=example.org
Expand Down Expand Up @@ -131,22 +134,33 @@ def _test_direct_urls_integration(env):
ctx = _mock_ctx(),
requirements_by_platform = {
"requirements_direct": ["linux_x86_64"],
"requirements_direct_sdist": ["osx_x86_64"],
},
)
env.expect.that_collection(got).contains_exactly([
struct(
name = "foo",
is_exposed = True,
is_multiple_versions = False,
is_multiple_versions = True,
srcs = [
struct(
distribution = "foo",
extra_pip_args = [],
filename = "foo-1.1.tar.gz",
requirement_line = "foo @ https://github.com/org/foo/downloads/foo-1.1.tar.gz",
sha256 = "",
target_platforms = ["osx_x86_64"],
url = "https://github.com/org/foo/downloads/foo-1.1.tar.gz",
yanked = False,
),
struct(
distribution = "foo",
extra_pip_args = [],
filename = "package.whl",
requirement_line = "foo[extra]",
sha256 = "",
target_platforms = ["linux_x86_64"],
url = "https://some-url/package.whl",
filename = "package.whl",
sha256 = "",
yanked = False,
),
],
Expand Down