Skip to content

Commit

Permalink
Rename version.py files to version/__init__.py (#4099)
Browse files Browse the repository at this point in the history
* Rename version.py files to version/__init__.py

Fixes #4097

* Use a better variable name
  • Loading branch information
ocelotl authored Sep 25, 2024
1 parent f15821f commit cafd7f2
Show file tree
Hide file tree
Showing 34 changed files with 44 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/prepare-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install toml
run: pip install toml

- name: Create release branch
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
Expand Down Expand Up @@ -105,6 +108,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install toml
run: pip install toml

- name: Set environment variables
env:
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/error_handler/error_handler_0/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
error_handler_0 = "error_handler_0:ErrorHandler0"

[tool.hatch.version]
path = "src/error_handler_0/version.py"
path = "src/error_handler_0/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/error_handler/error_handler_1/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
error_handler_1 = "error_handler_1:ErrorHandler1"

[tool.hatch.version]
path = "src/error_handler_1/version.py"
path = "src/error_handler_1/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-opencensus/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ opencensus = "opentelemetry.exporter.opencensus.trace_exporter:OpenCensusSpanExp
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-opencensus"

[tool.hatch.version]
path = "src/opentelemetry/exporter/opencensus/version.py"
path = "src/opentelemetry/exporter/opencensus/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-common"

[tool.hatch.version]
path = "src/opentelemetry/exporter/otlp/proto/common/version.py"
path = "src/opentelemetry/exporter/otlp/proto/common/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpa
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-grpc"

[tool.hatch.version]
path = "src/opentelemetry/exporter/otlp/proto/grpc/version.py"
path = "src/opentelemetry/exporter/otlp/proto/grpc/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ otlp_proto_http = "opentelemetry.exporter.otlp.proto.http._log_exporter:OTLPLogE
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-http"

[tool.hatch.version]
path = "src/opentelemetry/exporter/otlp/proto/http/version.py"
path = "src/opentelemetry/exporter/otlp/proto/http/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-otlp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ otlp = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpanExporter"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp"

[tool.hatch.version]
path = "src/opentelemetry/exporter/otlp/version.py"
path = "src/opentelemetry/exporter/otlp/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-prometheus/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ prometheus = "opentelemetry.exporter.prometheus:_AutoPrometheusMetricReader"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-prometheus"

[tool.hatch.version]
path = "src/opentelemetry/exporter/prometheus/version.py"
path = "src/opentelemetry/exporter/prometheus/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-zipkin-json/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ zipkin_json = "opentelemetry.exporter.zipkin.json:ZipkinExporter"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin-json"

[tool.hatch.version]
path = "src/opentelemetry/exporter/zipkin/json/version.py"
path = "src/opentelemetry/exporter/zipkin/json/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ zipkin_proto = "opentelemetry.exporter.zipkin.proto.http:ZipkinExporter"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin-proto-http"

[tool.hatch.version]
path = "src/opentelemetry/exporter/zipkin/proto/http/version.py"
path = "src/opentelemetry/exporter/zipkin/proto/http/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion exporter/opentelemetry-exporter-zipkin/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ zipkin = "opentelemetry.exporter.zipkin.proto.http:ZipkinExporter"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-zipkin"

[tool.hatch.version]
path = "src/opentelemetry/exporter/zipkin/version.py"
path = "src/opentelemetry/exporter/zipkin/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion propagator/opentelemetry-propagator-b3/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ b3multi = "opentelemetry.propagators.b3:B3MultiFormat"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-b3"

[tool.hatch.version]
path = "src/opentelemetry/propagators/b3/version.py"
path = "src/opentelemetry/propagators/b3/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion propagator/opentelemetry-propagator-jaeger/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jaeger = "opentelemetry.propagators.jaeger:JaegerPropagator"
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/propagator/opentelemetry-propagator-jaeger"

[tool.hatch.version]
path = "src/opentelemetry/propagators/jaeger/version.py"
path = "src/opentelemetry/propagators/jaeger/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
30 changes: 22 additions & 8 deletions scripts/eachdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import subprocess
import sys
from toml import load
from configparser import ConfigParser
from inspect import cleandoc
from itertools import chain
Expand Down Expand Up @@ -554,14 +555,27 @@ def filter_packages(targets, packages):


def update_version_files(targets, version, packages):
print("updating version.py files")
targets = filter_packages(targets, packages)
update_files(
targets,
"version.py",
"__version__ .*",
f'__version__ = "{version}"',
)
print("updating version/__init__.py files")

search = "__version__ .*"
replace = f'__version__ = "{version}"'

for target in filter_packages(targets, packages):

version_file_path = target.joinpath(
load(target.joinpath("pyproject.toml"))
["tool"]["hatch"]["version"]["path"]
)

with open(version_file_path) as file:
text = file.read()

if replace in text:
print(f"{version_file_path} already contains {replace}")
continue

with open(version_file_path, "w", encoding="utf-8") as file:
file.write(re.sub(search, replace, text))


def update_dependencies(targets, version, packages):
Expand Down
2 changes: 1 addition & 1 deletion shim/opentelemetry-opencensus-shim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = [
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opencensus-shim"

[tool.hatch.version]
path = "src/opentelemetry/shim/opencensus/version.py"
path = "src/opentelemetry/shim/opencensus/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = ["/src", "/tests"]
Expand Down
2 changes: 1 addition & 1 deletion shim/opentelemetry-opentracing-shim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/shim/opentelemetry-opentracing-shim"

[tool.hatch.version]
path = "src/opentelemetry/shim/opentracing_shim/version.py"
path = "src/opentelemetry/shim/opentracing_shim/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down
2 changes: 1 addition & 1 deletion tests/opentelemetry-test-utils/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tests/opentelemetry-test-utils"

[tool.hatch.version]
path = "src/opentelemetry/test/version.py"
path = "src/opentelemetry/test/version/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
Expand Down

0 comments on commit cafd7f2

Please sign in to comment.