File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
src/setuptools_scm/_integration Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+
4
+ ## v9.2.0
5
+
6
+ ### fixed
7
+
8
+ - fix #1216 : accept and create a warning for usages of ` version = attr: ` in setuptools config.
9
+ unfortunately dozens of projects cargo-culted that antipattern
10
+
11
+
3
12
## v9.2.0
4
13
5
14
### Added
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import os
4
+ import warnings
4
5
5
6
from dataclasses import dataclass
6
7
from pathlib import Path
@@ -25,6 +26,12 @@ def read_setup_cfg(input: str | os.PathLike[str] = "setup.cfg") -> SetuptoolsBas
25
26
26
27
name = parser .get ("metadata" , "name" , fallback = None )
27
28
version = parser .get ("metadata" , "version" , fallback = None )
29
+ if version is not None and "attr" in version :
30
+ warnings .warn (
31
+ "setup.cfg: ignoring invalid dynamic version - version = attr: ..."
32
+ " is sabotaging setuptools-scm"
33
+ )
34
+ version = None
28
35
return SetuptoolsBasicData (path = path , name = name , version = version )
29
36
30
37
Original file line number Diff line number Diff line change 18
18
from setuptools_scm ._integration import setuptools as setuptools_integration
19
19
from setuptools_scm ._integration .pyproject_reading import PyProjectData
20
20
from setuptools_scm ._integration .setup_cfg import SetuptoolsBasicData
21
+ from setuptools_scm ._integration .setup_cfg import read_setup_cfg
21
22
from setuptools_scm ._requirement_cls import extract_package_name
22
23
23
24
if TYPE_CHECKING :
@@ -457,6 +458,29 @@ def test_unicode_in_setup_cfg(tmp_path: Path) -> None:
457
458
assert data .version == "1.2.3"
458
459
459
460
461
+ @pytest .mark .issue (1216 )
462
+ def test_setup_cfg_dynamic_version_warns_and_ignores (tmp_path : Path ) -> None :
463
+ cfg = tmp_path / "setup.cfg"
464
+ cfg .write_text (
465
+ textwrap .dedent (
466
+ """
467
+ [metadata]
468
+ name = example-broken
469
+ version = attr: example_broken.__version__
470
+ """
471
+ ),
472
+ encoding = "utf-8" ,
473
+ )
474
+
475
+ with pytest .warns (
476
+ UserWarning ,
477
+ match = "setup.cfg: ignoring invalid dynamic version - version = attr: ... is sabotaging setuptools-scm" ,
478
+ ):
479
+ legacy_data = read_setup_cfg (cfg )
480
+
481
+ assert legacy_data .version is None
482
+
483
+
460
484
def test_setup_cfg_version_prevents_inference_version_keyword (
461
485
tmp_path : Path , monkeypatch : pytest .MonkeyPatch
462
486
) -> None :
You can’t perform that action at this time.
0 commit comments