Skip to content
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

Vendoring is broken #1918

Closed
bendavini opened this issue May 23, 2024 · 0 comments · Fixed by #1942
Closed

Vendoring is broken #1918

bendavini opened this issue May 23, 2024 · 0 comments · Fixed by #1942

Comments

@bendavini
Copy link

🐞 bug report

Affected Rule

vendored pip_parse dependencies

Is this a regression?

Yes, fixed in #608 and linked issues

Description

Clients of a vendored workspace (e.g., pip_parse_vendored) cannot use the 1-step solution documented in the readme and are instead still required to pip_parse their dependency's dependencies.

🔬 Minimal Reproduction

From slack thread (as of 66550eca4ae9d94be3a32da86e60a54cba13cf74):
Create a directory in use_pip_parse_vendored in rules_python/examples
WORKSPACE:

workspace(name = "use_pip_parse_vendored")

local_repository(
    name = "rules_python",
    path = "../..",
)

local_repository(
    name = "pip_parse_vendored",
    path = "../pip_parse_vendored",
)

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
    name = "python39",
    python_version = "3.9",
)

load("@pip_parse_vendored//:requirements.bzl", "install_deps")

install_deps()

hello_world.py in same directory (that wants to use one of the pip_parse_vendored requirements):

#!/usr/bin/env python3
import urllib3
if __name__ == "__main__":
    print("Hello world")
    http = urllib3.PoolManager()
    resp = http.request("GET", "https://httpbin.org/robots.txt")
    print(resp.data)

BUILD.bazel file that uses the dependency:

load("@rules_python//python:defs.bzl", "py_binary")
load("@pip_parse_vendored//:requirements.bzl", "requirement")

py_binary(
    name = "hello_world",
    srcs = ["hello_world.py"],
    visibility = ["//:__subpackages__"],
    deps = [
        requirement("urllib3"),
    ]
)

🔥 Exception or Error

Bazel 7.1.2:

bazel build ...
ERROR: no such package '@@[unknown repo 'pip' requested from @@]//urllib3': The repository '@@[unknown repo 'pip' requested from @@]' could not be resolved: No repository visible as '@pip' from main repository
ERROR: /Users/davinib/code/git/nonvmware/bazel/rules_python/examples/use_pip_parse_vendored/BUILD.bazel:4:10: no such package '@@[unknown repo 'pip' requested from @@]//urllib3': The repository '@@[unknown repo 'pip' requested from @@]' could not be resolved: No repository visible as '@pip' from main repository and referenced by '//:hello_world'
ERROR: Analysis of target '//:hello_world' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.946s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

Bazel 6.4.0:

ERROR: /Users/davinib/code/git/nonvmware/bazel/rules_python/examples/use_pip_parse_vendored/BUILD.bazel:4:10: no such package '@pip//urllib3': The repository '@pip' could not be resolved: Repository '@pip' is not defined and referenced by '//:hello_world'
ERROR: Analysis of target '//:hello_world' failed; build aborted: Analysis failed

🌍 Your Environment

Mac x86 14.4.1 (23E224)

Output of bazel version:
Both 7.1.2 and 6.4.0

Rules_python version:
ToT on 0.32.2 - 66550eca4ae9d94be3a32da86e60a54cba13cf74

Anything else relevant?
From slack thread:
Yeah, it is unfortunate that it is broken right now and the reason is that we are using aliases in the requirements.bzl for accessing the packages.
I think the targets in https://github.com/bazelbuild/rules_python/blob/main/examples/pip_parse_vendored/requirements.bzl#L9 should look like @pip_certify//:pkg instead of @pip//certify:pkg. Feel free to raise an issue in rules_python and a PR to fix this would be really welcome.
In the mean time the vendoring script could use some shell substitution like: sed 's|\(@pip\)//\(.*\):|\1_\2//:|g in order to get it generate the correct requirements.bzl.

aignas added a commit to aignas/rules_python that referenced this issue Jun 7, 2024
With this change we are now again generating a working
`requirements.bzl` file which broke during our switch
to using the `hub` repo.

Fixes bazelbuild#1918.
github-merge-queue bot pushed a commit that referenced this issue Jun 10, 2024
With this change we are now again generating a working
`requirements.bzl` file which broke during our switch
to using the `hub` repo.

Fixes #1918.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants