Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
533 changes: 533 additions & 0 deletions eng/scripts/migrate_setup_py_to_pyproject.py

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions eng/tools/azure-sdk-tools/packaging_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def build_packaging_by_package_name(
if template_name not in template_names:
_LOGGER.info("Skipping template %s", template_name)
continue

# Skip setup.py since packages now use pyproject.toml
if template_name == "setup.py":
_LOGGER.info("Skipping setup.py template (packages use pyproject.toml)")
continue

future_filepath = Path(output_folder) / package_name / template_name

# Might decide to make it more generic one day
Expand All @@ -120,10 +126,56 @@ def build_packaging_by_package_name(

continue

# pyproject.toml requires merge strategy to preserve existing tool settings
if template_name == "pyproject.toml" and future_filepath.exists():
_merge_pyproject_toml(future_filepath, result)
continue

with open(future_filepath, "w") as fd:
fd.write(result)
# azure_bdist_wheel had been removed, but need to delete it manually
with suppress(FileNotFoundError):
(Path(output_folder) / package_name / "azure_bdist_wheel.py").unlink()
# setup.py is no longer used, remove it if present
with suppress(FileNotFoundError):
(Path(output_folder) / package_name / "setup.py").unlink()

_LOGGER.info("Template done %s", package_name)


def _merge_pyproject_toml(existing_path: Path, new_content: str) -> None:
"""Merge new pyproject.toml template content with existing file, preserving tool settings."""
try:
import tomllib as toml
except ImportError:
import tomli as toml # type: ignore
import tomli_w as tomlw

# Parse existing file
with open(existing_path, "rb") as f:
existing = toml.load(f)

# Parse new template content
import io

new = toml.load(io.BytesIO(new_content.encode("utf-8")))

# Merge: new content takes precedence for project/build-system/setuptools,
# but preserve existing tool.* sections (other than setuptools)
merged = dict(new)
existing_tool = existing.get("tool", {})
new_tool = new.get("tool", {})
merged_tool = dict(new_tool)
for key, val in existing_tool.items():
if key not in merged_tool:
merged_tool[key] = val
merged["tool"] = merged_tool

# Preserve top-level non-tool sections from existing (like [packaging])
for key, val in existing.items():
if key not in merged:
merged[key] = val

with open(existing_path, "wb") as f:
tomlw.dump(merged, f)
_LOGGER.info("Merged pyproject.toml for %s", existing_path)
11 changes: 4 additions & 7 deletions eng/tools/azure-sdk-tools/packaging_tools/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ def generate_packaging_and_ci_files(package_path: Path):

package_name = package_path.name
if "azure-mgmt-" in package_name:
# if codegen generate pyproject.toml instead of setup.py, we delete existing setup.py
# delete setup.py if pyproject.toml exists (packages now use pyproject.toml)
setup_py = package_path / "setup.py"
if setup_py.exists():
_LOGGER.info(f"delete {setup_py} since codegen generate pyproject.toml")
with open(pyproject_toml, "rb") as f:
pyproject_content = toml.load(f)
if pyproject_content.get("project"):
setup_py.unlink()
if setup_py.exists() and pyproject_toml.exists():
_LOGGER.info(f"delete {setup_py} since packages now use pyproject.toml")
setup_py.unlink()

call_build_config(package_name, str(package_path.parent))
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[build-system]
requires = [
"setuptools>=77.0.3",
"wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "{{package_name}}"
authors = [
{ name = "Microsoft Corporation", email = "azpysdkhelp@microsoft.com" },
]
description = "Microsoft Azure {{package_pprint_name}} Client Library for Python"
license = "MIT"
classifiers = [
"{{classifier}}",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
requires-python = ">=3.9"
keywords = ["azure", "azure sdk"]
dependencies = [
"isodate>=0.6.1",
"typing-extensions>=4.6.0",
{%- if need_msrestazure %}
"msrestazure>=0.4.32",
{%- endif %}
"azure-common>=1.1",
{%- if need_azurecore %}
"azure-core>=1.35.0",
{%- endif %}
{%- if need_azuremgmtcore %}
"azure-mgmt-core>=1.6.0",
{%- endif %}
]
dynamic = ["version", "readme"]

[project.urls]
repository = "https://github.com/Azure/azure-sdk-for-python"

[tool.setuptools.dynamic.version]
attr = "{{package_name | replace('-', '.')}}._version.VERSION"

[tool.setuptools.dynamic.readme]
file = ["README.md", "CHANGELOG.md"]
content-type = "text/markdown"

[tool.setuptools.packages.find]
exclude = [
"tests*",
"generated_tests*",
"samples*",
"generated_samples*",
"doc*",
{%- for nspkg_name in nspkg_names %}
"{{ nspkg_name }}",
{%- endfor %}
{%- for folder in exclude_folders %}
"{{ folder }}",
{%- endfor %}
]

[tool.setuptools.package-data]
pytyped = ["py.typed"]
75 changes: 75 additions & 0 deletions sdk/advisor/azure-mgmt-advisor/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,81 @@
[build-system]
requires = [
"setuptools>=77.0.3",
"wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "azure-mgmt-advisor"
authors = [
{ name = "Microsoft Corporation", email = "azpysdkhelp@microsoft.com" },
]
description = "Microsoft Azure Advisor Client Library for Python"
license = "MIT"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]
requires-python = ">=3.7"
keywords = [
"azure",
"azure sdk",
]
dependencies = [
"msrest>=0.7.1",
"azure-common~=1.1",
"azure-mgmt-core>=1.3.2,<2.0.0",
"typing-extensions>=4.3.0; python_version<'3.8.0'",
]
dynamic = [
"version",
"readme",
]

[project.urls]
repository = "https://github.com/Azure/azure-sdk-for-python"

[tool.azure-sdk-build]
breaking = false
mypy = false
pyright = false
type_check_samples = false
verifytypes = false

[tool.setuptools.dynamic.version]
attr = "azure.mgmt.advisor._version.VERSION"

[tool.setuptools.dynamic.readme]
file = [
"README.md",
"CHANGELOG.md",
]
content-type = "text/markdown"

[tool.setuptools.packages.find]
exclude = [
"tests",
"azure",
"azure.mgmt",
]

[tool.setuptools.package-data]
pytyped = [
"py.typed",
]

[packaging]
package_name = "azure-mgmt-advisor"
package_nspkg = "azure-mgmt-nspkg"
package_pprint_name = "Advisor"
package_doc_id = "advisor"
is_stable = true
is_arm = true
sample_link = ""
title = "AdvisorManagementClient"
9 changes: 0 additions & 9 deletions sdk/advisor/azure-mgmt-advisor/sdk_packaging.toml

This file was deleted.

78 changes: 0 additions & 78 deletions sdk/advisor/azure-mgmt-advisor/setup.py

This file was deleted.

Loading
Loading