theoremlp / rules_mypy

a Bazel mypy aspect
Apache License 2.0
18 stars 6 forks source link

starting with rules_python 0.39.0, ability to setup mypy version as a requirement from pip hub is broken #43

Closed vadikmironov closed 1 week ago

vadikmironov commented 2 weeks ago

First of all, huge thank you to both @keith and @mark-thm for version 0.14.0 of rules_mypy which solves python binary/library imports very nicely indeed. However, the setup that nicely worked lasted only until the release of rules_python 0.39.0. With the configuration identical to the one described in rules_mypy documentation following the upgrade to 0.39.0 bazel started to fail with the following:

Starting local Bazel server and connecting to it...
ERROR: /home/user/.cache/bazel/_bazel_user/a219d8d8cea354fef6c5daef622e65cc/external/rules_python~/python/private/pypi/extension.bzl:491:21: Traceback (most recent call last):
        File "/home/user/.cache/bazel/_bazel_user/a219d8d8cea354fef6c5daef622e65cc/external/rules_python~/python/private/pypi/extension.bzl", line 654, column 25, in _pip_impl
                mods = parse_modules(module_ctx)
        File "/home/user/.cache/bazel/_bazel_user/a219d8d8cea354fef6c5daef622e65cc/external/rules_python~/python/private/pypi/extension.bzl", line 491, column 21, in parse_modules
                fail((
Error in fail: Duplicate cross-module pip hub named 'pip_deps': pip hub names must be unique across modules. First defined by module '', second attempted by module 'protobuf'
ERROR: Analysis of aspects '[//build/python/mypy:aspect.bzl%mypy_aspect] with parameters {} on //modules/test_binary:test_binary_bin' failed; build aborted: error evaluating module extension pip in @@rules_python~//python/extensions:pip.bzl

aspect.bzl content is exactly as per rules_mypy docs. rules_python up to 0.38.0 works perfectly fine. Here is the changelog which to my untrained eye does not contain anything suspicious: https://github.com/bazelbuild/rules_python/compare/0.38.0...0.39.0

Let me know if this does not look like rules_mypy issue and shall be posted to rules_python instead.

keith commented 1 week ago

This isn't a rules_mypy error, this is coming from your module:

Error in fail: Duplicate cross-module pip hub named 'pip_deps': pip hub names must be unique across modules. First defined by module '', second attempted by module 'protobuf'

I believe the empty string here is your root repo, and the other is coming from protobuf. You can fix by renaming pip_deps in your project's MODULE.bazel (I'm not sure if protobuf has been fixed for this). Otherwise I would report to rules_python. I assume it's because of this change: https://github.com/bazelbuild/rules_python//commit/38b5ac068c83f382f98e336dbd7390a66e44ae33 but I'm not sure if it was intentional or not

vadikmironov commented 1 week ago

Thanks a lot! Protobuf master still contains this particular name: https://github.com/protocolbuffers/protobuf/blob/main/MODULE.bazel#L72 and it all makes sense now. I initially was confused by the fact that switching off rules_mypy was hiding the problem, but now it's clearer as to why.