17
17
18
18
logger = get_logger (__name__ )
19
19
20
+
20
21
def fetch_upstream (* , base_url : str , path : str , version : str ) -> str :
21
22
upstream_url = "/" .join ((base_url , version , path ))
22
23
logger .debug (f"{ upstream_url = } " )
@@ -44,6 +45,7 @@ def get_upstream_contents(
44
45
else :
45
46
return fetch ()
46
47
48
+
47
49
def format_patch (patch_conf : Patch ) -> str :
48
50
"""
49
51
Transforms a patch definition to a raw python code.
@@ -80,6 +82,7 @@ def format_patch(patch_conf: Patch) -> str:
80
82
81
83
return res .strip ().rstrip (";" ).strip ()
82
84
85
+
83
86
def iter_patches (tree : ast .Module , conf : Conf ) -> "Iterator[tuple[int, str]]" :
84
87
"""
85
88
Get needed patches to apply for given ast tree based on the conf.
@@ -117,14 +120,14 @@ def iter_patches(tree: ast.Module, conf: Conf) -> "Iterator[tuple[int, str]]":
117
120
if not (patch_conf := cls_conf .pop (fn_node .name , None )):
118
121
continue
119
122
120
- '''
123
+ """
121
124
if any(
122
125
is_patch_present(dec_node, patch_conf)
123
126
for dec_node in fn_node.decorator_list
124
127
if isinstance(dec_node, (ast.Attribute, ast.Call))
125
128
):
126
129
continue
127
- '''
130
+ """
128
131
129
132
lineno = min (
130
133
(dec_node .lineno for dec_node in fn_node .decorator_list ),
@@ -158,6 +161,7 @@ def iter_patches(tree: ast.Module, conf: Conf) -> "Iterator[tuple[int, str]]":
158
161
""" .rstrip (),
159
162
)
160
163
164
+
161
165
def apply_conf (contents : str , conf : dict ) -> str :
162
166
"""
163
167
Patch a given source code based on the conf.
@@ -184,6 +188,7 @@ def apply_conf(contents: str, conf: dict) -> str:
184
188
185
189
return "\n " .join (lines )
186
190
191
+
187
192
def run (
188
193
conf : dict ,
189
194
path : str ,
@@ -196,7 +201,7 @@ def run(
196
201
path = path , version = version , base_url = base_upstream_url , cache_dir = cache_dir
197
202
)
198
203
199
- patched_contents = apply_conf (contents , conf )
204
+ patched_contents = apply_conf (contents , conf )
200
205
new_contents = f"# upstream_version: { version } \n { patched_contents } "
201
206
202
207
output_file = output_dir / path
0 commit comments