Skip to content

Commit 996b6bd

Browse files
Merge pull request #739 from RonnyPfannschmidt/fix-738-protect-relative-to
fix #738: protect relative_to of Configuration.from_file
2 parents 1b18371 + 12bf18e commit 996b6bd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
class PyProjectData(NamedTuple):
21+
name: str
2122
tool_name: str
2223
project: TOML_RESULT
2324
section: TOML_RESULT
@@ -48,7 +49,7 @@ def read_pyproject(
4849
except LookupError as e:
4950
raise LookupError(f"{name} does not contain a tool.{tool_name} section") from e
5051
project = defn.get("project", {})
51-
return PyProjectData(tool_name, project, section)
52+
return PyProjectData(name, tool_name, project, section)
5253

5354

5455
def get_args_for_pyproject(
@@ -59,7 +60,13 @@ def get_args_for_pyproject(
5960
"""drops problematic details and figures the distribution name"""
6061
section = pyproject.section.copy()
6162
kwargs = kwargs.copy()
62-
63+
if "relative_to" in section:
64+
relative = section.pop("relative_to")
65+
warnings.warn(
66+
f"{pyproject.name}: at [tool.{pyproject.tool_name}]\n"
67+
f"ignoring value relative_to={relative!r}"
68+
" as its always relative to the config file"
69+
)
6370
if "dist_name" in section:
6471
if dist_name is None:
6572
dist_name = section.pop("dist_name")

testing/test_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,26 @@ def test_config_regex_init() -> None:
5151
tag_regex = re.compile(r"v(\d+)")
5252
conf = Configuration(tag_regex=tag_regex)
5353
assert conf.tag_regex is tag_regex
54+
55+
56+
def test_config_from_file_protects_relative_to(tmp_path: Path) -> None:
57+
fn = tmp_path / "pyproject.toml"
58+
fn.write_text(
59+
textwrap.dedent(
60+
"""
61+
[tool.setuptools_scm]
62+
relative_to = "dont_use_me"
63+
[project]
64+
description = "Factory ⸻ A code generator 🏭"
65+
authors = [{name = "Łukasz Langa"}]
66+
"""
67+
),
68+
encoding="utf-8",
69+
)
70+
with pytest.warns(
71+
UserWarning,
72+
match=".*pyproject.toml: at \\[tool.setuptools_scm\\]\n"
73+
"ignoring value relative_to='dont_use_me'"
74+
" as its always relative to the config file",
75+
):
76+
assert Configuration.from_file(str(fn))

0 commit comments

Comments
 (0)