Repository: pypa/setuptools_scm

Issue:
Install pyarrow==11.0.0 --no-binary pyarrow fails
Hi, 

I tried to download the pyarrow package:

`pip download pyarrow==11.0.0 --no-binary pyarrow --no-deps`

Since version 8.0.0 (still with 8.0.2) I receive the following error:

` ERROR setuptools_scm._integration.setuptools pyproject.toml does not contain a tool.setuptools_scm section
      Traceback (most recent call last):
        File "/tmp/pip-build-env-x08ogq7b/overlay/lib/python3.8/site-packages/setuptools_scm/_integration/pyproject_reading.py", line 53, in read_pyproject
          section = defn.get("tool", {})[tool_name]
      KeyError: 'setuptools_scm'`

The problem does not occur if I force pyarrow to use version 7.1.0.

Discussion:

Patch:
diff --git a/changelog.d/20230922_200957_ronny_fix_925_turn_write_to_absolute_to_warning.md b/changelog.d/20230922_200957_ronny_fix_925_turn_write_to_absolute_to_warning.md
new file mode 100644
index 0000000..e7ecbfe
--- /dev/null
+++ b/changelog.d/20230922_200957_ronny_fix_925_turn_write_to_absolute_to_warning.md
@@ -0,0 +1,4 @@
+
+### Changed
+
+- fix #925: allow write_to to be a absolute path when it's a subdirectory of the root
diff --git a/src/setuptools_scm/_integration/dump_version.py b/src/setuptools_scm/_integration/dump_version.py
index 27c17b8..d890243 100644
--- a/src/setuptools_scm/_integration/dump_version.py
+++ b/src/setuptools_scm/_integration/dump_version.py
@@ -42,11 +42,19 @@ def dump_version(
     scm_version: ScmVersion | None = None,
 ) -> None:
     assert isinstance(version, str)
-    # todo: assert write_to doesnt escape
+    root = Path(root)
     write_to = Path(write_to)
-
-    assert not write_to.is_absolute(), f"{write_to=}"
-    target = Path(root).joinpath(write_to)
+    if write_to.is_absolute():
+        # trigger warning on escape
+        write_to.relative_to(root)
+        warnings.warn(
+            f"{write_to=!s} is a absolute path,"
+            " please switch to using a relative version file",
+            DeprecationWarning,
+        )
+        target = write_to
+    else:
+        target = Path(root).joinpath(write_to)
     write_version_to_path(
         target, template=template, version=version, scm_version=scm_version
     )


Test patch:
diff --git a/testing/test_regressions.py b/testing/test_regressions.py
index 6bd5246..e2594e8 100644
--- a/testing/test_regressions.py
+++ b/testing/test_regressions.py
@@ -3,6 +3,7 @@ from __future__ import annotations
 import pprint
 import subprocess
 import sys
+from dataclasses import replace
 from importlib.metadata import distribution
 from importlib.metadata import EntryPoint
 from pathlib import Path
@@ -13,6 +14,7 @@ from setuptools_scm import Configuration
 from setuptools_scm._run_cmd import run
 from setuptools_scm.git import parse
 from setuptools_scm.integration import data_from_mime
+from setuptools_scm.version import meta
 
 
 def test_data_from_mime_ignores_body() -> None:
@@ -104,3 +106,21 @@ def test_entrypoints_load() -> None:
             failed.append((ep, e))
     if failed:
         pytest.fail(pprint.pformat(failed))
+
+
+def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> None:
+    c = Configuration(root=tmp_path, write_to=tmp_path / "VERSION.py")
+    v = meta("1.0", config=c)
+    from setuptools_scm._get_version_impl import write_version_files
+
+    with pytest.warns(DeprecationWarning, match=".*write_to=.* is a absolute.*"):
+        write_version_files(c, "1.0", v)
+    write_version_files(replace(c, write_to="VERSION.py"), "1.0", v)
+    subdir = tmp_path / "subdir"
+    subdir.mkdir()
+    with pytest.raises(
+        # todo: python version specific error list
+        ValueError,
+        match=".*VERSION.py' .* .*subdir.*",
+    ):
+        write_version_files(replace(c, root=subdir), "1.0", v)