@@ -113,6 +113,7 @@ def call_build_config(package_name: str, folder_name: str):
113
113
os .environ .get ("GH_TOKEN" , None ),
114
114
packages = [package_name ],
115
115
build_conf = True ,
116
+ template_names = ["README.md" , "__init__.py" ],
116
117
)
117
118
# Replace this check_call by in process equivalent call, for better debugging
118
119
# check_call(
@@ -156,10 +157,19 @@ def generate_packaging_files(package_name, folder_name):
156
157
sdk_packaging_toml .rename (pyproject_toml )
157
158
158
159
if "azure-mgmt-" in package_name :
160
+ # if codegen generate pyproject.toml instead of setup.py, we delete existing setup.py
161
+ setup_py = output_path / "setup.py"
162
+ if setup_py .exists ():
163
+ _LOGGER .info (f"delete { setup_py } since codegen generate pyproject.toml" )
164
+ with open (pyproject_toml , "rb" ) as f :
165
+ pyproject_content = toml .load (f )
166
+ if pyproject_content .get ("project" ):
167
+ setup_py .unlink ()
168
+
159
169
call_build_config (package_name , folder_name )
160
170
else :
161
- if not ( output_path / CONF_NAME ) .exists ():
162
- with open (output_path / CONF_NAME , "w" ) as file_out :
171
+ if not pyproject_toml .exists ():
172
+ with open (pyproject_toml , "w" ) as file_out :
163
173
file_out .write ("[packaging]\n auto_update = false" )
164
174
165
175
# add ci.yaml
@@ -243,7 +253,38 @@ def judge_tag_preview(path: str, package_name: str) -> bool:
243
253
_LOGGER .info (f"can not open { file } " )
244
254
continue
245
255
256
+ skip_decorator_block = False
257
+ decorator_depth = 0
258
+
246
259
for line in list_in :
260
+ # skip the code of decorator @api_version_validation
261
+ stripped_line = line .strip ()
262
+
263
+ # Check if we're starting an @api_version_validation decorator block
264
+ if "@api_version_validation" in stripped_line :
265
+ skip_decorator_block = True
266
+ decorator_depth = 0
267
+ continue
268
+
269
+ # If we're in a decorator block, track parentheses depth
270
+ if skip_decorator_block :
271
+ decorator_depth += stripped_line .count ("(" ) - stripped_line .count (")" )
272
+ # If we've closed all parentheses and hit a function definition, skip until next function/class
273
+ if decorator_depth == 0 and (
274
+ stripped_line .startswith ("def " ) or stripped_line .startswith ("async def " )
275
+ ):
276
+ continue
277
+ # If we hit another decorator or function/class definition after closing parentheses, stop skipping
278
+ if decorator_depth == 0 and (
279
+ stripped_line .startswith ("@" )
280
+ or stripped_line .startswith ("def " )
281
+ or stripped_line .startswith ("async def " )
282
+ or stripped_line .startswith ("class " )
283
+ ):
284
+ skip_decorator_block = False
285
+ else :
286
+ continue
287
+
247
288
if "DEFAULT_API_VERSION = " in line :
248
289
default_api_version += line .split ("=" )[- 1 ].strip ("\n " ) # collect all default api version
249
290
if default_api_version == "" and "api_version" in line and "method_added_on" not in line :
@@ -462,13 +503,11 @@ def gen_typespec(
462
503
tsp_dir = (Path (spec_folder ) / typespec_relative_path ).resolve ()
463
504
repo_url = rest_repo_url .replace ("https://github.com/" , "" )
464
505
tspconfig = tsp_dir / "tspconfig.yaml"
465
- if tspconfig .exists ():
506
+ if tspconfig .exists () and api_version :
466
507
with open (tspconfig , "r" ) as file_in :
467
508
content = yaml .safe_load (file_in )
468
509
if content .get ("options" , {}).get ("@azure-tools/typespec-python" ):
469
- content ["options" ]["@azure-tools/typespec-python" ]["keep-setup-py" ] = True
470
- if api_version :
471
- content ["options" ]["@azure-tools/typespec-python" ]["api-version" ] = api_version
510
+ content ["options" ]["@azure-tools/typespec-python" ]["api-version" ] = api_version
472
511
with open (tspconfig , "w" ) as file_out :
473
512
yaml .dump (content , file_out )
474
513
cmd = f"tsp-client init --tsp-config { tsp_dir } --local-spec-repo { tsp_dir } --commit { head_sha } --repo { repo_url } "
0 commit comments