Skip to content

Commit cafd7f2

Browse files
authored
Rename version.py files to version/__init__.py (#4099)
* Rename version.py files to version/__init__.py Fixes #4097 * Use a better variable name
1 parent f15821f commit cafd7f2

File tree

34 files changed

+44
-24
lines changed

34 files changed

+44
-24
lines changed

.github/workflows/prepare-release-branch.yml

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v4
4343

44+
- name: Install toml
45+
run: pip install toml
46+
4447
- name: Create release branch
4548
env:
4649
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
@@ -105,6 +108,9 @@ jobs:
105108
steps:
106109
- uses: actions/checkout@v4
107110

111+
- name: Install toml
112+
run: pip install toml
113+
108114
- name: Set environment variables
109115
env:
110116
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}

docs/examples/error_handler/error_handler_0/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
error_handler_0 = "error_handler_0:ErrorHandler0"
3333

3434
[tool.hatch.version]
35-
path = "src/error_handler_0/version.py"
35+
path = "src/error_handler_0/version/__init__.py"
3636

3737
[tool.hatch.build.targets.sdist]
3838
include = [

docs/examples/error_handler/error_handler_1/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
error_handler_1 = "error_handler_1:ErrorHandler1"
3333

3434
[tool.hatch.version]
35-
path = "src/error_handler_1/version.py"
35+
path = "src/error_handler_1/version/__init__.py"
3636

3737
[tool.hatch.build.targets.sdist]
3838
include = [

exporter/opentelemetry-exporter-opencensus/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ opencensus = "opentelemetry.exporter.opencensus.trace_exporter:OpenCensusSpanExp
4343
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-opencensus"
4444

4545
[tool.hatch.version]
46-
path = "src/opentelemetry/exporter/opencensus/version.py"
46+
path = "src/opentelemetry/exporter/opencensus/version/__init__.py"
4747

4848
[tool.hatch.build.targets.sdist]
4949
include = [

exporter/opentelemetry-exporter-otlp-proto-common/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-common"
3535

3636
[tool.hatch.version]
37-
path = "src/opentelemetry/exporter/otlp/proto/common/version.py"
37+
path = "src/opentelemetry/exporter/otlp/proto/common/version/__init__.py"
3838

3939
[tool.hatch.build.targets.sdist]
4040
include = [

exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpa
4949
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-grpc"
5050

5151
[tool.hatch.version]
52-
path = "src/opentelemetry/exporter/otlp/proto/grpc/version.py"
52+
path = "src/opentelemetry/exporter/otlp/proto/grpc/version/__init__.py"
5353

5454
[tool.hatch.build.targets.sdist]
5555
include = [

exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ otlp_proto_http = "opentelemetry.exporter.otlp.proto.http._log_exporter:OTLPLogE
4949
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-http"
5050

5151
[tool.hatch.version]
52-
path = "src/opentelemetry/exporter/otlp/proto/http/version.py"
52+
path = "src/opentelemetry/exporter/otlp/proto/http/version/__init__.py"
5353

5454
[tool.hatch.build.targets.sdist]
5555
include = [

exporter/opentelemetry-exporter-otlp/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ otlp = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpanExporter"
4545
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp"
4646

4747
[tool.hatch.version]
48-
path = "src/opentelemetry/exporter/otlp/version.py"
48+
path = "src/opentelemetry/exporter/otlp/version/__init__.py"
4949

5050
[tool.hatch.build.targets.sdist]
5151
include = [

exporter/opentelemetry-exporter-prometheus/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ prometheus = "opentelemetry.exporter.prometheus:_AutoPrometheusMetricReader"
4040
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-prometheus"
4141

4242
[tool.hatch.version]
43-
path = "src/opentelemetry/exporter/prometheus/version.py"
43+
path = "src/opentelemetry/exporter/prometheus/version/__init__.py"
4444

4545
[tool.hatch.build.targets.sdist]
4646
include = [

exporter/opentelemetry-exporter-zipkin-json/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ zipkin_json = "opentelemetry.exporter.zipkin.json:ZipkinExporter"
4040
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin-json"
4141

4242
[tool.hatch.version]
43-
path = "src/opentelemetry/exporter/zipkin/json/version.py"
43+
path = "src/opentelemetry/exporter/zipkin/json/version/__init__.py"
4444

4545
[tool.hatch.build.targets.sdist]
4646
include = [

exporter/opentelemetry-exporter-zipkin-proto-http/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ zipkin_proto = "opentelemetry.exporter.zipkin.proto.http:ZipkinExporter"
4242
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin-proto-http"
4343

4444
[tool.hatch.version]
45-
path = "src/opentelemetry/exporter/zipkin/proto/http/version.py"
45+
path = "src/opentelemetry/exporter/zipkin/proto/http/version/__init__.py"
4646

4747
[tool.hatch.build.targets.sdist]
4848
include = [

exporter/opentelemetry-exporter-zipkin/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ zipkin = "opentelemetry.exporter.zipkin.proto.http:ZipkinExporter"
3939
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin"
4040

4141
[tool.hatch.version]
42-
path = "src/opentelemetry/exporter/zipkin/version.py"
42+
path = "src/opentelemetry/exporter/zipkin/version/__init__.py"
4343

4444
[tool.hatch.build.targets.sdist]
4545
include = [

propagator/opentelemetry-propagator-b3/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ b3multi = "opentelemetry.propagators.b3:B3MultiFormat"
3939
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-b3"
4040

4141
[tool.hatch.version]
42-
path = "src/opentelemetry/propagators/b3/version.py"
42+
path = "src/opentelemetry/propagators/b3/version/__init__.py"
4343

4444
[tool.hatch.build.targets.sdist]
4545
include = [

propagator/opentelemetry-propagator-jaeger/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jaeger = "opentelemetry.propagators.jaeger:JaegerPropagator"
3737
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-jaeger"
3838

3939
[tool.hatch.version]
40-
path = "src/opentelemetry/propagators/jaeger/version.py"
40+
path = "src/opentelemetry/propagators/jaeger/version/__init__.py"
4141

4242
[tool.hatch.build.targets.sdist]
4343
include = [

scripts/eachdist.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import subprocess
99
import sys
10+
from toml import load
1011
from configparser import ConfigParser
1112
from inspect import cleandoc
1213
from itertools import chain
@@ -554,14 +555,27 @@ def filter_packages(targets, packages):
554555

555556

556557
def update_version_files(targets, version, packages):
557-
print("updating version.py files")
558-
targets = filter_packages(targets, packages)
559-
update_files(
560-
targets,
561-
"version.py",
562-
"__version__ .*",
563-
f'__version__ = "{version}"',
564-
)
558+
print("updating version/__init__.py files")
559+
560+
search = "__version__ .*"
561+
replace = f'__version__ = "{version}"'
562+
563+
for target in filter_packages(targets, packages):
564+
565+
version_file_path = target.joinpath(
566+
load(target.joinpath("pyproject.toml"))
567+
["tool"]["hatch"]["version"]["path"]
568+
)
569+
570+
with open(version_file_path) as file:
571+
text = file.read()
572+
573+
if replace in text:
574+
print(f"{version_file_path} already contains {replace}")
575+
continue
576+
577+
with open(version_file_path, "w", encoding="utf-8") as file:
578+
file.write(re.sub(search, replace, text))
565579

566580

567581
def update_dependencies(targets, version, packages):

shim/opentelemetry-opencensus-shim/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies = [
3939
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opencensus-shim"
4040

4141
[tool.hatch.version]
42-
path = "src/opentelemetry/shim/opencensus/version.py"
42+
path = "src/opentelemetry/shim/opencensus/version/__init__.py"
4343

4444
[tool.hatch.build.targets.sdist]
4545
include = ["/src", "/tests"]

shim/opentelemetry-opentracing-shim/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opentracing-shim"
3737

3838
[tool.hatch.version]
39-
path = "src/opentelemetry/shim/opentracing_shim/version.py"
39+
path = "src/opentelemetry/shim/opentracing_shim/version/__init__.py"
4040

4141
[tool.hatch.build.targets.sdist]
4242
include = [

tests/opentelemetry-test-utils/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies = [
3535
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tests/opentelemetry-test-utils"
3636

3737
[tool.hatch.version]
38-
path = "src/opentelemetry/test/version.py"
38+
path = "src/opentelemetry/test/version/__init__.py"
3939

4040
[tool.hatch.build.targets.sdist]
4141
include = [

0 commit comments

Comments
 (0)