|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import toml |
4 | 3 | import sys |
5 | 4 | import os |
| 5 | +import re |
6 | 6 |
|
7 | 7 | # Dependencies that use the first version number (opentelemetry-python) |
8 | 8 | PYTHON_CORE_DEPS = [ |
@@ -79,24 +79,29 @@ def main(): |
79 | 79 |
|
80 | 80 | try: |
81 | 81 | with open(pyproject_path, 'r') as f: |
82 | | - data = toml.load(f) |
| 82 | + content = f.read() |
83 | 83 |
|
84 | | - deps = data.get('project', {}).get('dependencies', []) |
85 | 84 | updated = False |
86 | 85 |
|
87 | | - for i, dep in enumerate(deps): |
88 | | - dep_name = dep.split('==')[0].strip() |
89 | | - |
90 | | - if dep_name in PYTHON_CORE_DEPS: |
91 | | - deps[i] = f'{dep_name} == {otel_python_version}' |
| 86 | + # Update Python core dependencies |
| 87 | + for dep in PYTHON_CORE_DEPS: |
| 88 | + pattern = rf'"{re.escape(dep)} == [^"]*"' |
| 89 | + replacement = f'"{dep} == {otel_python_version}"' |
| 90 | + if re.search(pattern, content): |
| 91 | + content = re.sub(pattern, replacement, content) |
92 | 92 | updated = True |
93 | | - elif dep_name in CONTRIB_DEPS: |
94 | | - deps[i] = f'{dep_name} == {otel_contrib_version}' |
| 93 | + |
| 94 | + # Update contrib dependencies |
| 95 | + for dep in CONTRIB_DEPS: |
| 96 | + pattern = rf'"{re.escape(dep)} == [^"]*"' |
| 97 | + replacement = f'"{dep} == {otel_contrib_version}"' |
| 98 | + if re.search(pattern, content): |
| 99 | + content = re.sub(pattern, replacement, content) |
95 | 100 | updated = True |
96 | 101 |
|
97 | 102 | if updated: |
98 | 103 | with open(pyproject_path, 'w') as f: |
99 | | - toml.dump(data, f) |
| 104 | + f.write(content) |
100 | 105 | print(f'Dependencies updated to Python {otel_python_version} / Contrib {otel_contrib_version}') |
101 | 106 | else: |
102 | 107 | print('No OpenTelemetry dependencies found to update') |
|
0 commit comments