Skip to content

Commit ba363c4

Browse files
authored
Check for pyproject when parsing library dependencies (Azure#42039)
* Check for pyproject.toml * Only attempt pyproject parsing if setup.py fails * Add test and documentation * Pass lib_dir to from_path instead of file path * Updated parsing exception
1 parent 75bafb8 commit ba363c4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tools/azure-sdk-tools/ci_tools/dependency_analysis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ def get_lib_deps(base_dir: str) -> Tuple[Dict[str, Dict[str, Any]], Dict[str, Di
5959
packages = {}
6060
dependencies = {}
6161
for lib_dir in discover_targeted_packages("azure*", base_dir):
62-
setup_path = os.path.join(lib_dir, "setup.py")
6362
try:
64-
parsed = ParsedSetup.from_path(setup_path)
63+
parsed = ParsedSetup.from_path(lib_dir)
6564
lib_name, version, requires = parsed.name, parsed.version, parsed.requires
6665

6766
packages[lib_name] = {"version": version, "source": lib_dir, "deps": []}
@@ -76,7 +75,7 @@ def get_lib_deps(base_dir: str) -> Tuple[Dict[str, Dict[str, Any]], Dict[str, Di
7675
packages[lib_name]["deps"].append({"name": req_name, "version": str(spec)})
7776
record_dep(dependencies, req_name, str(spec), lib_name)
7877
except:
79-
print("Failed to parse %s" % (setup_path))
78+
print(f"Failed to parse setup.py or pyproject.toml at {lib_dir}")
8079
return packages, dependencies
8180

8281

tools/azure-sdk-tools/tests/test_pyproject_interactions.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
import pytest
55

6+
from ci_tools.dependency_analysis import get_lib_deps
67
from ci_tools.parsing import update_build_config, get_build_config, get_config_setting
78
from ci_tools.environment_exclusions import is_check_enabled
9+
from ci_tools.variables import discover_repo_root
810

911
integration_folder = os.path.join(os.path.dirname(__file__), "integration")
1012
pyproject_folder = os.path.join(integration_folder, "scenarios", "pyproject_build_config")
@@ -88,4 +90,13 @@ def test_pyproject_update_check_override():
8890
assert update_result == build_config
8991

9092
reloaded_build_config = get_build_config(temp_dir)
91-
assert reloaded_build_config == update_result
93+
assert reloaded_build_config == update_result
94+
95+
96+
def test_pyproject_get_lib_deps():
97+
all_packages, _ = get_lib_deps(discover_repo_root())
98+
# Ensure that libraries with pyproject.toml files are fetched correctly; azure-keyvault-keys is an example
99+
pyproject_info = all_packages["azure-keyvault-keys"]
100+
assert pyproject_info["version"]
101+
assert pyproject_info["source"]
102+
assert len(pyproject_info["deps"]) > 0

0 commit comments

Comments
 (0)