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

fix(python): skip dev group's deps for poetry #8106

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Dec 16, 2024

Description

This PR skips dependencies from the dev group for the poetry.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review December 16, 2024 10:50
@nikpivkin
Copy link
Contributor Author

nikpivkin commented Dec 17, 2024

poetry does not yet support PEP 735, so for now we can just exclude the dev group without resolving dependencies from other groups:

[dependency-groups]
test = ["pytest<8", "coverage"]
typing = ["mypy==1.7.1", "types-requests"]
lint = ["black", "flake8"]
dev = [{include-group = "test"}, {include-group = "typing"}, {include-group = "lint"}]

python-poetry/poetry#9751

Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left 2 small comments

pkg/fanal/analyzer/language/python/poetry/poetry.go Outdated Show resolved Hide resolved
pkg/fanal/analyzer/language/python/poetry/poetry.go Outdated Show resolved Hide resolved
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cc. @knqyf263

func (d *dependencies) UnmarshalTOML(data any) error {
m, ok := data.(map[string]any)
if !ok {
return fmt.Errorf("dependencies must be map, but got: %T", data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for consistency and stacktrace

Suggested change
return fmt.Errorf("dependencies must be map, but got: %T", data)
return xerrors.Errorf("dependencies must be map, but got: %T", data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed d1e2450

return nil
}

func (a poetryAnalyzer) parsePyProject(fsys fs.FS, path string) (map[string]any, error) {
func filterProdPackages(project pyproject.PyProject, app *types.Application) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should flag the Dev field instead of filtering for --include-dev-deps, but if you want to keep the original behavior in this PR, we can add the change in a separate PR.

Copy link
Contributor

@DmitriyLewen DmitriyLewen Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knqyf263 as i wrote in #8080 (comment) - are you sure that we want to add dev deps under Dev field?
Previously we only did this upon request from users.

I have yet to meet a python user who needs to scan for dev dependencies

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It sounds reasonable, but we should add a new column showing if --include-dev-deps is supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the implementation cost is not so different, it's better to mark dev dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open another PR for this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(python): Trivy doesn't skip dev deps for some versions of poetry
3 participants