|
| 1 | +import os |
| 2 | +import re |
| 3 | + |
| 4 | +import toml |
| 5 | + |
| 6 | +# Define the paths to the vonage packages |
| 7 | +packages = [ |
| 8 | + "vonage-account", |
| 9 | + "vonage-application", |
| 10 | + "vonage-http-client", |
| 11 | + "vonage-messages", |
| 12 | + "vonage-network-auth", |
| 13 | + "vonage-network-sim-swap", |
| 14 | + "vonage-network-number-verification", |
| 15 | + "vonage-number-insight", |
| 16 | + "vonage-numbers", |
| 17 | + "vonage-sms", |
| 18 | + "vonage-subaccounts", |
| 19 | + "vonage-users", |
| 20 | + "vonage-utils", |
| 21 | + "vonage-verify", |
| 22 | + "vonage-verify-legacy", |
| 23 | + "vonage-video", |
| 24 | + "vonage-voice", |
| 25 | +] |
| 26 | + |
| 27 | + |
| 28 | +# Function to read the version from _version.py |
| 29 | +def get_version(folder_path: str, package_path: str) -> str: |
| 30 | + content = None |
| 31 | + try: |
| 32 | + version_file = os.path.join( |
| 33 | + folder_path.replace("-", "_"), |
| 34 | + "src", |
| 35 | + package_path.replace("-", "_"), |
| 36 | + "_version.py", |
| 37 | + ) |
| 38 | + |
| 39 | + with open(version_file, "r") as f: |
| 40 | + content = f.read() |
| 41 | + except FileNotFoundError: |
| 42 | + if folder_path == "vonage-numbers": |
| 43 | + return get_version("number-management", "vonage-numbers") |
| 44 | + folder_path_fragments = package_path.split("-") |
| 45 | + folder_path = "_".join(folder_path_fragments[1:]) |
| 46 | + return get_version(folder_path, package_path) |
| 47 | + |
| 48 | + version_match = re.search(r'__version__\s*=\s*[\'"]([^\'"]+)[\'"]', content) |
| 49 | + if version_match: |
| 50 | + return version_match.group(1) |
| 51 | + raise ValueError(f"Version not found in {version_file}") |
| 52 | + |
| 53 | + |
| 54 | +# Read the existing pyproject.toml |
| 55 | +with open("vonage/pyproject.toml", "r") as f: |
| 56 | + pyproject = toml.load(f) |
| 57 | + |
| 58 | +# Update the dependencies with the versions from _version.py |
| 59 | +dependencies = [] |
| 60 | +for package in packages: |
| 61 | + version = get_version(package, package) |
| 62 | + dependencies.append(f"{package}>={version}") |
| 63 | + |
| 64 | +pyproject["project"]["dependencies"] = dependencies |
| 65 | + |
| 66 | +# Write the updated pyproject.toml |
| 67 | +with open("vonage/pyproject.toml", "w") as f: |
| 68 | + toml.dump(pyproject, f) |
| 69 | + |
| 70 | +print("pyproject.toml updated with local package versions.") |
0 commit comments