Debian Codegraph @

cloud_sptheme/__init__.py

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 """
2 This module contains a few small sphinx extensions.
3 They are mainly used to help with the generation
4 of BPS's own documentation, but some other projects
5 use them as well, so they are kept here.
6 """
7 #=============================================================================
8 # imports
9 #=============================================================================
10 # core
11 import re
12 import os.path
13 from warnings import warn
14 # site
15 # WARNING: since this is imported by setup.py, it's critical the toplevel
16 # not depend on any imports outside of stdlib & setuptools
17 # local
18 __all__ = [
19 # constants
20 "__version__",
21 "std_exts",
22 "all_exts",
23
24 # theme setup
25 "get_theme_dir", # deprecated
26 # "_iter_theme_sources()", # used by setup.py
27 # "setup", # used by sphinx.html_theme entrypoint
28
29 # public helpers
30 "get_version",
31
32 # internal helpers
33 "is_cloud_theme",
34 ]
35
36 #=============================================================================
37 # constants
38 #=============================================================================
39
40 #: canonical version string
41 __version__ = '1.10.1.post20200504175005'
42
43 #: names of standard cloud extensions used by most cloud themes
44 std_exts = [
45 'cloud_sptheme.ext.autodoc_sections',
46 'cloud_sptheme.ext.autoattribute_search_bases',
47 'cloud_sptheme.ext.docfield_markup',
48 'cloud_sptheme.ext.escaped_samp_literals',
49 'cloud_sptheme.ext.index_styling',
50 'cloud_sptheme.ext.relbar_links',
51 'cloud_sptheme.ext.table_styling',
52 ]
53
54 #: names of all cloud extensions
55 all_exts = std_exts + [
56 'cloud_sptheme.ext.issue_tracker',
57 ]
58
59 #=============================================================================
60 # theme setup
61 #=============================================================================
62
63 #: root of this package
64 _root_dir = os.path.abspath(os.path.dirname(__file__))
65
66 #: root of themes subdir
•67 _theme_dir = "/usr/share/sphinx/themes"
68
69
70 def get_theme_dir():
71 """Returns path to directory containing this package's Sphinx themes.
72
73 .. deprecated:: 1.7
74
75 As of Sphinx 1.2, this is passed to Sphinx via a ``setup.py`` entry point,
76 and no longer needs to be included in your documentation's ``conf.py``.
77 """
78 warn("get_theme_dir() is deprecated, and will be removed in version 2.0",
79 DeprecationWarning, stacklevel=1)
80 return _theme_dir
81
82
83 def _iter_theme_sources():
84 """
85 setup helper -- iterates over ``(theme name, theme path)`` pairs
86 for all HTML themes in this package.
87 """
88 base = _theme_dir
89 assert os.path.isabs(base)
90 for name in os.listdir(base):
91 path = os.path.join(base, name)
92 if os.path.exists(os.path.join(path, "theme.conf")):
93 yield name, path
94
95
96 def setup(app):
97 """
98 sphinx 1.6 entrypoint for registring HTML themes;
99 required by "sphinx.html_themes" entrypoint.
100 """
101 for name, path in _iter_theme_sources():
102 app.add_html_theme(name, path)
103
104 #=============================================================================
105 # misc public helpers
106 #=============================================================================
107
108 def get_version(release):
109 """
110 Derive short version string from longer 'release' string.
111
112 This is quick helper which takes a project's ``release`` string,
113 and generates the shortened ``version`` string required by ``conf.py``.
114 Usage example for ``conf.py``::
115
116 import cloud_sptheme as csp
117
118 ...
119
120 # The version info for the project you're documenting
121 from myapp import __version__ as release
122 version = csp.get_version(release)
123 """
•124 return re.match(r"(\d+\.\d+)", release).group(1)
125
126 #=============================================================================
127 # misc internal helpers
128 #=============================================================================
129
130 def is_cloud_theme(name):
131 """
132 [hack] internal helper to check if named theme belongs to this package
133 """
134 # TODO: find way to detect if an external theme *derives* from this package
135 return os.path.isfile(os.path.join(_theme_dir, name, "theme.conf"))
136
137 #=============================================================================
138 # eof
139 #=============================================================================