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

feat: support poetry v2 #839

Open
jkowalleck opened this issue Jan 5, 2025 · 14 comments
Open

feat: support poetry v2 #839

jkowalleck opened this issue Jan 5, 2025 · 14 comments
Labels
enhancement New feature or request help wanted Extra attention is needed source: poetry

Comments

@jkowalleck
Copy link
Member

jkowalleck commented Jan 5, 2025

poetry v2 just got released: https://github.com/python-poetry/poetry/releases/tag/2.0.0

add support for it and it's new features, if any

[⤴ this list will be updated continuously based on comments below, until the initial feature was provided eventually]

@jkowalleck
Copy link
Member Author

jkowalleck commented Jan 29, 2025

Note

in case somebody wants to champion this feature, feel free to let us know and organize yourselves in the comments section 📣

@kwaegel
Copy link

kwaegel commented Feb 7, 2025

I've started using cyclonedx-py with Poetry 2.0.1 in requirements mode, and the main issue I've run into so far is not reading metadata from the PEP 621 [project] section.

Initially I was getting a CRITICAL | CDX > 'name' fatal error, but adding a duplicate of the name field in the [tool.poetry] section fixed that (though now Poetry emits a warning about duplicate fields).

(This may be irrelevant if I switch over to using uv for packaging, though.)

@sam5827
Copy link

sam5827 commented Feb 14, 2025

We recently upgraded to Poetry v2 and changed to using the [project] table in the pyproject.toml, but Cyclone DX doesn't seem to support the dependencies defined in that table and they are not included in the SBOM.xml output.

I can see in poetry.py there's only mention of the [tool.poetry] section, so it appears it will only be considering dependencies defined there and won't consider one's in [project].

If that's right, then I would like to see support for Poetry 2 and the PEP621 [project] standards.
Please let me know if I've misunderstood this though!

(I'd consider attempting to contribute if I had a bit of help as well)

@jkowalleck
Copy link
Member Author

jkowalleck commented Feb 15, 2025

i did not look into all details of poetry2's docs.
could you point me to the docs, where they allow project instead of tool.poetry?

BTW: PEP621 is already implemented: https://github.com/CycloneDX/cyclonedx-python/blob/main/cyclonedx_py/_internal/utils/pep621.py
It is just not applied, since poetry went with tool.poetry, in the past.

https://python-poetry.org/docs/managing-dependencies/

Poetry supports specifying main dependencies in the project.dependencies section of your pyproject.toml according to PEP 621. For legacy reasons and to define additional information that are only used by Poetry the tool.poetry.dependencies sections can be used.

@m-erhardt
Copy link

m-erhardt commented Feb 15, 2025

@jkowalleck it's stated in the release notes for poetry 2.0.0

  • Add support for the project section in the pyproject.toml file according to PEP 621 (#9135, #9917).
    [...]
  • Deprecate several fields in the tool.poetry section in favor of the respective fields in the project section in the pyproject.toml file (#9135).

Since 2.0.0 poetry prints a warning if name, description, etc are specified in the tool.poetrysection of pyproject.toml

@armingerten
Copy link

We are also heavily awaiting the support for poetry 2 for cyclonedx-py. However, I have been thinking about the following work-around:

poetry export | cyclonedx-py requirements -

Doesn't this yield the same result as cyclonedx-py poetry (with poetry 2 support)?

@jkowalleck
Copy link
Member Author

jkowalleck commented Feb 17, 2025

poetry export | cyclonedx-py requirements -

Doesn't this yield the same result as cyclonedx-py poetry (with poetry 2 support)?

not at all.
have you tried it?

@jkowalleck
Copy link
Member Author

We are also heavily awaiting the support for poetry 2 for cyclonedx-py

Everyone is awaiting, nobody is contributing - yet.
Feel free to champion this feature, I will be there to assist you.

@armingerten
Copy link

armingerten commented Feb 17, 2025

Doesn't this yield the same result as cyclonedx-py poetry (with poetry 2 support)?

not at all.

Hmm, what's the difference? 🤔

We are also heavily awaiting the support for poetry 2 for cyclonedx-py

Everyone is awaiting, nobody is contributing - yet. Feel free to champion this feature, I will be there to assist you.

Yeah, I get that. I didn't intend to put pressure on anyone with that. I was just showing my interest in this issue 😉

@jkowalleck
Copy link
Member Author

In the meantime, I suggest looking into cyclonedx-py environment - https://cyclonedx-bom-tool.readthedocs.io/en/latest/usage.html#for-python-virtual-environment
It is probably the most true and complete BOM you could get.

@armingerten
Copy link

armingerten commented Feb 17, 2025

Thanks for the hint to cyclonedx-py environment!

So

cyclonedx-py environment "$(poetry env info --executable)" --pyproject ./pyproject.toml

seems to be even superior to

cyclonedx-py poetry

I just noticed that specifying the --pyproject parameter would also yield an error (CRITICAL | CDX > 'name') when using the PEP621 style in your pyproject.toml.

@sealedtx
Copy link

@jkowalleck @armingerten

I just noticed that specifying the --pyproject parameter would also yield an error

Can we simply update priority, take first [project] if present instead of [tool.poetry] here

def pyproject2component(data: Dict[str, Any], *,
ctype: 'ComponentType', fpath: str) -> 'Component':
tool = data.get('tool', {})
if poetry := tool.get('poetry'):
return poetry2component(poetry, ctype=ctype)
if project := data.get('project'):
return project2component(project, ctype=ctype, fpath=fpath)
raise ValueError('Unable to build component from pyproject')

@jkowalleck
Copy link
Member Author

Can we simply update priority, take first [project] if present instead of [tool.poetry] here

unfortunately not. please read this very ticket's (updated) description:

any new pytproject.toml declarations

support for PEP621 - metadata and dependencies
Goal: not either/or, but simultaneously the "old" tool.poetry and the "new" project

Add support for the project section in the pyproject.toml file according to PEP 621

@jkowalleck
Copy link
Member Author

jkowalleck commented Feb 21, 2025

started looking into this.

will provide test setups (lockfiles) for poetry v2 for the existing cases, and see how this turns out.
from there on, i might adjust the ticket's description to reflect needed tasks.

Done:

feature development may start, now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed source: poetry
Projects
None yet
Development

No branches or pull requests

6 participants