theoremlp / rules_mypy

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

Using custom mypy.ini #16

Closed jimmyt857 closed 3 months ago

jimmyt857 commented 3 months ago

According to the README, using my own mypy.ini file can be done as follows:

mypy_aspect = mypy(
    mypy_ini = "//:mypy.ini",
    types = types,
)

However, when trying this Bazel complained with this message:

ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/190ed845c43fd8fe2a479fa4f23ed0f1/external/rules_mypy~/BUILD.bazel: no such target '@@rules_mypy~//:mypy.ini': target 'mypy.ini' not declared in package '' defined by /home/ubuntu/.cache/bazel/_bazel_ubuntu/190ed845c43fd8fe2a479fa4f23ed0f1/external/rules_mypy~/BUILD.bazel
ERROR: /home/ubuntu/bazel-exploration/examples/basic_python/BUILD:4:10: every rule of type py_binary implicitly depends upon the target '@@rules_mypy~//:mypy.ini', but this target could not be found because of: no such target '@@rules_mypy~//:mypy.ini': target 'mypy.ini' not declared in package '' defined by /home/ubuntu/.cache/bazel/_bazel_ubuntu/190ed845c43fd8fe2a479fa4f23ed0f1/external/rules_mypy~/BUILD.bazel
Target //examples/basic_python:a up-to-date:
  bazel-bin/examples/basic_python/a
  bazel-bin/examples/basic_python/a.venv.pth

Based on the message, it seems that the //:mypy.ini string is being evaluated from the context of rules_mypy instead of my repo. Indeed, I was able to resolve the error by using the following syntax instead:

mypy_aspect = mypy(
    mypy_ini = Label("//:mypy.ini"),
    types = types,
)

The Label() call seems to make things resolve properly. Ideally this can be solved internally, but if not the README could be updated to suggest this fix.

mark-thm commented 3 months ago

Thanks for flagging, I'll update the readme, but the solution here is generally to use an absolute label, something like @@//:mypy.ini.

mark-thm commented 3 months ago

Readme updated.