File: local_extension.py

package info (click to toggle)
python-whey 0.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,912 kB
  • sloc: python: 4,433; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 838 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# stdlib
import json
from typing import Any

# 3rd party
from sphinx.application import Sphinx
from sphinx_toolbox.more_autodoc.variables import VariableDocumenter

# this package
from whey.config.whey import license_lookup


class LicenseLookupDocumenter(VariableDocumenter):

	def add_content(self, more_content: Any, no_docstring: bool = False) -> None:
		super().add_content(more_content, no_docstring)

		if self.object is license_lookup:
			sourcename = self.get_sourcename()

			self.add_line('', sourcename)
			self.add_line(".. code-block:: JSON", sourcename)
			self.add_line('', sourcename)

			for line in json.dumps(license_lookup, indent=2).splitlines():
				self.add_line(f"    {line}", sourcename)

			self.add_line('', sourcename)


def setup(app: Sphinx):
	app.add_autodocumenter(LicenseLookupDocumenter, override=True)