@@ -178,8 +178,24 @@ from setuptools_scm import get_version
178178version = get_version(root = ' ..' , relative_to = __file__ )
179179```
180180
181+ For legacy configurations or when working with extracted archives (like PyPI tarballs),
182+ you may need to specify a ` fallback_root ` parameter. This is particularly useful
183+ for legacy Sphinx configurations that use ` get_version() ` instead of getting the
184+ version from the installed package:
185+
186+ ``` python
187+ from setuptools_scm import get_version
188+ # For legacy Sphinx conf.py that needs to work both in development and from archives
189+ version = get_version(root = ' ..' , fallback_root = ' ..' , relative_to = __file__ )
190+ ```
191+
192+ The ` fallback_root ` parameter specifies the directory to use when the SCM metadata
193+ is not available (e.g., in extracted tarballs), while ` root ` is used when SCM
194+ metadata is present.
195+
181196### Usage from Sphinx
182197
198+ The recommended approach for Sphinx configurations is to use the installed package metadata:
183199
184200``` {.python file=docs/.entangled/sphinx_conf.py}
185201from importlib.metadata import version as get_version
@@ -192,6 +208,21 @@ The underlying reason is that services like *Read the Docs* sometimes change
192208the working directory for good reasons and using the installed metadata
193209prevents using needless volatile data there.
194210
211+ !!! note "Legacy Sphinx configurations"
212+
213+ If you have a legacy Sphinx configuration that still uses `setuptools_scm.get_version()`
214+ directly (instead of `importlib.metadata`), you may need to use the `fallback_root`
215+ parameter to ensure it works both in development and when building from archives:
216+
217+ ```python
218+ from setuptools_scm import get_version
219+ # Legacy approach - use fallback_root for archive compatibility
220+ release = get_version(root='..', fallback_root='..', relative_to=__file__)
221+ version = ".".join(release.split('.')[:2])
222+ ```
223+
224+ However, it's strongly recommended to migrate to the `importlib.metadata` approach above.
225+
195226
196227### With Docker/Podman
197228
0 commit comments