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

[Bug]: aspect_rules_py is incompatible with rules_poetry #338

Closed
luangong opened this issue May 1, 2024 · 4 comments
Closed

[Bug]: aspect_rules_py is incompatible with rules_poetry #338

luangong opened this issue May 1, 2024 · 4 comments
Labels
bug Something isn't working untriaged Requires traige

Comments

@luangong
Copy link

luangong commented May 1, 2024

What happened?

The py_library, py_binary, and py_test rules don’t work with rules_poetry. Packages installed by poetry.parse() can’t be included as dependencies of a py_library, py_binary, or py_test target.

Version

  • Development (host) and target OS/architectures: macOS on an Apple silicon Mac
  • Output of bazel --version: bazel 7.1.1
  • Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: aspect_rules_py 0.7.3
  • Language(s) and/or frameworks involved: Python, Poetry

How to reproduce

Given the following minimal example:

# MODULE.bazel
module(name = "poetry_demo", version = "0.1.0")

bazel_dep(name = "aspect_rules_py", version = "0.7.3")
bazel_dep(name = "rules_python", version = "0.31.0")

# Register a hermetic Python toolchain rather than rely on a locally-installed
# interpreter.
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = True,
    is_default = True,
    python_version = "3.11",
)
use_repo(python, "python_3_11")

# https://registry.bazel.build/modules/rules_poetry
bazel_dep(name = "rules_poetry", version = "0.3.4")

poetry = use_extension("@rules_poetry//python:extensions.bzl", "poetry")
poetry.parse(
    name = "poetry",
    lock = "//:poetry.lock",
)
use_repo(poetry, "poetry")
# BUILD.bazel
load("@aspect_rules_py//py:defs.bzl", "py_binary")

py_binary(
    name = "main",
    srcs = ["main.py"],
    deps = [
        "@poetry//:absl-py",
    ],
)
# pyproject.toml
[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
authors = []
description = "Bazel Python example using Poetry"
package-mode = false

[tool.poetry.dependencies]
python = "~3.11"
absl-py = "^2.1.0"
# main.py
from absl import app

def main(argv):
    print('Hello, Python and Poetry!')
    return 0

if __name__ == '__main__':
    app.run(main)

The build fails with the following error message:

ERROR: poetry-demo/BUILD.bazel:3:10: in deps attribute of py_binary rule //:main:
'@@rules_poetry~~poetry~poetry//:absl-py' does not have mandatory providers:
'PyInfo' or 'PyVirtualInfo'. Since this rule was created by the macro 'py_binary',
the error might have been caused by the macro implementation

However, aspect_rules_py works with pip.parse, and rules_python works with both pip.parse and poetry.parse. Here is the compatibility table:

Extension Method rules_python aspect_rules_py
pip.parse
poetry.parse
@luangong luangong added the bug Something isn't working label May 1, 2024
@github-actions github-actions bot added the untriaged Requires traige label May 1, 2024
@luangong luangong changed the title [Bug]: py_library, py_binary, py_test are not compatible with rules_poetry [Bug]: aspect_rules_py is incompatible with rules_poetry May 1, 2024
@luangong
Copy link
Author

luangong commented May 1, 2024

It seems that the issue is caused by #311. I have to downgrade aspect_rules_py to 0.7.1 to work around this.

@mattem
Copy link
Collaborator

mattem commented May 1, 2024

Alternatively, open an issue with rules_poetry to use the provider loaded from rules_python, rather than native as it'll hit up against this issue with other uses of PyInfo.

@mattem
Copy link
Collaborator

mattem commented May 1, 2024

As a data point, rules_pycross did the same thing here, jvolkman/rules_pycross#90

@oxidase
Copy link

oxidase commented Jun 1, 2024

I suggest to close it here as it relates to bazelbuild/rules_python#1069 (comment)

Will fix in the rules repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged Requires traige
Projects
None yet
Development

No branches or pull requests

3 participants