Skip to content

Commit 8d6bc97

Browse files
Register all existing recipes
1 parent e7f8710 commit 8d6bc97

7 files changed

Lines changed: 57 additions & 19 deletions

File tree

rewrite-python/rewrite/src/rewrite/__init__.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,29 @@ def activate(marketplace: RecipeMarketplace) -> None:
108108
marketplace: The RecipeMarketplace to install recipes into
109109
"""
110110
from rewrite.decorators import get_recipe_category
111-
from rewrite.python.recipes import RemovePass
112-
113-
# Install all Python recipes with their categories
114-
category = get_recipe_category(RemovePass)
115-
if category is not None:
116-
marketplace.install(RemovePass, category)
111+
from rewrite.python.recipes import (
112+
RemovePass,
113+
ChangeImport,
114+
ChangeType,
115+
ChangeMethodName,
116+
ChangePackage,
117+
DeleteMethodArgument,
118+
ReorderMethodArguments,
119+
AddLiteralMethodArgument,
120+
)
121+
122+
for recipe_class in [
123+
RemovePass,
124+
ChangeImport,
125+
ChangeType,
126+
ChangeMethodName,
127+
ChangePackage,
128+
DeleteMethodArgument,
129+
ReorderMethodArguments,
130+
AddLiteralMethodArgument,
131+
]:
132+
category = get_recipe_category(recipe_class)
133+
if category is not None:
134+
marketplace.install(recipe_class, category)
135+
else:
136+
marketplace.install(recipe_class, Python)

rewrite-python/rewrite/src/rewrite/python/recipes/add_literal_method_argument.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
from typing import Any, Optional
2222

2323
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
24+
from rewrite.decorators import categorize
25+
from rewrite.marketplace import Python
2426
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2527

2628

29+
@categorize(Python)
2730
class AddLiteralMethodArgument(Recipe):
2831
"""
2932
Add a literal argument to method invocations matching a pattern.
@@ -58,9 +61,9 @@ class AddLiteralMethodArgument(Recipe):
5861

5962
def __init__(
6063
self,
61-
method_pattern: str,
62-
argument_index: int,
63-
literal: str
64+
method_pattern: str = "",
65+
argument_index: int = 0,
66+
literal: str = ""
6467
):
6568
self.method_pattern = method_pattern
6669
self.argument_index = argument_index

rewrite-python/rewrite/src/rewrite/python/recipes/change_method_name.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
from typing import Any, Optional
2222

2323
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
24+
from rewrite.decorators import categorize
25+
from rewrite.marketplace import Python
2426
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2527

2628

29+
@categorize(Python)
2730
class ChangeMethodName(Recipe):
2831
"""
2932
Rename method invocations matching a pattern.
@@ -65,8 +68,8 @@ class ChangeMethodName(Recipe):
6568

6669
def __init__(
6770
self,
68-
method_pattern: str,
69-
new_method_name: str,
71+
method_pattern: str = "",
72+
new_method_name: str = "",
7073
match_overrides: bool = False,
7174
ignore_definition: bool = False
7275
):

rewrite-python/rewrite/src/rewrite/python/recipes/change_package.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
from typing import Any, Optional
2222

2323
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
24+
from rewrite.decorators import categorize
25+
from rewrite.marketplace import Python
2426
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2527

2628

29+
@categorize(Python)
2730
class ChangePackage(Recipe):
2831
"""
2932
Change package/module references from one name to another.
@@ -58,8 +61,8 @@ class ChangePackage(Recipe):
5861

5962
def __init__(
6063
self,
61-
old_package_name: str,
62-
new_package_name: str,
64+
old_package_name: str = "",
65+
new_package_name: str = "",
6366
recursive: bool = True
6467
):
6568
self.old_package_name = old_package_name

rewrite-python/rewrite/src/rewrite/python/recipes/change_type.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
from typing import Any, Optional
2323

2424
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
25+
from rewrite.decorators import categorize
26+
from rewrite.marketplace import Python
2527
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2628

2729

30+
@categorize(Python)
2831
class ChangeType(Recipe):
2932
"""
3033
Change a type reference from one fully qualified name to another.
@@ -63,8 +66,8 @@ class ChangeType(Recipe):
6366

6467
def __init__(
6568
self,
66-
old_fully_qualified_type_name: str,
67-
new_fully_qualified_type_name: str,
69+
old_fully_qualified_type_name: str = "",
70+
new_fully_qualified_type_name: str = "",
6871
ignore_definition: bool = False
6972
):
7073
self.old_fully_qualified_type_name = old_fully_qualified_type_name

rewrite-python/rewrite/src/rewrite/python/recipes/delete_method_argument.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
from typing import Any, Optional
2222

2323
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
24+
from rewrite.decorators import categorize
25+
from rewrite.marketplace import Python
2426
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2527

2628

29+
@categorize(Python)
2730
class DeleteMethodArgument(Recipe):
2831
"""
2932
Remove an argument from method invocations matching a pattern.
@@ -51,8 +54,8 @@ class DeleteMethodArgument(Recipe):
5154

5255
def __init__(
5356
self,
54-
method_pattern: str,
55-
argument_index: int
57+
method_pattern: str = "",
58+
argument_index: int = 0
5659
):
5760
self.method_pattern = method_pattern
5861
self.argument_index = argument_index

rewrite-python/rewrite/src/rewrite/python/recipes/reorder_method_arguments.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
from typing import Any, List, Optional
2323

2424
from rewrite import ExecutionContext, Recipe, TreeVisitor, option
25+
from rewrite.decorators import categorize
26+
from rewrite.marketplace import Python
2527
from rewrite.rpc.java_recipe import prepare_java_recipe, JavaRecipeVisitor, PreparedJavaRecipe
2628

2729

30+
@categorize(Python)
2831
class ReorderMethodArguments(Recipe):
2932
"""
3033
Reorder arguments in method invocations matching a pattern.
@@ -59,8 +62,8 @@ class ReorderMethodArguments(Recipe):
5962

6063
def __init__(
6164
self,
62-
method_pattern: str,
63-
new_parameter_names: List[str],
65+
method_pattern: str = "",
66+
new_parameter_names: Optional[List[str]] = None,
6467
old_parameter_names: Optional[List[str]] = None
6568
):
6669
self.method_pattern = method_pattern

0 commit comments

Comments
 (0)