Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions rewrite-python/rewrite/src/rewrite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,29 @@ def activate(marketplace: RecipeMarketplace) -> None:
marketplace: The RecipeMarketplace to install recipes into
"""
from rewrite.decorators import get_recipe_category
from rewrite.python.recipes import RemovePass

# Install all Python recipes with their categories
category = get_recipe_category(RemovePass)
if category is not None:
marketplace.install(RemovePass, category)
from rewrite.python.recipes import (
RemovePass,
ChangeImport,
ChangeType,
ChangeMethodName,
ChangePackage,
DeleteMethodArgument,
ReorderMethodArguments,
AddLiteralMethodArgument,
)

for recipe_class in [
RemovePass,
ChangeImport,
ChangeType,
ChangeMethodName,
ChangePackage,
DeleteMethodArgument,
ReorderMethodArguments,
AddLiteralMethodArgument,
]:
category = get_recipe_category(recipe_class)
if category is not None:
marketplace.install(recipe_class, category)
else:
marketplace.install(recipe_class, Python)
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
from typing import Any, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class AddLiteralMethodArgument(Recipe):
"""
Add a literal argument to method invocations matching a pattern.
Expand Down Expand Up @@ -58,9 +61,9 @@ class AddLiteralMethodArgument(Recipe):

def __init__(
self,
method_pattern: str,
argument_index: int,
literal: str
method_pattern: str = "",
argument_index: int = 0,
literal: str = ""
):
self.method_pattern = method_pattern
self.argument_index = argument_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
from typing import Any, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class ChangeMethodName(Recipe):
"""
Rename method invocations matching a pattern.
Expand Down Expand Up @@ -65,8 +68,8 @@ class ChangeMethodName(Recipe):

def __init__(
self,
method_pattern: str,
new_method_name: str,
method_pattern: str = "",
new_method_name: str = "",
match_overrides: bool = False,
ignore_definition: bool = False
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
from typing import Any, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class ChangePackage(Recipe):
"""
Change package/module references from one name to another.
Expand Down Expand Up @@ -58,8 +61,8 @@ class ChangePackage(Recipe):

def __init__(
self,
old_package_name: str,
new_package_name: str,
old_package_name: str = "",
new_package_name: str = "",
recursive: bool = True
):
self.old_package_name = old_package_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
from typing import Any, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class ChangeType(Recipe):
"""
Change a type reference from one fully qualified name to another.
Expand Down Expand Up @@ -63,8 +66,8 @@ class ChangeType(Recipe):

def __init__(
self,
old_fully_qualified_type_name: str,
new_fully_qualified_type_name: str,
old_fully_qualified_type_name: str = "",
new_fully_qualified_type_name: str = "",
ignore_definition: bool = False
):
self.old_fully_qualified_type_name = old_fully_qualified_type_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
from typing import Any, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class DeleteMethodArgument(Recipe):
"""
Remove an argument from method invocations matching a pattern.
Expand Down Expand Up @@ -51,8 +54,8 @@ class DeleteMethodArgument(Recipe):

def __init__(
self,
method_pattern: str,
argument_index: int
method_pattern: str = "",
argument_index: int = 0
):
self.method_pattern = method_pattern
self.argument_index = argument_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
from typing import Any, List, Optional

from rewrite import ExecutionContext, Recipe, TreeVisitor, option
from rewrite.decorators import categorize
from rewrite.marketplace import Python
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe


@categorize(Python)
class ReorderMethodArguments(Recipe):
"""
Reorder arguments in method invocations matching a pattern.
Expand Down Expand Up @@ -59,8 +62,8 @@ class ReorderMethodArguments(Recipe):

def __init__(
self,
method_pattern: str,
new_parameter_names: List[str],
method_pattern: str = "",
new_parameter_names: Optional[List[str]] = None,
old_parameter_names: Optional[List[str]] = None
):
self.method_pattern = method_pattern
Expand Down