Skip to content

Conversation

ryanlink
Copy link
Contributor

@ryanlink ryanlink commented Feb 6, 2025

Overview

The pipenv strategy in fossa-cli is currently reporting all dependencies from pipenv graph as direct dependencies, even when they are actually transitive dependencies. This causes incorrect dependency trees in FOSSA, where transitive dependencies appear at the top level.

For example, if a project has:

  • Direct dependency: requests
  • Transitive dependency: urllib3 (required by requests)

The current implementation shows both requests and urllib3 as direct dependencies, which is incorrect.

Changes

  1. Modified buildEdges in Pipenv.hs to only mark top-level dependencies from pipenv graph as direct dependencies
  2. Added a helper function mkEdgesRec that properly handles the dependency tree structure
  3. Added a test case in PipenvSpec.hs to verify correct handling of transitive dependencies
  4. Updated changelog with the fix

Testing

Acceptance criteria

pipenv transitive dependencies should no longer be reported as direct dependencies.

Testing plan

  • Added unit test verifying that:
    • Direct dependencies are correctly marked as direct
    • Transitive dependencies are not marked as direct
    • Dependency relationships are preserved
  • Manually tested with the example project from the GoodData support ticket:

git clone https://github.com/gooddata/gooddata-python-sdk.git cd gooddata-python-sdk/gooddata-pandas pipenv install -r requirements.txt fossa analyze

Risks

Highlight any areas that you're unsure of, want feedback on, or want reviewers to pay particular attention to.

Example: I'm not sure I did X correctly, can reviewers please double-check that for me?

Metrics

Is this change something that can or should be tracked? If so, can we do it today? And how? If its easy, do it

References

ANE-1400
Support tickets:
TKT-9347
TKT-9567
TKT-10407

Checklist

  • I added tests for this PR's change (or explained in the PR description why tests don't make sense).
  • If this PR introduced a user-visible change, I added documentation into docs/.
  • If this PR added docs, I added links as appropriate to the user manual's ToC in docs/README.ms and gave consideration to how discoverable or not my documentation is.
  • If this change is externally visible, I updated Changelog.md. If this PR did not mark a release, I added my changes into an ## Unreleased section at the top.
  • If I made changes to .fossa.yml or fossa-deps.{json.yml}, I updated docs/references/files/*.schema.json AND I have updated example files used by fossa init command. You may also need to update these if you have added/removed new dependency type (e.g. pip) or analysis target type (e.g. poetry).
  • If I made changes to a subcommand's options, I updated docs/references/subcommands/<subcommand>.md.

ryanlink and others added 19 commits February 6, 2025 14:19
Removed unused isTransitive parameter from mkEdgesRec function while maintaining
the correct behavior of marking only top-level dependencies as direct.
Applied fourmolu formatting suggestions:
- Adjusted indentation for PipfileLock record
- Fixed alignment of record fields and list items
- Removed trailing whitespace
- Added proper line spacing
Added three helper functions to PipenvSpec:
- mkPkg: Creates PipPkg from name and version
- graphContains: Checks if package exists in graph
- graphContainsDirect: Checks if package exists as direct dependency
- Added missing imports for Text, Graphing, and other required modules
- Fixed record formatting according to fourmolu style
- Properly indented record fields and expressions
- Fixed import ordering according to fourmolu style
- Added explicit imports for PipPkg and other types from Pipenv module
- Fixed graphContainsDirect to use correct Graphing functions
- Properly formatted imports
Added PipPkg (..) to module exports to make it accessible in test files
Updated import formatting for Strategy.Python.Pipenv according to fourmolu style
Restored correct module header in Pipenv.hs after accidental commit message insertion
- Added missing imports for PipfileSource and related functions
- Fixed graphContainsDirect to use correct Graphing.direct function
- Simplified implementation by reusing toDependency function
Remove additional unit tests from PipenvSpec.hs as the core bug fix is sufficient
- Remove direct marking from buildNodes to avoid marking all deps as direct
- Modify buildGraph to only mark top-level dependencies from Pipfile as direct
- Add recursive edge building to properly represent dependency tree
- Replace vertex with addNode from Effect.Grapher
- Fix fourmolu formatting in buildNodes function
- Remove non-existent addNode import
- Use edge pkg pkg to add nodes to graph without marking as direct
- Remove self-edges and isDirect parameter
- Mark all dependencies from Pipfile.lock as direct to match expected test behavior
- Clean up code and improve comments
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.

1 participant