Class RequirementsFile

java.lang.Object
org.openrewrite.python.trait.RequirementsFile
All Implemented Interfaces:
PythonDependencyFile, org.openrewrite.trait.Trait<org.openrewrite.SourceFile>

public class RequirementsFile extends Object implements PythonDependencyFile
  • 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: PythonDependencyFile
      Upgrade version constraints for dependencies in the specified scope.
      Specified by:
      withUpgradedVersions in interface PythonDependencyFile
      Parameters:
      upgrades - package name → new version
      scope - the scope to upgrade in, or null to upgrade in all scopes
      groupName - 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: PythonDependencyFile
      Add dependencies to the specified scope.
      Specified by:
      withAddedDependencies in interface PythonDependencyFile
      Parameters:
      additions - package name → version constraint (e.g. "2.0" or ">=2.0")
      scope - the TOML scope (e.g. "project.optional-dependencies", "dependency-groups"), or null for the default ([project].dependencies)
      groupName - required when scope is "project.optional-dependencies" or "dependency-groups", otherwise null
    • withRemovedDependencies

      public RequirementsFile withRemovedDependencies(Set<String> packageNames, @Nullable String scope, @Nullable String groupName)
      Description copied from interface: PythonDependencyFile
      Remove dependencies from the specified scope.
      Specified by:
      withRemovedDependencies in interface PythonDependencyFile
      Parameters:
      packageNames - package names to remove
      scope - the scope to remove from, or null to remove from all scopes
      groupName - 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: PythonDependencyFile
      Change a dependency to a different package.
      Specified by:
      withChangedDependency in interface PythonDependencyFile
      Parameters:
      oldPackageName - the current package name
      newPackageName - the new package name
      newVersion - optional new version constraint, or null to preserve the original
      scope - the scope to change in, or null to change in all scopes
      groupName - 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: PythonDependencyFile
      Pin 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:
      withPinnedTransitiveDependencies in interface PythonDependencyFile
      Parameters:
      pins - package name → version constraint
      scope - the scope to look for transitive dependencies in, or null to search all scopes
      groupName - 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: PythonDependencyFile
      Add search result markers for vulnerable dependencies.
      Specified by:
      withDependencySearchMarkers in interface PythonDependencyFile
      Parameters:
      packageMessages - package name → vulnerability description message
      scope - the scope to search in, or null to search all scopes
      groupName - required for "project.optional-dependencies" or "dependency-groups"