1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
from __future__ import annotations
import re
import textwrap
from pathlib import Path
import pytest
from setuptools_scm import Configuration
@pytest.mark.parametrize(
"tag, expected_version",
[
("apache-arrow-0.9.0", "0.9.0"),
("arrow-0.9.0", "0.9.0"),
("arrow-0.9.0-rc", "0.9.0-rc"),
("arrow-1", "1"),
("arrow-1+", "1"),
("arrow-1+foo", "1"),
("arrow-1.1+foo", "1.1"),
("v1.1", "v1.1"),
("V1.1", "V1.1"),
],
)
def test_tag_regex(tag: str, expected_version: str) -> None:
config = Configuration()
match = config.tag_regex.match(tag)
assert match
version = match.group("version")
assert version == expected_version
def test_config_from_pyproject(tmp_path: Path) -> None:
fn = tmp_path / "pyproject.toml"
fn.write_text(
textwrap.dedent(
"""
[tool.setuptools_scm]
[project]
description = "Factory ⸻ A code generator 🏭"
authors = [{name = "Łukasz Langa"}]
"""
),
encoding="utf-8",
)
assert Configuration.from_file(str(fn))
def test_config_regex_init() -> None:
tag_regex = re.compile(r"v(\d+)")
conf = Configuration(tag_regex=tag_regex)
assert conf.tag_regex is tag_regex
def test_config_from_file_protects_relative_to(tmp_path: Path) -> None:
fn = tmp_path / "pyproject.toml"
fn.write_text(
textwrap.dedent(
"""
[tool.setuptools_scm]
relative_to = "dont_use_me"
[project]
description = "Factory ⸻ A code generator 🏭"
authors = [{name = "Łukasz Langa"}]
"""
),
encoding="utf-8",
)
with pytest.warns(
UserWarning,
match=".*pyproject.toml: at \\[tool.setuptools_scm\\]\n"
"ignoring value relative_to='dont_use_me'"
" as its always relative to the config file",
):
assert Configuration.from_file(str(fn))
def test_config_overrides(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
fn = tmp_path / "pyproject.toml"
fn.write_text(
textwrap.dedent(
"""
[tool.setuptools_scm]
root = "."
[project]
name = "test_a"
"""
),
encoding="utf-8",
)
pristine = Configuration.from_file(fn)
monkeypatch.setenv(
"SETUPTOOLS_SCM_OVERRIDES_FOR_TEST_A", '{root="..", fallback_root=".."}'
)
overriden = Configuration.from_file(fn)
assert pristine.root != overriden.root
assert pristine.fallback_root != overriden.fallback_root
|