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 11# Changelog
22
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+
312## v9.2.0
413
514### Added
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import os
4+ import warnings
45
56from dataclasses import dataclass
67from pathlib import Path
@@ -25,6 +26,12 @@ def read_setup_cfg(input: str | os.PathLike[str] = "setup.cfg") -> SetuptoolsBas
2526
2627 name = parser .get ("metadata" , "name" , fallback = None )
2728 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
2835 return SetuptoolsBasicData (path = path , name = name , version = version )
2936
3037
Original file line number Diff line number Diff line change 1818from setuptools_scm ._integration import setuptools as setuptools_integration
1919from setuptools_scm ._integration .pyproject_reading import PyProjectData
2020from setuptools_scm ._integration .setup_cfg import SetuptoolsBasicData
21+ from setuptools_scm ._integration .setup_cfg import read_setup_cfg
2122from setuptools_scm ._requirement_cls import extract_package_name
2223
2324if TYPE_CHECKING :
@@ -457,6 +458,29 @@ def test_unicode_in_setup_cfg(tmp_path: Path) -> None:
457458 assert data .version == "1.2.3"
458459
459460
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+
460484def test_setup_cfg_version_prevents_inference_version_keyword (
461485 tmp_path : Path , monkeypatch : pytest .MonkeyPatch
462486) -> None :
You can’t perform that action at this time.
0 commit comments