Skip to content

Poetry project using project.dependencies in pyproject.toml or using no dependencies: project: Error: key "packages" not found in dictionary` #212

@sin-ack

Description

@sin-ack

Environment info

Bazel version: 9.0.0rc3
rules_python: 1.6.3
rules_pycross: 0.8.1

Description

I just created a Poetry project with poetry init and integrated it with rules_pycross right away. However, because I haven't started working on it, it doesn't have any dependencies yet. As a result, it appears that both raw_lock.json and lock.json in the generated repository omit the packages key, and I get the following error:

ERROR: /home/agni/.cache/bazel/_bazel_agni/72d70f606e4bf63ec51519992d448765/external/rules_pycross+/pycross/private/package_repo.bzl:198:20: An error occurred during the fetch of repository 'rules_pycross++lock_repos+project_requirements':
   Traceback (most recent call last):
        File "/home/agni/.cache/bazel/_bazel_agni/72d70f606e4bf63ec51519992d448765/external/rules_pycross+/pycross/private/package_repo.bzl", line 198, column 20, in _package_repo_impl
                packages = lock["packages"].values()
Error: key "packages" not found in dictionary

Later, I added a dependency using poetry add pyyaml, but kept getting the same error. Recent versions of Poetry seem to be using the project.dependencies section of pyproject.toml, with this syntax:

[project]
# ...
dependencies = [
    "pyyaml (>=6.0.3,<7.0.0)"
]

I changed it to be a tool.poetry.dependencies section again, and this time rules_pycross worked.

I think there's one bug and one missing feature here:

  • Fix handling of zero-dependency packages.
  • Handle project.dependencies in pyproject.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions