- Notifications
You must be signed in to change notification settings - Fork25
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
a72733d
to0b6ddbb
Compare0b6ddbb
tob71e613
CompareOptional 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.
b71e613
to8a8f796
Compareadrobuta approved these changesNov 15, 2024
cdb9eba
intomain 17 checks passed
Uh oh!
There was an error while loading.Please reload this page.
snyk-team-unify commentedNov 15, 2024
🎉 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.
7 tasks
7 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
This means 'logger' is always installed, but 'tester' is only installed if 'my-package' is installed with extra 'test' dependencies, like so:
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