Skip to content

Commit 5af67ab

Browse files
authored
[sdk generation pipeline] update for pyproject.toml (#41478)
* update for pyproject.toml * Update package_utils.py
1 parent 2e7b619 commit 5af67ab

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

tools/azure-sdk-tools/packaging_tools/package_utils.py

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -336,24 +336,52 @@ def check_dev_requirement(self):
336336
@return_origin_path
337337
def check_pyproject_toml(self):
338338
os.chdir(Path("sdk") / self.sdk_folder / self.whole_package_name)
339-
# add `breaking = false` in pyproject.toml
340-
toml = Path("pyproject.toml")
341-
if not toml.exists():
342-
with open(toml, "w") as file:
343-
file.write("[tool.azure-sdk-build]\nbreaking = false\n")
344-
_LOGGER.info("create pyproject.toml")
345-
339+
# Configure and ensure pyproject.toml exists with required settings
340+
toml_path = Path("pyproject.toml")
341+
342+
# Default configurations to enforce
343+
default_configs = {
344+
"breaking": "false",
345+
"pyright": "false",
346+
"mypy": "false",
347+
}
348+
349+
# Create new pyproject.toml if it doesn't exist
350+
if not toml_path.exists():
351+
with open(toml_path, "w") as file:
352+
file.write("[tool.azure-sdk-build]\n")
353+
for key, value in default_configs.items():
354+
file.write(f"{key} = {value}\n")
355+
_LOGGER.info("Created pyproject.toml with default configurations")
356+
return
357+
358+
# If file exists, ensure all required configurations are present
346359
def edit_toml(content: List[str]):
347-
has_breaking = False
348-
for line in content:
349-
if "breaking = false" in line:
350-
has_breaking = True
351-
break
352-
if not has_breaking:
353-
_LOGGER.info("add breaking = false to pyproject.toml")
354-
content.append("breaking = false\n")
355-
356-
modify_file(str(toml), edit_toml)
360+
# Track if we have the [tool.azure-sdk-build] section
361+
has_section = False
362+
config_exists = {key: False for key in default_configs}
363+
364+
# Check for existing configurations and section
365+
for i, line in enumerate(content):
366+
if "[tool.azure-sdk-build]" in line:
367+
has_section = True
368+
369+
# Check for each configuration
370+
for key in default_configs:
371+
if f"{key} = " in line:
372+
config_exists[key] = True
373+
374+
# Add section if it doesn't exist
375+
if not has_section:
376+
content.append("\n[tool.azure-sdk-build]\n")
377+
378+
# Add missing configurations
379+
for key, value in default_configs.items():
380+
if not config_exists[key]:
381+
_LOGGER.info(f"Adding {key} = {value} to pyproject.toml")
382+
content.append(f"{key} = {value}\n")
383+
384+
modify_file(str(toml_path), edit_toml)
357385

358386
def run(self):
359387
self.check_file_with_packaging_tool()

0 commit comments

Comments
 (0)