From 4863f27fab81fa0301554a5df623feb8c72fd404 Mon Sep 17 00:00:00 2001 From: Adam Janovsky Date: Sun, 24 Apr 2022 20:59:47 +0200 Subject: sphinx quickstart --- docs/Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/Makefile (limited to 'docs/Makefile') diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -- cgit v1.3.1 From 4fe5372ec385c3662a7a05d75ec40922d40c414e Mon Sep 17 00:00:00 2001 From: Adam Janovsky Date: Fri, 20 May 2022 18:24:01 +0200 Subject: Docs: automatically generate configuration page --- .gitignore | 3 +++ docs/Makefile | 7 +++++++ docs/generate_config_page.py | 20 ++++++++++++++++++++ docs/index.md | 3 ++- sec_certs/config/configuration.py | 8 +++++++- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 docs/generate_config_page.py (limited to 'docs/Makefile') diff --git a/.gitignore b/.gitignore index 1d2da538..8faf062e 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,9 @@ instance/ # Sphinx documentation docs/_build/ +# Dynamically built configuration page +docs/configuration.md + # PyBuilder target/ diff --git a/docs/Makefile b/docs/Makefile index d4bb2cbb..0405fafe 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -17,4 +17,11 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile + @if [ "$@" = "html" ]; then \ + chmod +x ./generate_config_page.py ;\ + python3 ./generate_config_page.py ;\ + fi @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @if [ "$@" = "html" ]; then \ + rm ./configuration.md ;\ + fi \ No newline at end of file diff --git a/docs/generate_config_page.py b/docs/generate_config_page.py new file mode 100755 index 00000000..d928c178 --- /dev/null +++ b/docs/generate_config_page.py @@ -0,0 +1,20 @@ +# This will generate configuration.md page from `settings.yaml` in sec_certs.configuration file + +from sec_certs.config import configuration + + +def main(): + cfg = configuration.config + + with open("./configuration.md", "w") as handle: + handle.write("# Configuration\n\n") + handle.write( + "The configuration is stored in yaml file `settings.yaml` at `sec_certs.config`. These are the supported options, descriptions and default values.\n\n" + ) + for key in cfg.__dict__: + handle.write(f"`{key}`\n\n- Description: {cfg.get_desription(key)}\n") + handle.write(f"- Default value: `{cfg.__getattribute__(key)}`\n\n") + + +if __name__ == "__main__": + main() diff --git a/docs/index.md b/docs/index.md index 8949debe..61c39ec5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -32,6 +32,7 @@ Seccerts PyPi installation.md quickstart.md tutorial.md +configuration.md ``` ```{toctree} @@ -44,7 +45,7 @@ notebooks/examples/model.ipynb ``` ```{toctree} -:caption: API +:caption: API reference :hidden: True :maxdepth: 1 api/sample.md diff --git a/sec_certs/config/configuration.py b/sec_certs/config/configuration.py index 8560529c..6a9a5880 100644 --- a/sec_certs/config/configuration.py +++ b/sec_certs/config/configuration.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Any, Union +from typing import Any, Optional, Union import jsonschema import yaml @@ -30,6 +30,12 @@ class Configuration(object): return res["value"] return object.__getattribute__(self, key) + def get_desription(self, key: str) -> Optional[str]: + res = object.__getattribute__(self, key) + if isinstance(res, dict) and "description" in res: + return res["description"] + return None + DEFAULT_CONFIG_PATH = Path(__file__).parent / "settings.yaml" config = Configuration() -- cgit v1.3.1 From b01f20c1b219199ab4e1369c8cfa47c1409ba443 Mon Sep 17 00:00:00 2001 From: Adam Janovsky Date: Sat, 21 May 2022 09:41:28 +0200 Subject: Docs: configuratiom.md without editing makefile --- .gitignore | 3 --- docs/Makefile | 7 ------- docs/configuration.md | 26 ++++++++++++++++++++++++++ docs/generate_config_page.py | 20 -------------------- 4 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 docs/configuration.md delete mode 100755 docs/generate_config_page.py (limited to 'docs/Makefile') diff --git a/.gitignore b/.gitignore index 8faf062e..1d2da538 100644 --- a/.gitignore +++ b/.gitignore @@ -78,9 +78,6 @@ instance/ # Sphinx documentation docs/_build/ -# Dynamically built configuration page -docs/configuration.md - # PyBuilder target/ diff --git a/docs/Makefile b/docs/Makefile index 0405fafe..d4bb2cbb 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -17,11 +17,4 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @if [ "$@" = "html" ]; then \ - chmod +x ./generate_config_page.py ;\ - python3 ./generate_config_page.py ;\ - fi @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - @if [ "$@" = "html" ]; then \ - rm ./configuration.md ;\ - fi \ No newline at end of file diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 00000000..27d07760 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,26 @@ +--- +file_format: mystnb +mystnb: + remove_code_source: true + execution_mode: 'force' +--- +# Configuration + +The configuration is stored in yaml file `settings.yaml` at `sec_certs.config`. These are the supported options, descriptions and default values. + + +```{code-cell} python +from sec_certs.config import configuration +from myst_nb import glue +from IPython.display import Markdown + +cfg = configuration.config +text = "" +for key in cfg.__dict__: + text += f"`{key}`\n\n- Description: {cfg.get_desription(key)}\n" + text += f"- Default value: `{cfg.__getattribute__(key)}`\n\n" +glue("text", Markdown(text)) +``` +```{glue:md} text +:format: myst +``` diff --git a/docs/generate_config_page.py b/docs/generate_config_page.py deleted file mode 100755 index d928c178..00000000 --- a/docs/generate_config_page.py +++ /dev/null @@ -1,20 +0,0 @@ -# This will generate configuration.md page from `settings.yaml` in sec_certs.configuration file - -from sec_certs.config import configuration - - -def main(): - cfg = configuration.config - - with open("./configuration.md", "w") as handle: - handle.write("# Configuration\n\n") - handle.write( - "The configuration is stored in yaml file `settings.yaml` at `sec_certs.config`. These are the supported options, descriptions and default values.\n\n" - ) - for key in cfg.__dict__: - handle.write(f"`{key}`\n\n- Description: {cfg.get_desription(key)}\n") - handle.write(f"- Default value: `{cfg.__getattribute__(key)}`\n\n") - - -if __name__ == "__main__": - main() -- cgit v1.3.1