| 1 |
import os |
| 2 |
import re |
| 3 |
|
| 4 |
|
| 5 |
def read(*parts) -> str: |
| 6 |
""" |
| 7 |
Build an absolute path from *parts* and and return the contents of the |
| 8 |
resulting file. Assume UTF-8 encoding. |
| 9 |
""" |
| 10 |
here = os.path.abspath(os.path.dirname(__file__)) |
| 11 |
with open(os.path.join(here, *parts), encoding="utf-8") as f: |
| 12 |
return f.read() |
| 13 |
|
| 14 |
|
| 15 |
def find_version(*file_paths) -> str: |
| 16 |
""" |
| 17 |
Build a path from *file_paths* and search for a ``__version__`` |
| 18 |
string inside. |
| 19 |
""" |
| 20 |
version_file = read(*file_paths) |
| 21 |
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) |
| 22 |
if version_match: |
| 23 |
return version_match.group(1) |
| 24 |
raise RuntimeError("Unable to find version string.") |
| 25 |
|
| 26 |
|
| 27 |
# -- General configuration ------------------------------------------------ |
| 28 |
|
| 29 |
# Add any Sphinx extension module names here, as strings. They can be |
| 30 |
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 31 |
# ones. |
| 32 |
extensions = [ |
| 33 |
"sphinx.ext.autodoc", |
| 34 |
"sphinx.ext.doctest", |
| 35 |
"sphinx.ext.intersphinx", |
| 36 |
"sphinx.ext.todo", |
| 37 |
"sphinx_rtd_theme", |
| 38 |
] |
| 39 |
|
| 40 |
# Add any paths that contain templates here, relative to this directory. |
| 41 |
templates_path = ["_templates"] |
| 42 |
|
| 43 |
# The suffix(es) of source filenames. |
| 44 |
# You can specify multiple suffix as a list of string: |
| 45 |
# source_suffix = ['.rst', '.md'] |
| 46 |
source_suffix = ".rst" |
| 47 |
|
| 48 |
# The master toctree document. |
| 49 |
master_doc = "index" |
| 50 |
|
| 51 |
# General information about the project. |
| 52 |
project = "PyJWT" |
| 53 |
copyright = "2015-2022, José Padilla" |
| 54 |
author = "José Padilla" |
| 55 |
|
| 56 |
# The version info for the project you're documenting, acts as replacement for |
| 57 |
# |version| and |release|, also used in various other places throughout the |
| 58 |
# built documents. |
| 59 |
# |
| 60 |
# The full version, including alpha/beta/rc tags. |
| 61 |
release = find_version("../jwt/__init__.py") |
| 62 |
|
| 63 |
# The short X.Y version. |
| 64 |
version = release.rsplit(".", 1)[0] |
| 65 |
|
| 66 |
# The language for content autogenerated by Sphinx. Refer to documentation |
| 67 |
# for a list of supported languages. |
| 68 |
# |
| 69 |
# This is also used if you do content translation via gettext catalogs. |
| 70 |
# Usually you set "language" from the command line for these cases. |
| 71 |
# language = None |
| 72 |
|
| 73 |
# List of patterns, relative to source directory, that match files and |
| 74 |
# directories to ignore when looking for source files. |
| 75 |
exclude_patterns = ["_build"] |
| 76 |
|
| 77 |
# The name of the Pygments (syntax highlighting) style to use. |
| 78 |
pygments_style = "sphinx" |
| 79 |
|
| 80 |
# If true, `todo` and `todoList` produce output, else they produce nothing. |
| 81 |
todo_include_todos = False |
| 82 |
|
| 83 |
# Suppress nitpick warnings for type aliases that Sphinx cannot resolve. |
| 84 |
nitpick_ignore = [ |
| 85 |
("py:class", "JWKDict"), |
| 86 |
("py:class", "PublicKeyTypes"), |
| 87 |
("py:class", "PrivateKeyTypes"), |
| 88 |
] |
| 89 |
|
| 90 |
# Intersphinx extension. |
| 91 |
intersphinx_mapping = { |
| 92 |
"python": ("https://docs.python.org/3/", None), |
| 93 |
"cryptography": ("https://cryptography.io/en/latest/", None), |
| 94 |
} |
| 95 |
|
| 96 |
# Hack for allowing aliases within TYPE_CHECKING to be documented |
| 97 |
os.environ["SPHINX_BUILD"] = "1" |
| 98 |
|
| 99 |
# -- Options for HTML output ---------------------------------------------- |
| 100 |
|
| 101 |
|
| 102 |
html_theme = "sphinx_rtd_theme" |
| 103 |
|
| 104 |
# Add any paths that contain custom static files (such as style sheets) here, |
| 105 |
# relative to this directory. They are copied after the builtin static files, |
| 106 |
# so a file named "default.css" will overwrite the builtin "default.css". |
| 107 |
html_static_path = ["_static"] |
| 108 |
|
| 109 |
# These paths are either relative to html_static_path |
| 110 |
# or fully qualified paths (eg. https://...) |
| 111 |
html_css_files = [ |
| 112 |
"theme_overrides.css", |
| 113 |
] |
| 114 |
|
| 115 |
# Output file base name for HTML help builder. |
| 116 |
htmlhelp_basename = "PyJWTdoc" |
| 117 |
|
| 118 |
|
| 119 |
# -- Options for manual page output --------------------------------------- |
| 120 |
|
| 121 |
# One entry per manual page. List of tuples |
| 122 |
# (source start file, name, description, authors, manual section). |
| 123 |
man_pages = [(master_doc, "pyjwt", "PyJWT Documentation", [author], 1)] |
| 124 |
|
| 125 |
|
| 126 |
# -- Options for Texinfo output ------------------------------------------- |
| 127 |
|
| 128 |
# Grouping the document tree into Texinfo files. List of tuples |
| 129 |
# (source start file, target name, title, author, |
| 130 |
# dir menu entry, description, category) |
| 131 |
texinfo_documents = [ |
| 132 |
( |
| 133 |
master_doc, |
| 134 |
"PyJWT", |
| 135 |
"PyJWT Documentation", |
| 136 |
author, |
| 137 |
"PyJWT", |
| 138 |
"One line description of project.", |
| 139 |
"Miscellaneous", |
| 140 |
) |
| 141 |
] |