diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2022-07-01 12:21:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 12:21:24 +0200 |
commit | 996b6bdfbeb0201e02139c7b47ba6fa01c1a6ce9 (patch) | |
tree | 6047a842543e11ebdbd8173c59981b2068b65edd | |
parent | 1b18371fc2fa672f39c758a103c4d12956b5964f (diff) | |
parent | 12bf18e6c39c8f3563aa5948b817eb31cc6b9859 (diff) | |
download | setuptools-scm-7.0.4.tar.gz |
Merge pull request #739 from RonnyPfannschmidt/fix-738-protect-relative-tov7.0.4
fix #738: protect relative_to of Configuration.from_file
-rw-r--r-- | src/setuptools_scm/_integration/pyproject_reading.py | 11 | ||||
-rw-r--r-- | testing/test_config.py | 23 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/setuptools_scm/_integration/pyproject_reading.py b/src/setuptools_scm/_integration/pyproject_reading.py index cd7149d..f43e6b1 100644 --- a/src/setuptools_scm/_integration/pyproject_reading.py +++ b/src/setuptools_scm/_integration/pyproject_reading.py @@ -18,6 +18,7 @@ TOML_LOADER: TypeAlias = Callable[[str], TOML_RESULT] class PyProjectData(NamedTuple): + name: str tool_name: str project: TOML_RESULT section: TOML_RESULT @@ -48,7 +49,7 @@ def read_pyproject( except LookupError as e: raise LookupError(f"{name} does not contain a tool.{tool_name} section") from e project = defn.get("project", {}) - return PyProjectData(tool_name, project, section) + return PyProjectData(name, tool_name, project, section) def get_args_for_pyproject( @@ -59,7 +60,13 @@ def get_args_for_pyproject( """drops problematic details and figures the distribution name""" section = pyproject.section.copy() kwargs = kwargs.copy() - + if "relative_to" in section: + relative = section.pop("relative_to") + warnings.warn( + f"{pyproject.name}: at [tool.{pyproject.tool_name}]\n" + f"ignoring value relative_to={relative!r}" + " as its always relative to the config file" + ) if "dist_name" in section: if dist_name is None: dist_name = section.pop("dist_name") diff --git a/testing/test_config.py b/testing/test_config.py index d7aa3f4..97bb36e 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -51,3 +51,26 @@ 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)) |