Skip to content

Commit 7e4053a

Browse files
authored
toxgen: Detect correct sentry-sdk (#4558)
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. Closes #4556
1 parent 987824e commit 7e4053a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

scripts/generate-test-files.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ set -xe
66

77
cd "$(dirname "$0")"
88

9+
rm -rf toxgen.venv
910
python -m venv toxgen.venv
1011
. toxgen.venv/bin/activate
1112

12-
pip install -e ..
13-
pip install -r populate_tox/requirements.txt
14-
pip install -r split_tox_gh_actions/requirements.txt
13+
toxgen.venv/bin/pip install -e ..
14+
toxgen.venv/bin/pip install -r populate_tox/requirements.txt
15+
toxgen.venv/bin/pip install -r split_tox_gh_actions/requirements.txt
1516

16-
python populate_tox/populate_tox.py
17-
python split_tox_gh_actions/split_tox_gh_actions.py
17+
toxgen.venv/bin/python populate_tox/populate_tox.py
18+
toxgen.venv/bin/python split_tox_gh_actions/split_tox_gh_actions.py

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)