Skip to content

Commit fae0a59

Browse files
committed
update dependencies in all file locations
1 parent 6d7edc4 commit fae0a59

File tree

1 file changed

+53
-34
lines changed

1 file changed

+53
-34
lines changed

scripts/update_dependencies.py

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
PYTHON_CORE_DEPS = [
1111
"opentelemetry-api",
1212
"opentelemetry-sdk",
13+
"opentelemetry-proto",
1314
"opentelemetry-exporter-otlp-proto-grpc",
1415
"opentelemetry-exporter-otlp-proto-http",
1516
"opentelemetry-propagator-b3",
@@ -76,69 +77,87 @@
7677
]
7778

7879

79-
def main():
80-
otel_python_version = os.environ.get("OTEL_PYTHON_VERSION")
81-
otel_contrib_version = os.environ.get("OTEL_CONTRIB_VERSION")
82-
aws_sdk_ext_version = os.environ.get("OPENTELEMETRY_SDK_EXTENSION_AWS_VERSION")
83-
aws_xray_prop_version = os.environ.get("OPENTELEMETRY_PROPAGATOR_AWS_XRAY_VERSION")
84-
85-
if not otel_python_version or not otel_contrib_version:
86-
print("Error: OTEL_PYTHON_VERSION and OTEL_CONTRIB_VERSION environment variables required")
87-
sys.exit(1)
88-
89-
if not aws_sdk_ext_version or not aws_xray_prop_version:
90-
print("Error: AWS dependency versions required")
91-
sys.exit(1)
92-
93-
pyproject_path = "aws-opentelemetry-distro/pyproject.toml"
94-
80+
def update_file_dependencies(file_path, otel_python_version, otel_contrib_version, aws_versions):
81+
"""Update all Otel dependencies in a given file"""
9582
try:
96-
with open(pyproject_path, "r", encoding="utf-8") as input_file:
83+
with open(file_path, "r", encoding="utf-8") as input_file:
9784
content = input_file.read()
9885

9986
updated = False
10087

10188
# Update opentelemetry-python dependencies
10289
for dep in PYTHON_CORE_DEPS:
103-
pattern = rf'"{re.escape(dep)} == [^"]*"'
104-
replacement = f'"{dep} == {otel_python_version}"'
90+
pattern = rf'{re.escape(dep)}==[^\s,\]"]*'
91+
replacement = f'{dep}=={otel_python_version}'
10592
if re.search(pattern, content):
10693
content = re.sub(pattern, replacement, content)
10794
updated = True
10895

10996
# Update opentelemetry-python-contrib dependencies
11097
for dep in CONTRIB_DEPS:
111-
pattern = rf'"{re.escape(dep)} == [^"]*"'
112-
replacement = f'"{dep} == {otel_contrib_version}"'
98+
pattern = rf'{re.escape(dep)}==[^\s,\]"]*'
99+
replacement = f'{dep}=={otel_contrib_version}'
113100
if re.search(pattern, content):
114101
content = re.sub(pattern, replacement, content)
115102
updated = True
116103

117-
# Update AWS dependencies with provided versions
118-
aws_versions = {
119-
"opentelemetry-sdk-extension-aws": aws_sdk_ext_version,
120-
"opentelemetry-propagator-aws-xray": aws_xray_prop_version,
121-
}
122-
104+
# Update independently versioned AWS dependencies
123105
for dep, version in aws_versions.items():
124106
if version:
125-
pattern = rf'"{re.escape(dep)} == [^"]*"'
126-
replacement = f'"{dep} == {version}"'
107+
pattern = rf'{re.escape(dep)}==[^\s,\]"]*'
108+
replacement = f'{dep}=={version}'
127109
if re.search(pattern, content):
128110
content = re.sub(pattern, replacement, content)
129111
updated = True
130112

131113
if updated:
132-
with open(pyproject_path, "w", encoding="utf-8") as output_file:
114+
with open(file_path, "w", encoding="utf-8") as output_file:
133115
output_file.write(content)
134-
print(f"Dependencies updated to Python {otel_python_version} / Contrib {otel_contrib_version}")
135-
else:
136-
print("No OpenTelemetry dependencies found to update")
116+
print(f"Updated {file_path}")
137117

118+
return updated
138119
except (OSError, IOError) as file_error:
139-
print(f"Error updating dependencies: {file_error}")
120+
print(f"Error updating {file_path}: {file_error}")
121+
return False
122+
123+
124+
def main():
125+
otel_python_version = os.environ.get("OTEL_PYTHON_VERSION")
126+
otel_contrib_version = os.environ.get("OTEL_CONTRIB_VERSION")
127+
aws_sdk_ext_version = os.environ.get("OPENTELEMETRY_SDK_EXTENSION_AWS_VERSION")
128+
aws_xray_prop_version = os.environ.get("OPENTELEMETRY_PROPAGATOR_AWS_XRAY_VERSION")
129+
130+
if not otel_python_version or not otel_contrib_version:
131+
print("Error: OTEL_PYTHON_VERSION and OTEL_CONTRIB_VERSION environment variables required")
140132
sys.exit(1)
141133

134+
if not aws_sdk_ext_version or not aws_xray_prop_version:
135+
print("Error: AWS dependency versions required")
136+
sys.exit(1)
137+
138+
aws_versions = {
139+
"opentelemetry-sdk-extension-aws": aws_sdk_ext_version,
140+
"opentelemetry-propagator-aws-xray": aws_xray_prop_version,
141+
}
142+
143+
# All files to update
144+
files_to_update = [
145+
"aws-opentelemetry-distro/pyproject.toml",
146+
"contract-tests/images/mock-collector/pyproject.toml",
147+
"contract-tests/images/mock-collector/requirements.txt",
148+
"contract-tests/tests/pyproject.toml",
149+
]
150+
151+
any_updated = False
152+
for file_path in files_to_update:
153+
if update_file_dependencies(file_path, otel_python_version, otel_contrib_version, aws_versions):
154+
any_updated = True
155+
156+
if any_updated:
157+
print(f"Dependencies updated to Python {otel_python_version} / Contrib {otel_contrib_version}")
158+
else:
159+
print("No OpenTelemetry dependencies found to update")
160+
142161

143162
if __name__ == "__main__":
144163
main()

0 commit comments

Comments
 (0)