Skip to content

Commit 3fe55e8

Browse files
committed
toxgen: Detect correct sentry-sdk
Sometimes after switching branches, importlib.metadata(sentry-sdk) would point to the wrong metadata (SDK 2.x instead of 3.x), which in turn meant toxgen would think the SDK supports different Python versions than it should.
1 parent 987824e commit 3fe55e8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/populate_tox/populate_tox.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bisect import bisect_left
1111
from collections import defaultdict
1212
from datetime import datetime, timedelta, timezone # noqa: F401
13-
from importlib.metadata import metadata
13+
from importlib.metadata import PackageMetadata, distributions
1414
from packaging.specifiers import SpecifierSet
1515
from packaging.version import Version
1616
from pathlib import Path
@@ -88,6 +88,13 @@
8888
}
8989

9090

91+
def _fetch_sdk_metadata() -> PackageMetadata:
92+
(dist,) = distributions(
93+
name="sentry-sdk", path=[Path(__file__).parent.parent.parent]
94+
)
95+
return dist.metadata
96+
97+
9198
def fetch_url(url: str) -> Optional[dict]:
9299
for attempt in range(3):
93100
pypi_data = requests.get(url)
@@ -583,8 +590,9 @@ def main(fail_on_changes: bool = False) -> None:
583590
)
584591

585592
global MIN_PYTHON_VERSION, MAX_PYTHON_VERSION
593+
meta = _fetch_sdk_metadata()
586594
sdk_python_versions = _parse_python_versions_from_classifiers(
587-
metadata("sentry-sdk").get_all("Classifier")
595+
meta.get_all("Classifier")
588596
)
589597
MIN_PYTHON_VERSION = sdk_python_versions[0]
590598
MAX_PYTHON_VERSION = sdk_python_versions[-1]

0 commit comments

Comments
 (0)