8000 Trying to import pip packages in submodule: Invalid user-provided repo name · Issue #1256 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content
Trying to import pip packages in submodule: Invalid user-provided repo name #1256
Closed
@elalo-deloitte

Description

@elalo-deloitte

Trying to build my project and running into an issue.

My folder structure is as follows.

src (sub module)
  |
  - BUILD
  - __main__.py
  - more sub modules...
cli.py
BUILD
MODULE.bazel
WORKSPACE

Pretty much all of my bazel files follow the examples in the docs.

Here's my WORKSPACE

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

http_archive(
    name = "rules_python",
    sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539",
    strip_prefix = "rules_python-0.22.0",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz",
)

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

py_repositories()

MODULE.bazel

bazel_dep(name = "rules_python", version = "0.22.0")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

pip.parse(
    name = "my_deps",
    requirements_lock = "//:requirements.txt",
)

use_repo(pip, "my_deps")

# (Optional) Register a specific python toolchain instead of using the host version
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    name = "python3_10",
    python_version = "3.10"
)
use_repo(python, "python3_10_toolchains")

register_toolchains(
    "@python3_10_toolchains//:all",
)

Root BUILD

Note: If there's an easy way to load all pip packages here then I would prefer that. I tried various examples and couldn't get it to work.

py_binary(
    name = "cli",
    srcs = ["cli.py"],
    deps = [
        "//src:src",
    ]
)

src/BUILD

load("@my_deps//:requirements.bzl", "requirement")

py_library(
    name = "src",
    srcs = glob(["**/*.py"]),
    visibility = ["//visibility:public"],
    deps = [
        ":cli",
        requirement("docker"),
    ]
)

If I run bazelisk build //:cli I get the following error.

ERROR: Traceback (most recent call last):
        File "C:/users/evlalo/_bazel_evlalo/uvypka5x/external/rules_python~0.22.0/python/extensions/pip.bzl", line 43, column 28, in _pip_impl
                whl_library(
Error in repository_rule: invalid user-provided repo name 'my_deps_ ■a<?>l<?>t<?>g<?>r<?>a<?>p<?>h<?>': valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter
ERROR: Analysis of target '//:cli' failed; build aborted: error evaluating module extension pip in @rules_python~0.22.0//python/extensions:pip.bzl
INFO: Elapsed time: 5.966s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (59 packages loaded, 229 targets configured)
    currently loading: src
ERROR: Build failed. Not running target

The repo name and pip.parse config is exactly as it's laid out in the docs.

If I remove the pip dependencies from my src/BUILD my code will compile, but then I don't have my pip dependencies.

bazelisk version

Bazelisk version: v1.17.0
Build label: 6.2.1

Running on windows 10.
Python 3.10


Any help would be greatly appreciated.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Can Close?Will close in 30 days if there is no new activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0