def test_empty_authors(tmp_pathplus: PathPlus):
    minimum = "[project]\nname = 'foo'\nversion = '1.2.3'\ndescription = 'Description'"

    (tmp_pathplus / "pyproject.toml"
     ).write_text(f"{minimum}\n[[project.authors]]\nemail = '*****@*****.**'")

    with pytest.raises(BadConfigError,
                       match="The 'project.authors' key cannot be empty."):
        SphinxConfig(tmp_pathplus / "pyproject.toml")
def test_missing_keys(tmp_pathplus: PathPlus, config: str):
    (tmp_pathplus / "pyproject.toml").write_text(config)

    err = (
        "Either '.*' was not declared in the 'project' table "
        "or it was marked as 'dynamic', which is unsupported by 'sphinx-pyproject'."
    )

    with pytest.raises(BadConfigError, match=err):
        SphinxConfig(tmp_pathplus / "pyproject.toml")
def test_parse_config(
    tmp_pathplus: PathPlus,
    config: str,
    size: int,
    advanced_data_regression: AdvancedDataRegressionFixture,
):
    (tmp_pathplus / "pyproject.toml").write_text(config)

    loaded_config = SphinxConfig(tmp_pathplus / "pyproject.toml")
    advanced_data_regression.check(loaded_config)
    assert len(loaded_config) == size
def test_authors_commas(tmp_pathplus: PathPlus):
    minimum = "[project]\nname = 'foo'\nversion = '1.2.3'\ndescription = 'Description'"

    (tmp_pathplus / "pyproject.toml").write_text(
        f"{minimum}\n[[project.authors]]\nname = 'Bob, Alice and Claire'")

    with pytest.raises(
            BadConfigError,
            match=r"The 'project.authors\[0\].name' key cannot contain commas."
    ):
        SphinxConfig(tmp_pathplus / "pyproject.toml")
def test_parse_our_config(
        advanced_data_regression: AdvancedDataRegressionFixture):
    globalns: Dict[str, Any] = {}

    config = SphinxConfig(root_dir / "pyproject.toml", globalns=globalns)

    assert config.name == "sphinx-pyproject"
    assert config.author == "Dominic Davis-Foster"
    assert config.version == __version__
    assert config.description == "Move some of your Sphinx configuration into pyproject.toml"

    assert config["language"] == "en"
    assert config["package_root"] == "sphinx_pyproject"
    assert config["github_repository"] == "sphinx-pyproject"
    assert config["sphinxemoji_style"] == "twemoji"
    assert config["templates_path"] == ["_templates"]
    assert config["add_module_names"] is False
    assert "html_theme_options" not in config

    advanced_data_regression.check(globalns)
예제 #6
0
#!/usr/bin/env python3

# This file is managed by 'repo_helper'. Don't edit it directly.

# stdlib
import os
import re
import sys

# 3rd party
from sphinx_pyproject import SphinxConfig

sys.path.append('.')

config = SphinxConfig(globalns=globals())
project = config["project"]
author = config["author"]
documentation_summary = config.description

github_url = "https://github.com/{github_username}/{github_repository}".format_map(
    config)

rst_prolog = f""".. |pkgname| replace:: py2LaTeX
.. |pkgname2| replace:: ``py2LaTeX``
.. |browse_github| replace:: `Browse the GitHub Repository <{github_url}>`__
"""

slug = re.sub(r'\W+', '-', project.lower())
release = version = config.version

todo_include_todos = bool(os.environ.get("SHOW_TODOS", 0))
예제 #7
0
#!/usr/bin/env python3

# This file is managed by 'repo_helper'. Don't edit it directly.

# stdlib
import os
import re

# 3rd party
from sphinx_pyproject import SphinxConfig

config = SphinxConfig()

github_username = "******"
github_repository = "repo_helper_sphinx_theme"
author = "Dominic Davis-Foster"
project = "repo-helper Theme"
copyright = "2020 Dominic Davis-Foster"
language = "en"
package_root = "repo_helper_sphinx_theme"
extensions = [
    "sphinx_toolbox",
    "sphinx_toolbox.more_autodoc",
    "sphinx_toolbox.more_autosummary",
    "sphinx_toolbox.documentation_summary",
    "sphinx_toolbox.tweaks.param_dash",
    "sphinx_toolbox.tweaks.latex_toc",
    "sphinx.ext.intersphinx",
    "sphinx.ext.mathjax",
    "sphinxcontrib.httpdomain",
    "sphinxcontrib.extras_require",
def test_empty_config(tmp_pathplus: PathPlus):
    (tmp_pathplus / "pyproject.toml").touch()

    with pytest.raises(BadConfigError, match="No 'project' table found in .*"):
        SphinxConfig(tmp_pathplus / "pyproject.toml")
예제 #9
0
# Configuration file for the Sphinx documentation builder.
from __future__ import annotations

import datetime as dt
import os
import sys

from sphinx_pyproject import SphinxConfig

root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Add project root directory to module search paths
sys.path.insert(0, os.path.join(root_dir, "src"))

# Loan configurations from pyproject.toml
name = None  # will be populated by SphinxConfig
author = None  # will be populated by SphinxConfig
version = None  # will be populated by SphinxConfig
config = SphinxConfig(os.path.join(root_dir, "pyproject.toml"),
                      globalns=globals())

# Additional configurations
project = name
project_copyright = f"{dt.date.today().year}, {author} ({version})"
release = version

# Sphinx plugins configurations
autosectionlabel_prefix_document = True
autodoc_member_order = 'bysource'
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}