pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.26k stars 626 forks source link

Using poetry as a build tool with python_distribution does not work #21276

Open georgieprojie opened 1 month ago

georgieprojie commented 1 month ago

I want to generate a whl file from a package i wrote. to do that i use the python_distribution target. my dependencies contain a resource, which a pyproject.toml file is it's source.

as described in the docs, Running pants package {dir}:{name of the python_distribution target} will cause Pants to inspect the [build-system] table in pyproject.toml, install the requirements specified in that table's requires key, and then execute the entry point specified in the build-backend key to build an sdist and a wheel, just as PEP 517 requires.

my pyproject.toml contains:

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

until here everything is great, only that when i actually run pants package, i get an error: ValueError: /tmp/{some sandbox dir}/chroot/{mytargetname} does not contain any element.

after some research and debugging poetry itself with pants, i found out that the problem is that the pyproject.toml is copied to the tmp directory, and when poetry api starts trying to build the package, it thinks that the root directory (where the packages should actually be) is in the tmp sandbox dir, which are not (maybe you should copy the package files into the sandbox dir?)

I would really appreciate if you could validate me and check this bug, and maybe upload an example of a project that generates a whl package with poetry as it's backend?

im using pants version 2.21.0 on a wsl platform

thanks in advance!

georgieprojie commented 1 month ago

also, i would actually like to know if any backend ever was tested and was specified in the pyproject.toml, and if so, i would really appreciate an example :)

cdallosta commented 1 month ago

I have experienced the same behavior

huonw commented 1 month ago

Sorry for the trouble.

To help debug this, a minimal reproducing example will make sure we're all looking at the same problem. Can you construct one? I'd hope for a project with only a handful of files, where we can run pants package and see the error you've encountered.

x0f0 commented 2 weeks ago
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
resources(name="pyproject", sources=["pyproject.toml"])

python_distribution(
    name="dist",
    dependencies=[
        ":pyproject",
        "./pkg",
    ],
    provides=python_artifact(
        name="my-pkg",
        version="1.0.0",
    ),
)

Works fine for me on 2.21.