API Reference
Move some of your Sphinx configuration into pyproject.toml
.
Classes:
|
Read the Sphinx configuration from |
Parser for PEP 621 metadata from |
|
Parser for poetry metadata from |
-
class
SphinxConfig
(pyproject_file='../pyproject.toml', *, globalns=None, style='pep621', config_overrides=None)[source] -
Read the Sphinx configuration from
pyproject.toml
.- Parameters
pyproject_file (
Union
[str
,Path
,PathLike
]) – The path to thepyproject.toml
file. Default'../pyproject.toml'
.globalns (
Optional
[MutableMapping
]) – The global namespace of theconf.py
file. The variables parsed from the[tool.sphinx-pyproject]
table will be added to this namespace. By default, or if explicitlyNone
, this does not happen.style (
str
) – Eitherpep621
(default), orpoetry
to read configuration from the[tool.poetry]
table.config_overrides (
Optional
[MutableMapping
]) – Custom configuration overrides. This parameter can be used to dynamically update values frompyproject.toml
. This can be used to patch dynamic values likeversion
. By default, or if explicitlyNone
, no config updates are performed.
Changed in version 0.2.0: Added the
style
keyword argument.Changed in version 0.3.0: Added the
config_overrides
keyword argument.Attributes:
The value of the project.name key in the PEP 621 metadata.
The value of the project.version key in the PEP 621 metadata.
The value of the project.description key in the PEP 621 metadata.
A string giving the names of the authors.
Methods:
__getitem__
(item)Returns the value of the given key in the
tool.sphinx-pyproject
table.__len__
()Returns the number of keys in the
tool.sphinx-pyproject
table.__iter__
()Returns an iterator over the keys in the
tool.sphinx-pyproject
table.-
name
Type:
str
The value of the project.name key in the PEP 621 metadata.
Underscores are replaced by dashes but PEP 508 normalization is not applied.
The recommendation is to assign this to the project variable in
conf.py
:from sphinx_pyproject import SphinxConfig config = SphinxConfig() project = config.name
-
version
Type:
str
The value of the project.version key in the PEP 621 metadata.
Converted to a string if the value was a number in the
pyproject.toml
file.
-
description
Type:
str
The value of the project.description key in the PEP 621 metadata.
Type:
str
A string giving the names of the authors.
This is parsed from the project.authors key in the PEP 621 metadata, or the project.maintainers key as a fallback.
The names are joined together, e.g.:
# pyproject.toml [[project.authors]] name = "Dominic Davis-Foster" [[project.authors]] name = "Joe Bloggs" [[project.authors]] name = "Jane Doe"
>>> SphinxConfig("pyproject.toml").author 'Dominic Davis-Foster, Joe Bloggs and Jane Doe'
-
class
ProjectParser
[source] Bases:
AbstractConfigParser
Parser for PEP 621 metadata from
pyproject.toml
.Methods:
get_namespace
(filename, config)Returns the
[project]
table in aproject.toml
file.parse_name
(config)Parse the name key.
parse_version
(config)Parse the version key.
parse_description
(config)Parse the description key.
parse_author
(config)Parse the authors/maintainers key.
parse
(config[, set_defaults])Parse the TOML configuration.
-
static
get_namespace
(filename, config)[source] Returns the
[project]
table in aproject.toml
file.- Parameters
New in version 0.2.0.
-
parse_description
(config)[source] Parse the description key.
Parse the authors/maintainers key.
-
static
-
class
PoetryProjectParser
[source] Bases:
ProjectParser
Parser for poetry metadata from
pyproject.toml
.New in version 0.2.0.
Methods:
get_namespace
(filename, config)Returns the
[tool.poetry]
table in aproject.toml
file.parse_author
(config)Parse poetry’s authors key.