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

main_mypy.runfiles is not a valid Python package name #120

Open
ssmall opened this issue Apr 11, 2024 · 1 comment
Open

main_mypy.runfiles is not a valid Python package name #120

ssmall opened this issue Apr 11, 2024 · 1 comment

Comments

@ssmall
Copy link

ssmall commented Apr 11, 2024

This seems like it could be similar to #15 but I'm opening a new issue because it has nothing to do with protobuf. I have a plain Python application with no external dependencies that only uses rules_python and Bzlmod.

I am consistently getting the error

main_mypy.runfiles is not a valid Python package name

when running bazel test.

My source file is

main.py

def sayHello():
    return f"Hello, world!"

if __name__ == "__main__":
    print(sayHello())

and my BUILD.bazel contains:

py_binary(
    name = "main",
    srcs = ["main.py"],
    visibility = ["//:__subpackages__"],
)

mypy_test(
    name = "main_mypy",
    deps = [
        ":main",
    ],
)

Lines from relevant files:

MODULE.bazel

bazel_dep(
    name = "rules_python",
    version = "0.31.0",
)
bazel_dep(
    name = "rules_python_gazelle_plugin",
    version = "0.31.0",
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = True,
    python_version = "3.12",
)

bazel_dep(
    name = "mypy_integration",
    version = "0.0.0",
)

git_override(
    module_name = "mypy_integration",
    remote = "https://github.com/bazel-contrib/bazel-mypy-integration",
    commit = "c289c0cd30e53b5cc467b601295834dbc400f4b2",
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "mypy_pip",
    python_version = "3.12",
    requirements_lock = "//third_party/python/mypy:requirements_lock.txt",
)
use_repo(pip, "mypy_pip")

.bazelrc

build --@mypy_integration//:mypy=//third_party/python/mypy:mypy

third_party/python/mypy/BUILD.bazel

load("@mypy_pip//:requirements.bzl", "requirement")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements(
    name = "requirements",
    src = "requirements.txt",
    requirements_txt = "requirements_lock.txt",
)

alias(
    name = "mypy",
    actual = requirement("mypy"),
    visibility = ["//visibility:public"],
)
@ssmall
Copy link
Author

ssmall commented Apr 11, 2024

I was able to work around this by adding

build --incompatible_default_to_explicit_init_py

to .bazelrc, which requires me to manually create __init__.py for my Python modules. Not ideal, but workable.

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

1 participant