sphinx-toolbox / sphinx-pyproject

Move some of your Sphinx configuration into pyproject.toml
https://sphinx-pyproject.readthedocs.io/en/latest
MIT License
24 stars 6 forks source link

Let dynamic pyproject.toml values to be optionally allowed for version/etc #19

Open alinsavix opened 2 years ago

alinsavix commented 2 years ago

Description

Currently, I use setuptools_scm to determine the correct version number for my package, and write that version to a file in my module, after setting version to be dynamic.

e.g. in my pyproject.toml (irrelevant lines elided):

[build-system]
requires = [
    "setuptools_scm[toml]>=5",
]

[project]
dynamic = [ "version" ]

[tool.setuptools_scm]
write_to = "src/pkgname/_version.py"

...and then some quick stub code in my package's __init__.py:

from ._version import version as __version__

Currently, no matter what exists in my documentation's conf.py, attempting to initialize things via SphinxConfig() gives an error about version being unset or marked as dynamic.

What I'd like to be able to do is something like this in my conf.py (which is basically what I'm doing currently, minus sphinx-pyproject):

module_dir = os.path.join(__location__, "../src/pkgname")
from pkgname import __version__ as version

from sphinx_pyproject import SphinxConfig
config = SphinxConfig("../pyproject.toml", globalns=globals())

...and have it work, because "version" is already set in the global namespace. There's lots of ways to accomplish the same thing, though, e.g. SphynxConfig could take an extra argument, something like defaults={"version": version} or similar. Or simply have a flag that can be passed to it to indicate that it couldn't fail just because one of the expected values isn't there. It doesn't matter too much which way the problem is solved, as long as it's still possible to use sphinx-pyproject without a version number hardcoded in the pyproject.toml.

Thanks!

Version

garysb commented 2 years ago

Same issue when using PDM with version set to dynamic.

ghisvail commented 1 year ago

Same for flit-scm.

Support for dynamic version retrieval would be very welcome.

dyve commented 1 year ago

Same for Hatch.

Support for dynamic version retrieval or for skipping retrieval of version from pyproject.toml would be very welcome.

I noticed that this package only gets automated updates. Is it still being actively developed @domdfcoding?

domdfcoding commented 1 year ago

Are there any other usecases which aren't covered by #19, or can I close this now v0.3.0 is out?

christian-herber-nxp commented 8 months ago

Does anybody have a working example of pulling the version number used in sphinx from a git tag? I can't really find a comprehensive example, just snippets here and there. Would appreciate any pointer.

christian-herber-nxp commented 8 months ago

Does anybody have a working example of pulling the version number used in sphinx from a git tag? I can't really find a comprehensive example, just snippets here and there. Would appreciate any pointer.

In particular, the following is what bugs me:

when trying to retrieve the version with setuptool_scm in pyproject.toml, and setting dynamic = ["version"], I get the following Error:

dom_toml.parser.BadConfigError: Either 'version' was not declared in the 'project' table or it was marked as 'dynamic', which is unsupported by 'sphinx-pyproject

The PR linked in this issue does not seem to address this.