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
1 changed files with 62 additions and 49 deletions

View File

@ -19,49 +19,51 @@ import datetime
import sphinx
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 = 'Polybar User Manual'
copyright = '2016-{}, Michael Carlberg & contributors'.format(
datetime.datetime.now().year
)
)
author = 'Polybar Team'
# is whether we are on readthedocs.io
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if on_rtd:
# On readthedocs, cmake isn't run so the version string isn't available
version = os.environ.get('READTHEDOCS_VERSION', None)
# On readthedocs, cmake isn't run so the version string isn't available
version = os.environ.get('READTHEDOCS_VERSION', None)
else:
# The short X.Y version
version = '@APP_VERSION@'
# The short X.Y version
version = '@APP_VERSION@'
# The full version, including alpha/beta/rc tags
release = version
# Set path to documentation
if on_rtd:
# On readthedocs conf.py is already in the doc folder
doc_path = '.'
# On readthedocs conf.py is already in the doc folder
doc_path = '.'
else:
# In all other builds conf.py is configured with cmake and put into the
# build folder.
doc_path = '@doc_path@'
# In all other builds conf.py is configured with cmake and put into the
# build folder.
doc_path = '@doc_path@'
# 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
@ -126,10 +128,10 @@ html_theme_options = {}
# a list of builtin themes.
#
if on_rtd or os.environ.get('USE_RTD_THEME', '0') == '1':
html_theme = 'sphinx_rtd_theme'
html_theme_options['collapse_navigation'] = False
html_theme = 'sphinx_rtd_theme'
html_theme_options['collapse_navigation'] = False
else:
html_theme = 'alabaster'
html_theme = 'alabaster'
# 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,
@ -187,9 +189,18 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
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.5', 'polybar', 'configuration file for polybar(1)', [], 5)
(
'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.5', 'polybar',
'configuration file for polybar(1)', [], 5
)
]
man_make_section_directory = False
@ -235,28 +246,30 @@ suppress_warnings = ['app.add_directive']
# is added to local builds.
if packaging.version.parse(sphinx.__version__) >= packaging.version.parse("1.8.5"):
from typing import List
from docutils.nodes import Node
from sphinx.domains.changeset import VersionChange
from typing import List
from docutils.nodes import Node
from sphinx.domains.changeset import VersionChange
def setup(app):
app.add_directive('deprecated', VersionDirective)
app.add_directive('versionadded', VersionDirective)
app.add_directive('versionchanged', VersionDirective)
sys.path.insert(0, os.path.abspath(doc_path))
from configdomain import myDomain
app.add_domain(myDomain)
def setup(app):
app.add_directive('deprecated', VersionDirective)
app.add_directive('versionadded', VersionDirective)
app.add_directive('versionchanged', VersionDirective)
sys.path.insert(0, os.path.abspath(doc_path))
from configdomain import myDomain
app.add_domain(myDomain)
class VersionDirective(VersionChange):
"""
Overwrites the Sphinx directive for versionchanged, versionadded, and
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)
class VersionDirective(VersionChange):
"""
Overwrites the Sphinx directive for versionchanged, versionadded, and
deprecated and adds an unreleased tag to versions that are not yet
released
"""
if directive_version > parsed_version_txt:
self.arguments[0] += " (unreleased)"
def run(self) -> List[Node]:
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()