Skip to content

Implement --exclude-dependencies#488

Merged
gaborbernat merged 3 commits intotox-dev:mainfrom
kemzeb:feat/exclude-dependencies
Jul 10, 2025
Merged

Implement --exclude-dependencies#488
gaborbernat merged 3 commits intotox-dev:mainfrom
kemzeb:feat/exclude-dependencies

Conversation

@kemzeb
Copy link
Copy Markdown
Collaborator

@kemzeb kemzeb commented Jul 5, 2025

Resolves #453.

Much harder than I expected to implement, but I think my logic and implementation checks out. The algorithm is the following:

  • Take the exclude set from CLI input and resolve it to actual nodes in the graph
  • Determine all possible candidates for exclusion by performing DFS
    • So we add the direct and transitive dependencies of the exclude nodes we gathered in Step 1 into a candidates set, but we aren't sure yet if they should be excluded since a non-excluded node maybe using it. This is the reason why we have more steps below
  • Create a reversed graph so that we know all the nodes that depend on a specific node
  • Iterate over candidates, counting the number of dependents for each node using the reversed graph
  • Now iterate over the explicitly-excluded nodes that we created in Step 1, where for each node:
    • Add it to the new excluded set
    • Iterate over their children. For each child, get the dependent count of that child and decrement it by 1
      • If the count equals 0, we haven't added it to the new set, and it isn't apart of the original resolved set created in Step 1, this child is a candidate for exclusion so let's add it (and in effect, also add their applicable children)
      • If this specific branch is never reached, it means that their is a non-excluded node that has an outgoing edge to child. We should not remove it
  • Return the new excluded set, which will contain both the explicitly-excluded nodes and the dependency nodes associated to them

@kemzeb kemzeb marked this pull request as draft July 5, 2025 18:34
@kemzeb kemzeb marked this pull request as ready for review July 5, 2025 18:37
@kemzeb kemzeb requested a review from gaborbernat July 5, 2025 18:38
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

@gaborbernat gaborbernat merged commit daa759d into tox-dev:main Jul 10, 2025
11 checks passed
@kemzeb kemzeb deleted the feat/exclude-dependencies branch July 11, 2025 03:47
@Shread1234
Copy link
Copy Markdown

Sorry to resurrect a merged PR, but I just want to say thank you! I've wanted this for a long time, but never had the drive to open a PR myself. Great work! 😄

@kemzeb
Copy link
Copy Markdown
Collaborator Author

kemzeb commented Jul 24, 2025

No problem!

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.

Implement --exclude-dependencies to make --exclude exclude a package's dependencies

3 participants