Skip to content

Move KV Keys to pyproject.toml #39100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/azure-sdk-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Install azure-sdk-tools
run: |
python -m pip install -e tools/azure-sdk-tools[build,ghtools]
python -m pip install -e tools/azure-sdk-tools[build,ghtools,conda]
python -m pip freeze
shell: bash

Expand Down
1 change: 1 addition & 0 deletions eng/ci_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typing-extensions<=4.6.3
pyproject-api<1.6
cibuildwheel==2.16.5
importlib-metadata==8.0.0
build==1.2.2.post1

# requirements leveraged for testing
pytest==7.3.1
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/get_package_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# Use abspath for the os.walk because if setup parsing fails it often changes cwd which throws off the relative walk
for root, dirs, files in os.walk(os.path.abspath(args.search_path)):
if re.search(r"sdk[\\/][^\\/]+[\\/][^\\/]+$", root):
if "setup.py" in files:
if "setup.py" or "pyproject.toml" in files:
try:
parsed = ParsedSetup.from_path(root)

Expand Down
1 change: 1 addition & 0 deletions eng/test_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ coverage==7.2.5
bandit==1.6.2
protobuf==3.17.3; python_version == '2.7'
pyproject-api<1.6
build==1.2.2.post1

# locking packages defined as deps from azure-sdk-tools
Jinja2==3.1.2
Expand Down
10 changes: 6 additions & 4 deletions eng/tox/install_depend_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def check_req_against_exclusion(req, req_to_exclude):


def filter_dev_requirements(
setup_py_path,
package_directory,
released_packages,
temp_dir,
additional_filter_fn: Optional[Callable[[str, List[str], List[Requirement]], List[str]]] = None,
Expand All @@ -324,7 +324,7 @@ def filter_dev_requirements(
by the package).
"""
# This method returns list of requirements from dev_requirements by filtering out packages in given list
dev_req_path = os.path.join(os.path.dirname(setup_py_path), DEV_REQ_FILE)
dev_req_path = os.path.join(package_directory, DEV_REQ_FILE)
requirements = []
with open(dev_req_path, "r") as dev_req_file:
requirements = dev_req_file.readlines()
Expand All @@ -348,7 +348,7 @@ def filter_dev_requirements(

if additional_filter_fn:
# this filter function handles the case where a dev requirement is incompatible with the current set of targeted packages
filtered_req = additional_filter_fn(setup_py_path, filtered_req, released_packages)
filtered_req = additional_filter_fn(package_directory, filtered_req, released_packages)

logging.info("Filtered dev requirements: %s", filtered_req)

Expand Down Expand Up @@ -410,10 +410,12 @@ def install_packages(packages, req_file):
)

args = parser.parse_args()
setup_path = os.path.join(os.path.abspath(args.target_package), "setup.py")

setup_path = os.path.join(os.path.abspath(args.target_package))

if not (os.path.exists(setup_path) and os.path.exists(args.work_dir)):
logging.error("Invalid arguments. Please make sure target directory and working directory are valid path")
sys.exit(1)


install_dependent_packages(setup_path, args.dependency_type, args.work_dir)
4 changes: 2 additions & 2 deletions eng/tox/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ envlist = whl,sdist
deps =
-r {repository_root}/eng/test_tools.txt


[coverage:paths]
source =
azure
Expand All @@ -45,6 +44,7 @@ pkgs =
packaging==23.1
urllib3==1.26.15
tomli==2.0.1
build==1.2.2.post1

[pytest]
ignore_args=--ignore=.tox --ignore=build --ignore=.eggs --ignore=samples
Expand Down Expand Up @@ -415,7 +415,7 @@ deps =
{[packaging]pkgs}
commands =
python -m pip install {repository_root}/tools/azure-sdk-tools --no-deps
python {tox_root}/setup.py --q sdist -d {envtmpdir}
sdk_build_package --package_folder {tox_root} -d {envtmpdir} --package_type sdist
python {repository_root}/eng/tox/verify_sdist.py -d {envtmpdir} -t {tox_root}


Expand Down
2 changes: 1 addition & 1 deletion eng/tox/verify_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_root_directories_in_sdist(dist_dir: str, version: str) -> List[str]:
"""
# find sdist zip file
# extract sdist and find list of directories in sdist
path_to_zip = glob.glob(os.path.join(dist_dir, "*{}*.tar.gz".format(version)))[0]
path_to_zip = glob.glob(os.path.join(dist_dir, "**", "*{}*.tar.gz".format(version)))[0]
extract_location = os.path.join(dist_dir, "unzipped")
# Cleanup any files in unzipped
cleanup(extract_location)
Expand Down
47 changes: 47 additions & 0 deletions sdk/keyvault/azure-keyvault-keys/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
[build-system]
requires = ["setuptools>=61.0.0", "wheel"] # Requires 61.0.0 for dynamic version
build-backend = "setuptools.build_meta"

[project]
name = "azure-keyvault-keys"
authors = [
{name = "Microsoft Corporation", email = "[email protected]"},
]
description = "Microsoft Azure Key Vault Keys Client Library for Python"
keywords = ["azure", "azure sdk"]
requires-python = ">=3.8"
license = {text = "MIT License"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"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",
"License :: OSI Approved :: MIT License",
]
dependencies = [
"azure-core>=1.31.0",
"cryptography>=2.1.4",
"isodate>=0.6.1",
"typing-extensions>=4.6.0",
]
dynamic = ["version", "readme"]

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

[tool.setuptools.dynamic]
version = {attr = "azure.keyvault.keys._version.VERSION"}
readme = {file = ["README.md", "CHANGELOG.md"], content-type = "text/markdown"}

[tool.setuptools.packages.find]
exclude = ["samples*", "tests*", "azure", "azure.keyvault"]

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

[tool.azure-sdk-build]
pyright = false
76 changes: 0 additions & 76 deletions sdk/keyvault/azure-keyvault-keys/setup.py

This file was deleted.

59 changes: 57 additions & 2 deletions tools/azure-sdk-tools/ci_tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,57 @@
from ci_tools.versioning.version_set_dev import get_dev_version, format_build_id


def build_package() -> None:
parser = argparse.ArgumentParser(
description="""This is a secondary entrypoint for the "build" action. This command is used to install dependencies and build a specific package within the azure-sdk-for-python repository.""",
)

parser.add_argument(
"-d",
"--distribution-directory",
dest="distribution_directory",
help="The path to the distribution directory. Should be passed $(Build.ArtifactStagingDirectory) from the devops yaml definition."
+ "If that is not provided, will default to env variable SDK_ARTIFACT_DIRECTORY -> <calculated_repo_root>/.artifacts.",
)

parser.add_argument(
"--package_folder",
dest="package_folder",
required=True,
help="The target that should be assembled",
)

parser.add_argument(
"--package_type",
dest="package_type",
choices=["sdist", "whl", "all"],
default="all",
help="The type of package to build: sdist (source distribution only), whl (wheel only), or all (both)",
)

args = parser.parse_args()

target_package = ParsedSetup.from_path(args.package_folder)
artifact_directory = get_artifact_directory(args.distribution_directory)

enable_sdist = True
enable_wheel = True

if args.package_type == "sdist":
enable_wheel = False

if args.package_type == "whl":
enable_sdist = False

build_packages(
[target_package.folder],
artifact_directory,
False,
DEFAULT_BUILD_ID,
enable_wheel,
enable_sdist
)

def build() -> None:
parser = argparse.ArgumentParser(
description="""This is the primary entrypoint for the "build" action. This command is used to build any package within the azure-sdk-for-python repository.""",
Expand Down Expand Up @@ -125,6 +176,8 @@ def build() -> None:
artifact_directory,
str_to_bool(args.is_dev_build),
build_id,
True,
True
)


Expand All @@ -146,6 +199,8 @@ def build_packages(
distribution_directory: Optional[str] = None,
is_dev_build: bool = False,
build_id: str = "",
enable_wheel: bool = True,
enable_sdist: bool = True
):
logging.log(level=logging.INFO, msg=f"Generating {targeted_packages} using python{sys.version}")

Expand All @@ -168,7 +223,7 @@ def build_packages(
set_version_py(setup_parsed.setup_filename, new_version)
set_dev_classifier(setup_parsed.setup_filename, new_version)

create_package(package_root, dist_dir)
create_package(package_root, dist_dir, enable_wheel, enable_sdist)


def create_package(
Expand All @@ -193,7 +248,7 @@ def create_package(
pip_output = get_pip_list_output(sys.executable)
necessary_install_requirements = [req for req in setup_parsed.requires if parse_require(req).key not in pip_output.keys()]
run([sys.executable, "-m", "pip", "install", *necessary_install_requirements], cwd=setup_parsed.folder)
run([sys.executable, "-m", "build", f"-n{'s' if enable_sdist else ''}{'w' if enable_wheel else ''}", "-o", dist], cwd=setup_parsed.folder)
run([sys.executable, "-m", "build", f"-n{'s' if enable_sdist else ''}{'w' if enable_wheel else ''}", "-o", dist], cwd=setup_parsed.folder, check=True)
else:
if enable_wheel:
if setup_parsed.ext_modules:
Expand Down
2 changes: 1 addition & 1 deletion tools/azure-sdk-tools/ci_tools/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def process_requires(setup_py_path: str, is_dev_build: bool = False):
else:
logging.info("Packages not available on PyPI:{}".format(requirement_to_update))
update_requires(setup_py_path, requirement_to_update)
logging.info("Package requirement is updated in setup.py")
logging.info(f"Package requirement is updated in {'pyproject.toml' if pkg_details.is_pyproject else 'setup.py'}.")


def find_sdist(dist_dir: str, pkg_name: str, pkg_version: str) -> Optional[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def parse_pyproject(
python_requires = project_config.get("requires-python")
requires = project_config.get("dependencies")
is_new_sdk = name in NEW_REQ_PACKAGES or any(map(lambda x: (parse_require(x).key in NEW_REQ_PACKAGES), requires))
# todo: update traversal logic
name_space = name.replace("-", ".")
package_data = get_value_from_dict(toml_dict, "tool.setuptools.package-data", None)
include_package_data = get_value_from_dict(toml_dict, "tool.setuptools.include-package-data", True)
Expand Down
7 changes: 3 additions & 4 deletions tools/azure-sdk-tools/ci_tools/scenario/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def create_package_and_install(

commands_options = []
built_pkg_path = ""
setup_py_path = os.path.join(target_setup, "setup.py")
additional_downloaded_reqs = []

if not os.path.exists(distribution_directory):
Expand All @@ -69,10 +68,10 @@ def create_package_and_install(
commands_options.extend(["--cache-dir", cache_dir])

discovered_packages = discover_packages(
setup_py_path, distribution_directory, target_setup, package_type, force_create
target_setup, distribution_directory, target_setup, package_type, force_create
)

target_package = ParsedSetup.from_path(setup_py_path)
target_package = ParsedSetup.from_path(target_setup)

# ensure that discovered packages are always copied to the distribution directory regardless of other factors
for built_package in discovered_packages:
Expand Down Expand Up @@ -104,7 +103,7 @@ def create_package_and_install(
logging.info("Installing {w} from fresh built package.".format(w=built_package))

if not pre_download_disabled:
requirements = ParsedSetup.from_path(os.path.join(os.path.abspath(target_setup), "setup.py")).requires
requirements = ParsedSetup.from_path(os.path.join(os.path.abspath(target_setup))).requires
azure_requirements = [req.split(";")[0] for req in requirements if req.startswith("azure-")]

if azure_requirements:
Expand Down
1 change: 1 addition & 0 deletions tools/azure-sdk-tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"sdk_generator=packaging_tools.sdk_generator:generate_main",
"sdk_package=packaging_tools.sdk_package:generate_main",
"sdk_build=ci_tools.build:build",
"sdk_build_package=ci_tools.build:build_package",
"sdk_build_conda=ci_tools.conda:entrypoint",
"sdk_set_dev_version=ci_tools.versioning.version_set_dev:version_set_dev_main",
"sdk_set_version=ci_tools.versioning.version_set:version_set_main",
Expand Down