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

Using rules_python requires undocumented dependency on bazel_skylib #932

Closed
oliverlee opened this issue Dec 16, 2022 · 15 comments
Closed

Using rules_python requires undocumented dependency on bazel_skylib #932

oliverlee opened this issue Dec 16, 2022 · 15 comments

Comments

@oliverlee
Copy link

I'm getting the following error:

> bazel fetch //...
ERROR: Failed to load Starlark extension '@bazel_skylib//lib:dicts.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @bazel_skylib

with this:

# //:WORKSPACE.bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    sha256 = "497ca47374f48c8b067d786b512ac10a276211810f4a580178ee9b9ad139323a",
    strip_prefix = "rules_python-0.16.1",
    url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.16.1.tar.gz",
)

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

python_register_toolchains(
    name = "python3_10",
    python_version = "3.10",
)

load("@python3_10//:defs.bzl", "interpreter")

and

# //:BUILD.bazel

I assume this is the cause:
https://github.com/bazelbuild/rules_python/blob/main/python/config_settings/transition.bzl#L5

bazel_skylib isn't needed with rules_python 0.14.0.

@yin
Copy link

yin commented Jan 10, 2023

I managed to fix the problem locally by adding the repository to my WORKSPACE file:

http_archive(
    name = "bazel_skylib",
    sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
    ],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

@aiuto
Copy link
Contributor

aiuto commented Jan 11, 2023

Almost every rule set depends on skylib. And they might depend on different versions.
The safest way to approach it is to do what you have done and bring skylib in via your own WORKSPACE or MODULE.bzlmod file.

@oliverlee
Copy link
Author

I assumed it wasn't necessary given that there is a vendored copy of bazel_skylib and the README states:

This exists so that users of rules_python don't have to install bazel-skylib copied from https://github.com/bazelbuild/bazel-skylib/blob/1.0.3

Maybe it's worth cleaning up the documentation if that statement is no longer valid?

@yin
Copy link

yin commented Jan 19, 2023 via email

@oliverlee
Copy link
Author

No it is not problem for me, thanks for asking :)

Cleaning up the Getting Started guide sounds reasonable but feel free to close if don't think it's worth doing.

@alexeagle
Copy link
Collaborator

Nope this was a legit bug and an accidental regression in the last release. Sorry about that!

Fixed in #1001

@alexeagle
Copy link
Collaborator

@oliverlee where is that README? I'm trying to clean up but I don't see that text in rules_python anywhere.

@oliverlee
Copy link
Author

https://github.com/bazelbuild/rules_python/blob/main/third_party/github.com/bazelbuild/bazel-skylib/README.md

@alexeagle
Copy link
Collaborator

@yin where is "the Getting Started Guide"? Want to make sure I found all the outdated spots.

@yin
Copy link

yin commented Jan 23, 2023

@alexeagle With "Getting Started Guide" I meant https://github.com/bazelbuild/rules_python/blob/main/README.md

I may have been confusing this with another issue I had with the python_rules version in the doc being outdated.

I've got this error, when trying to set up python toolchain on GitLab CI. My test were failing, because the docker image I am using has preinstalled Python 2.7.

When I added the bazel_skylib dependency explicitly, commit: https://gitlab.com/yin2/language/-/commit/dcb25a5b5969de2e578ae8358e4905ec02eb791c

.. I get another error:

ERROR: /root/.cache/bazel/_bazel_root/4755c6ea53a31c010470a9916f866540/external/rules_python/python/pip_install/pip_repository.bzl:175:13: name 'json' is not defined

And this is the CI run: https://gitlab.com/yin2/language/-/jobs/3583021972

@oliverlee
Copy link
Author

It looks like json was introduced in Bazel 4:
https://blog.bazel.build/2021/01/19/bazel-4-0.html#starlark

But your CI runner is using Bazel 3.5.0:
https://gitlab.com/yin2/language/-/jobs/3583021972#L32

I guess rules_python could check the Bazel version with bazel-skylib now that it is a dependency.

@alexeagle
Copy link
Collaborator

We do have a check already (this is exactly why we vendored a bit of skylib to begin with)
https://github.com/bazelbuild/rules_python/blob/main/python/pip_install/repositories.bzl#L118-L123

I guess you don't happen to call pip_install_dependencies somehow, so you didn't have that version check applied.

I don't think there's more to do here - thanks!

@yin
Copy link

yin commented Jan 24, 2023

Can we explain this in the docs?

Following the README.md did not get me to a usable workspace. I don't know, which GitLab CI guide I followed anymore, gcr.io/bazel-public/bazel:latest is the official Bazel 3.5.0 docker image and it was not updated with Bazel 4.0

@alexeagle
Copy link
Collaborator

docker run --rm -it gcr.io/bazel-public/bazel:6.0.0 version gives me 6.0. If there's a missing validation on the minimum Bazel version, we should fix it in code so we don't rely on someone finding it in the docs.

@yin
Copy link

yin commented Jan 25, 2023

@alexeagle Thank you! The correct docker image is listed in bazelbuild's Release Notes and Official Bazel docs.

I have been using the wrong docker image all along: l.gcr.io/google/bazel:latest. This image stopped being released in 2020 and is tagged with version 3.5.0.

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

No branches or pull requests

4 participants