Package org.openrewrite.python.trait
Class RequirementsFile
java.lang.Object
org.openrewrite.python.trait.RequirementsFile
- All Implemented Interfaces:
PythonDependencyFile,org.openrewrite.trait.Trait<org.openrewrite.SourceFile>
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionwithAddedDependencies(Map<String, String> additions, @Nullable String scope, @Nullable String groupName) Add dependencies to the specified scope.withChangedDependency(String oldPackageName, String newPackageName, @Nullable String newVersion, @Nullable String scope, @Nullable String groupName) Change a dependency to a different package.withDependencySearchMarkers(Map<String, String> packageMessages, @Nullable String scope, @Nullable String groupName, org.openrewrite.ExecutionContext ctx) Add search result markers for vulnerable dependencies.withPinnedTransitiveDependencies(Map<String, String> pins, @Nullable String scope, @Nullable String groupName) Pin transitive dependencies using the strategy appropriate for this file's package manager.withRemovedDependencies(Set<String> packageNames, @Nullable String scope, @Nullable String groupName) Remove dependencies from the specified scope.withUpgradedVersions(Map<String, String> upgrades, @Nullable String scope, @Nullable String groupName) Upgrade version constraints for dependencies in the specified scope.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openrewrite.python.trait.PythonDependencyFile
getMarkerMethods inherited from interface org.openrewrite.trait.Trait
getCursor, getTree
-
Constructor Details
-
RequirementsFile
public RequirementsFile()
-
-
Method Details
-
withUpgradedVersions
public RequirementsFile withUpgradedVersions(Map<String, String> upgrades, @Nullable String scope, @Nullable String groupName) Description copied from interface:PythonDependencyFileUpgrade version constraints for dependencies in the specified scope.- Specified by:
withUpgradedVersionsin interfacePythonDependencyFile- Parameters:
upgrades- package name → new versionscope- the scope to upgrade in, ornullto upgrade in all scopesgroupName- required for"project.optional-dependencies"or"dependency-groups"
-
withAddedDependencies
public RequirementsFile withAddedDependencies(Map<String, String> additions, @Nullable String scope, @Nullable String groupName) Description copied from interface:PythonDependencyFileAdd dependencies to the specified scope.- Specified by:
withAddedDependenciesin interfacePythonDependencyFile- Parameters:
additions- package name → version constraint (e.g."2.0"or">=2.0")scope- the TOML scope (e.g."project.optional-dependencies","dependency-groups"), ornullfor the default ([project].dependencies)groupName- required when scope is"project.optional-dependencies"or"dependency-groups", otherwisenull
-
withRemovedDependencies
public RequirementsFile withRemovedDependencies(Set<String> packageNames, @Nullable String scope, @Nullable String groupName) Description copied from interface:PythonDependencyFileRemove dependencies from the specified scope.- Specified by:
withRemovedDependenciesin interfacePythonDependencyFile- Parameters:
packageNames- package names to removescope- the scope to remove from, ornullto remove from all scopesgroupName- required for"project.optional-dependencies"or"dependency-groups"
-
withChangedDependency
public RequirementsFile withChangedDependency(String oldPackageName, String newPackageName, @Nullable String newVersion, @Nullable String scope, @Nullable String groupName) Description copied from interface:PythonDependencyFileChange a dependency to a different package.- Specified by:
withChangedDependencyin interfacePythonDependencyFile- Parameters:
oldPackageName- the current package namenewPackageName- the new package namenewVersion- optional new version constraint, ornullto preserve the originalscope- the scope to change in, ornullto change in all scopesgroupName- required for"project.optional-dependencies"or"dependency-groups"
-
withPinnedTransitiveDependencies
public RequirementsFile withPinnedTransitiveDependencies(Map<String, String> pins, @Nullable String scope, @Nullable String groupName) Description copied from interface:PythonDependencyFilePin transitive dependencies using the strategy appropriate for this file's package manager. For pyproject.toml: uv uses[tool.uv].constraint-dependencies, PDM uses[tool.pdm.overrides], and other managers add a direct dependency. For requirements.txt: appends the dependency.- Specified by:
withPinnedTransitiveDependenciesin interfacePythonDependencyFile- Parameters:
pins- package name → version constraintscope- the scope to look for transitive dependencies in, ornullto search all scopesgroupName- required for"project.optional-dependencies"or"dependency-groups"
-
withDependencySearchMarkers
public RequirementsFile withDependencySearchMarkers(Map<String, String> packageMessages, @Nullable String scope, @Nullable String groupName, org.openrewrite.ExecutionContext ctx) Description copied from interface:PythonDependencyFileAdd search result markers for vulnerable dependencies.- Specified by:
withDependencySearchMarkersin interfacePythonDependencyFile- Parameters:
packageMessages- package name → vulnerability description messagescope- the scope to search in, ornullto search all scopesgroupName- required for"project.optional-dependencies"or"dependency-groups"
-