doc: Reformat conf.py

This commit is contained in:
patrick96 2023-04-03 00:37:12 +02:00 committed by Patrick Ziegler
parent c6eb3f88ea
commit 98d58b6f27

View File

@ -19,49 +19,51 @@ import datetime
import sphinx import sphinx
import packaging.version import packaging.version
def get_version(root_path):
"""
Reads the polybar version from the version.txt at the root of the repo.
"""
path = Path(root_path) / "version.txt"
with open(path, "r") as f:
for line in f.readlines():
if not line.startswith("#"):
# NB: we can't parse it yet since sphinx could import
# pkg_resources later on and it could patch packaging.version
return line
raise RuntimeError("No version found in {}".format(path)) def get_version(root_path):
"""
Reads the polybar version from the version.txt at the root of the repo.
"""
path = Path(root_path) / "version.txt"
with open(path, "r") as f:
for line in f.readlines():
if not line.startswith("#"):
# NB: we can't parse it yet since sphinx could import
# pkg_resources later on and it could patch packaging.version
return line
raise RuntimeError("No version found in {}".format(path))
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'Polybar User Manual' project = 'Polybar User Manual'
copyright = '2016-{}, Michael Carlberg & contributors'.format( copyright = '2016-{}, Michael Carlberg & contributors'.format(
datetime.datetime.now().year datetime.datetime.now().year
) )
author = 'Polybar Team' author = 'Polybar Team'
# is whether we are on readthedocs.io # is whether we are on readthedocs.io
on_rtd = os.environ.get('READTHEDOCS', None) == 'True' on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if on_rtd: if on_rtd:
# On readthedocs, cmake isn't run so the version string isn't available # On readthedocs, cmake isn't run so the version string isn't available
version = os.environ.get('READTHEDOCS_VERSION', None) version = os.environ.get('READTHEDOCS_VERSION', None)
else: else:
# The short X.Y version # The short X.Y version
version = '@APP_VERSION@' version = '@APP_VERSION@'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = version release = version
# Set path to documentation # Set path to documentation
if on_rtd: if on_rtd:
# On readthedocs conf.py is already in the doc folder # On readthedocs conf.py is already in the doc folder
doc_path = '.' doc_path = '.'
else: else:
# In all other builds conf.py is configured with cmake and put into the # In all other builds conf.py is configured with cmake and put into the
# build folder. # build folder.
doc_path = '@doc_path@' doc_path = '@doc_path@'
# The version from the version.txt file. Since we are not always first # The version from the version.txt file. Since we are not always first
# configured by cmake, we don't necessarily have access to the current version # configured by cmake, we don't necessarily have access to the current version
@ -126,10 +128,10 @@ html_theme_options = {}
# a list of builtin themes. # a list of builtin themes.
# #
if on_rtd or os.environ.get('USE_RTD_THEME', '0') == '1': if on_rtd or os.environ.get('USE_RTD_THEME', '0') == '1':
html_theme = 'sphinx_rtd_theme' html_theme = 'sphinx_rtd_theme'
html_theme_options['collapse_navigation'] = False html_theme_options['collapse_navigation'] = False
else: else:
html_theme = 'alabaster' html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
@ -187,9 +189,18 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('man/polybar.1', 'polybar', 'A fast and easy-to-use tool status bar', [], 1), (
('man/polybar-msg.1', 'polybar-msg', 'Send IPC messages to polybar', [], 1), 'man/polybar.1', 'polybar',
('man/polybar.5', 'polybar', 'configuration file for polybar(1)', [], 5) 'A fast and easy-to-use tool status bar', [], 1
),
(
'man/polybar-msg.1', 'polybar-msg',
'Send IPC messages to polybar', [], 1
),
(
'man/polybar.5', 'polybar',
'configuration file for polybar(1)', [], 5
)
] ]
man_make_section_directory = False man_make_section_directory = False
@ -235,28 +246,30 @@ suppress_warnings = ['app.add_directive']
# is added to local builds. # is added to local builds.
if packaging.version.parse(sphinx.__version__) >= packaging.version.parse("1.8.5"): if packaging.version.parse(sphinx.__version__) >= packaging.version.parse("1.8.5"):
from typing import List from typing import List
from docutils.nodes import Node from docutils.nodes import Node
from sphinx.domains.changeset import VersionChange from sphinx.domains.changeset import VersionChange
def setup(app): def setup(app):
app.add_directive('deprecated', VersionDirective) app.add_directive('deprecated', VersionDirective)
app.add_directive('versionadded', VersionDirective) app.add_directive('versionadded', VersionDirective)
app.add_directive('versionchanged', VersionDirective) app.add_directive('versionchanged', VersionDirective)
sys.path.insert(0, os.path.abspath(doc_path)) sys.path.insert(0, os.path.abspath(doc_path))
from configdomain import myDomain from configdomain import myDomain
app.add_domain(myDomain) app.add_domain(myDomain)
class VersionDirective(VersionChange): class VersionDirective(VersionChange):
""" """
Overwrites the Sphinx directive for versionchanged, versionadded, and Overwrites the Sphinx directive for versionchanged, versionadded, and
deprecated and adds an unreleased tag to versions that are not yet released deprecated and adds an unreleased tag to versions that are not yet
""" released
def run(self) -> List[Node]: """
directive_version = packaging.version.parse(self.arguments[0])
parsed_version_txt = packaging.version.parse(version_txt)
if directive_version > parsed_version_txt: def run(self) -> List[Node]:
self.arguments[0] += " (unreleased)" directive_version = packaging.version.parse(self.arguments[0])
parsed_version_txt = packaging.version.parse(version_txt)
return super().run() if directive_version > parsed_version_txt:
self.arguments[0] += " (unreleased)"
return super().run()