Skip to content

Commit 0c1fbe3

Browse files
committed
collector.VERSION constant from pyproject.toml via importlib.metadata
So that there's a single source of truth again; prior to uv the setup.py file was loading the version from the constant... now we're doing it the other way around.
1 parent 10625ca commit 0c1fbe3

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/buildkite_test_collector/collector/constants.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,16 @@
22

33
"""This module defines collector-level constants."""
44

5-
COLLECTOR_NAME='buildkite-test-collector'
6-
VERSION='1.0.4'
5+
DISTRIBUTION_NAME = 'buildkite-test-collector'
6+
COLLECTOR_NAME = f"python-{DISTRIBUTION_NAME}"
7+
8+
try:
9+
from importlib.metadata import version, PackageNotFoundError
10+
try:
11+
VERSION = version(DISTRIBUTION_NAME)
12+
except PackageNotFoundError:
13+
# Fallback for development environments where package isn't installed
14+
VERSION = 'dev'
15+
except ImportError:
16+
# Fallback for edge cases
17+
VERSION = 'unknown'

src/buildkite_test_collector/collector/run_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Dict, Optional, Mapping
66
from uuid import uuid4
77

8-
from .constants import COLLECTOR_NAME, VERSION # pylint: disable=W0611
8+
from .constants import COLLECTOR_NAME, VERSION
99

1010
# pylint: disable=too-few-public-methods
1111
class RunEnvBuilder:
@@ -140,7 +140,7 @@ def as_json(self) -> Dict[str, str]:
140140
"commit_sha": self.commit_sha,
141141
"message": self.message,
142142
"url": self.url,
143-
"collector": f"python-{COLLECTOR_NAME}",
143+
"collector": COLLECTOR_NAME,
144144
"version": VERSION,
145145
"language_version": f"{platform.python_version()}"
146146
}

tests/buildkite_test_collector/collector/test_run_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from uuid import uuid4, UUID
44

55
from buildkite_test_collector.collector.constants import VERSION
6-
from buildkite_test_collector.collector.run_env import RunEnv, RunEnvBuilder
6+
from buildkite_test_collector.collector.run_env import RunEnvBuilder
77

88

99
def test_detect_env_with_buildkite_api_env_vars_returns_the_correct_environment():

0 commit comments

Comments
 (0)