pantsbuild / pants

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

Generated wheel name is wrong when using namespace packages #18265

Closed RLC92 closed 1 year ago

RLC92 commented 1 year ago

Describe the bug

In a project project_a with structure: `src/namespace_a/namespace_b/source_code.py'

The command

./pants package :dist builds a whl in dist named dist/namespace_a.namespace_b-0.0.0-py310-none-any.whl rather than a wheel file named dist/project_a-2.3.0-py310-none-any.whl.

Problems:

1) It seems impossible to set the final wheel name using any name string in the pyproject.toml, pants.toml, or BUILD files. 2) Version is always 0.0.0, no matter what the version is specified in the python_artifact, pyproject.toml, etc.

Pants version Which version of Pants are you using?

I tried 2.14.1 bit am currently on 2.16.0.dev5

OS Are you encountering the bug on MacOS, Linux, or both?

WSL2 Ubuntu 22.04.01 LTS on Windows 11 22H2 (OS Build 22621.1194)

Additional info Add any other information about the problem here, such as attachments or links to gists, if relevant.

Sanitized python_distrubtion entry:

python_distribution(
    name="dist",
    dependencies=[
        "src/namespace_a/namespace_b:lib",
        ":poetry",
    ],
    wheel_config_settings={"--global-option": ["--python-tag", "py310"]},
    generate_setup=False,
    skip_twine=True,
    sdist=False,
    wheel=True,
    provides=python_artifact(name="project_a", version="2.3.0"),
)
benjyw commented 1 year ago

Since you have generate_setup=False, what metadata are you using to build the wheel? E.g., handwritten setup.py, setup.cfg, pyproject.toml etc

RLC92 commented 1 year ago

The metadata comes from a pyproject.toml created with poetry. The poetry build command works as expected.

RLC92 commented 1 year ago

That was just enough of a hint to put me onto the solution, I don't think this is a bug: resource(name="poetry", source="pyproject.toml") works but poetry_requirements(name="poetry") (which is what tailor created) does not.

I believe we can close this as this fixes both issues, although I'm still uncertain of the difference somewhat.

benjyw commented 1 year ago

Ah yes, sorry this was unclear. poetry_requirements is how you describe 3rdparty deps originating from a project.toml. But if a project.toml (the same one or another one) also contains instructions for building your own 1stparty wheel then it has to be made available as a resource to the python_distribution.

This modeling was inspired by the requirements.txr/setup.py world.

It could be nice for tailor to detect this situation in pyproject.toml and do the right thing.