|
| 1 | +import ast |
| 2 | +import sys |
| 3 | + |
| 4 | + |
| 5 | +def fetch_dependencies_from_setup(file_path): |
| 6 | + with open(file_path, "r") as file: |
| 7 | + tree = ast.parse(file.read(), filename=file_path) |
| 8 | + |
| 9 | + dependencies = [] |
| 10 | + |
| 11 | + for node in ast.walk(tree): |
| 12 | + if isinstance(node, ast.Call) and getattr(node.func, "id", None) == "setup": |
| 13 | + for keyword in node.keywords: |
| 14 | + if keyword.arg == "install_requires": |
| 15 | + dependencies = [elt.s for elt in keyword.value.elts] |
| 16 | + break |
| 17 | + |
| 18 | + return dependencies |
| 19 | + |
| 20 | + |
| 21 | +# Path to the setup.py file of azure-ai-ml |
| 22 | +setup_file_path = "sdk/ml/azure-ai-ml/setup.py" |
| 23 | + |
| 24 | +# Fetch dependencies |
| 25 | +deps_list = fetch_dependencies_from_setup(setup_file_path) |
| 26 | + |
| 27 | +print("Dependencies of azure-sdk-for-python repo from setup.py of azure-ai-ml:") |
| 28 | +print(deps_list) |
| 29 | + |
| 30 | +from packaging.requirements import Requirement |
| 31 | + |
| 32 | +deps = [Requirement(line) for line in deps_list if line.strip() and not line.strip().startswith("#")] |
| 33 | +import requests |
| 34 | + |
| 35 | + |
| 36 | +def list_versions(package_name): |
| 37 | + url = f"https://pypi.org/pypi/{package_name}/json" |
| 38 | + response = requests.get(url) |
| 39 | + data = response.json() |
| 40 | + versions = data["releases"].keys() |
| 41 | + version_array = [] |
| 42 | + for version in versions: |
| 43 | + version_array.append(version.split(".")[0]) |
| 44 | + return sorted(version_array, key=int, reverse=True) |
| 45 | + |
| 46 | + |
| 47 | +from packaging.version import Version |
| 48 | + |
| 49 | + |
| 50 | +def is_major_update(previous, latest): |
| 51 | + return Version(latest).major > Version(previous).major |
| 52 | + |
| 53 | + |
| 54 | +def check_for_major_updates(): |
| 55 | + major_updates = [] |
| 56 | + for dep in deps: |
| 57 | + all_version = list_versions(dep.name) |
| 58 | + if len(all_version) > 1 and is_major_update(all_version[1], all_version[0]): |
| 59 | + major_updates.append( |
| 60 | + f"Current config of `{dep}` and major version updated from {dep.name}: {all_version[1]} → {all_version[0]}" |
| 61 | + ) |
| 62 | + if major_updates: |
| 63 | + # body = "\n".join(major_updates) # Uncomment this line if you want to send an email or notification |
| 64 | + print("Major Dependency Updates Found:") |
| 65 | + print(major_updates) |
| 66 | + sys.exit(1) |
| 67 | + else: |
| 68 | + print("No major updates found.") |
| 69 | + |
| 70 | + |
| 71 | +check_for_major_updates() |
0 commit comments