diff --git a/rewrite-python/rewrite/src/rewrite/__init__.py b/rewrite-python/rewrite/src/rewrite/__init__.py index e5e65265491..7526a49e72c 100644 --- a/rewrite-python/rewrite/src/rewrite/__init__.py +++ b/rewrite-python/rewrite/src/rewrite/__init__.py @@ -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) diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/add_literal_method_argument.py b/rewrite-python/rewrite/src/rewrite/python/recipes/add_literal_method_argument.py index 6bc641d976d..ab6e49c760b 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/add_literal_method_argument.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/add_literal_method_argument.py @@ -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. @@ -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 diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/change_method_name.py b/rewrite-python/rewrite/src/rewrite/python/recipes/change_method_name.py index 8e8f7d484f0..59571c40e1f 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/change_method_name.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/change_method_name.py @@ -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. @@ -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 ): diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/change_package.py b/rewrite-python/rewrite/src/rewrite/python/recipes/change_package.py index d60b7b799bf..ce8ef15a895 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/change_package.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/change_package.py @@ -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. @@ -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 diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/change_type.py b/rewrite-python/rewrite/src/rewrite/python/recipes/change_type.py index 1de638b4416..cfb0fac79ba 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/change_type.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/change_type.py @@ -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. @@ -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 diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/delete_method_argument.py b/rewrite-python/rewrite/src/rewrite/python/recipes/delete_method_argument.py index e029e636cd3..cfcb5190ee9 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/delete_method_argument.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/delete_method_argument.py @@ -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. @@ -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 diff --git a/rewrite-python/rewrite/src/rewrite/python/recipes/reorder_method_arguments.py b/rewrite-python/rewrite/src/rewrite/python/recipes/reorder_method_arguments.py index 32fea24f841..ce341bc961e 100644 --- a/rewrite-python/rewrite/src/rewrite/python/recipes/reorder_method_arguments.py +++ b/rewrite-python/rewrite/src/rewrite/python/recipes/reorder_method_arguments.py @@ -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. @@ -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