Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: optional python dependencies#614

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gitphill merged 1 commit intomainfromfix/optional-python-dependencies
Nov 15, 2024

Conversation

gitphill
Copy link
Contributor

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

Optional Python dependencies are being over connected.

When building Python dep-graphs the current algorithm does not consider whether a transitive should be traversed based on 'extra' definitions.

When a Python dependency uses extras, this means that dependency is optional and will only be installed when the installer asks.

For example if 'my-package' has the following METADATA snippet:

Requires-Dist: logger>=1.0Provides-Extra: testRequires-Dist: tester>=0.5.0; extra == 'test'

This means 'logger' is always installed, but 'tester' is only installed if 'my-package' is installed with extra 'test' dependencies, like so:

my-package[test]==1.2.3

The current algorithm sometimes gets away with this lack of accuracy because if the dependency is not used at all the the METADATA file doesn't even exist and we don't attach any node to the graph. However in many cases what's optional in one transitive line is not in another and this can mean the METADATA file does exists. This results in the current algorithm accidentally associating potentially large sub-graphs to transitive lines that should be terminated when extras are not being used.

The first change here introduces code that firstly parses out these extra definitions in both requirements.txt and METADATA files. Then also parsers that pick out the Provides-Extra and Requires-Dist extra environment markers.

The second change adapts the pip dep-graph builder to take into account extra properties to decide whether a dependency should be traversed or not.

Screenshots

Screenshot 2024-11-14 at 15 11 39

@gitphillgitphillforce-pushed thefix/optional-python-dependencies branch froma72733d to0b6ddbbCompareNovember 14, 2024 15:13
@gitphillgitphill marked this pull request as ready for reviewNovember 14, 2024 15:15
@gitphillgitphill requested a review froma team as acode ownerNovember 14, 2024 15:15
@gitphillgitphill self-assigned thisNov 14, 2024
@gitphillgitphillforce-pushed thefix/optional-python-dependencies branch from0b6ddbb tob71e613CompareNovember 14, 2024 15:21
Optional Python dependencies are being over connected.When building Python dep-graphs the current algorithm does not considerwhether a transitive should be traversed based on 'extra' definitions.When a Python dependency uses extras, this means that dependency isoptional and will only be installed when the installer asks.For example if 'my-package' has the following METADATA snippet:```Requires-Dist: logger>=1.0Provides-Extra: testRequires-Dist: tester>=0.5.0; extra == 'test'```This means 'logger' is always installed, but 'tester' is only installedif 'my-package' is installed with extra 'test' dependencies, like so:```my-package[test]==1.2.3```The current algorithm sometimes gets away with this lack of accuracybecause the dependency is skipped if the METADATA file doesn't evenexist. However in many cases what's optional in one transitive line isnot in another and this can mean the METADATA file does exists. Thisresults in the current algorithm accidentally associating potentiallylarge sub-graphs to transitive lines that should be terminated whenextras are not being used.The first change here introduces code that firstly parses out theseextra definitions in both requirements.txt and METADATA files. Then alsoparsers that pick out the Provides-Extra and Requires-Dist extraenvironment markers.The second change adapts the pip dep-graph builder to take into accountextra properties to decide whether a dependency should be traversed ornot.
@gitphillgitphillforce-pushed thefix/optional-python-dependencies branch fromb71e613 to8a8f796CompareNovember 14, 2024 15:52
@gitphillgitphill merged commitcdb9eba intomainNov 15, 2024
17 checks passed
@gitphillgitphill deleted the fix/optional-python-dependencies branchNovember 15, 2024 11:54
@snyk-team-unify
Copy link

🎉 This PR is included in version 6.13.15 🎉

The release is available on:

Yoursemantic-release bot 📦🚀

gitphill added a commit to snyk/cli that referenced this pull requestNov 15, 2024
Seesnyk/snyk-docker-plugin#614Fixing a bug in snyk-docker-plugin so that optional dependencies areproperly connected in the dep-graph.This could mean that 'snyk container monitor' commands that previouslytimed out or errored may now start working. The fix reduces unecessary(optional) paths in the dep-graph and so reduce the work Snyk needs todo when scanning for vulnerabilities.
gitphill added a commit to snyk/cli that referenced this pull requestNov 15, 2024
Seesnyk/snyk-docker-plugin#614Fixing a bug in snyk-docker-plugin so that optional dependencies areproperly connected in the dep-graph.This could mean that 'snyk container monitor' commands that previouslytimed out or errored may now start working. The fix reducesunnecessary (optional) paths in the dep-graph and so reduce the workSnyk needs to do when scanning for vulnerabilities.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@adrobutaadrobutaadrobuta approved these changes

Assignees

@gitphillgitphill

Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@gitphill@snyk-team-unify@adrobuta

[8]ページ先頭

©2009-2025 Movatter.jp