Module has dependency
org.openrewrite.python.search.ModuleHasDependencyArtifactorg.openrewrite:rewrite-pythonSearches for Python projects that have a dependency matching the specified package name. Places a SearchResult marker on all sources within a project with a matching dependency. A source belongs to the dependency manifest (pyproject.toml, Pipfile, setup.cfg, setup.py or requirements.txt) in its nearest enclosing directory. This recipe is intended to be used as a precondition for other recipes. For example this could be used to limit the application of a migration to only projects that use a specific version of a library. If the search result you want is instead just the dependency entry in the manifest, use the DependencyInsight recipe instead.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
settings.gradle.kts
pluginManagement {
repositories {
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.python.search.ModuleHasDependency")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite:rewrite-python:8.93.8")
}
Then run
./gradlew rewriteRunThis recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.search.ModuleHasDependency --recipe-option "packageNamePattern=django*"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-python:RELEASEOptions
| Name | Type | Description |
|---|---|---|
packageNamePatternrequired | String | A glob pattern to match Python package names (PEP 503 normalized). Use * as a wildcard.e.g. django* |
version | String | Match only dependencies with the specified resolved version. Node-style version selectors may be used. When a dependency is not resolved, only an exact == pin in its constraint is considered. All versions are searched by default.e.g. 4.2.x |
onlyDirect | Boolean | If enabled, transitive dependencies will not be considered. All dependencies are searched by default. e.g. true |
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats