From 7dc48b2b48022a87980f3e3a7a678b1db2b7edd4 Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Fri, 8 Sep 2023 11:07:08 +0200 Subject: [PATCH] Start doc (#66) * sphinx-quickstart * update .gitignore * add structure * iterate on docs * iterate on docs * generate CLI reference * use rtd theme * syntax * add hatch dependency --- .gitignore | 6 ++++++ docs/Makefile | 20 +++++++++++++++++ docs/conf.py | 50 +++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 29 +++++++++++++++++++++++++ docs/installation.rst | 44 +++++++++++++++++++++++++++++++++++++ docs/make.bat | 35 ++++++++++++++++++++++++++++++ pyproject.toml | 5 +++++ 7 files changed, 189 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/make.bat diff --git a/.gitignore b/.gitignore index 17db4e1..3470c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,10 @@ __pycache__/ .coverage .tox/ + +# Build dist/ +docs/_build/ + +# CLI reference is auto-generated +docs/cli_reference.md diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /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) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..c486042 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,50 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +from subprocess import PIPE, Popen, run + + +project = "catleg" +copyright = "2023, the catala contributors" +author = "the catala contributors" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ["myst_parser"] + +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "sphinx_rtd_theme" +html_static_path = ["_static"] + +# version +pipe = Popen("hatch version", stdout=PIPE, shell=True) +version = pipe.stdout.read().decode("utf8") + +# generate CLI reference +# (this command implies that `make html` is executed from the `docs` +# directory -- this could be made more robust?) +run( + [ + "typer", + "../src/catleg/catleg.py", + "utils", + "docs", + "--name", + "catleg", + "--output", + "cli_reference.md", + ], + check=True, +) diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..760148b --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,29 @@ +================= + catleg |version| +================= + +*A library of helper tools for catala programming in the context of French legislative texts.* + +|PyPI| |CI| |License| + +.. |PyPI| image:: https://img.shields.io/pypi/v/catleg.svg + :target: https://pypi.org/project/catleg/ +.. |CI| image:: https://github.com/CatalaLang/catleg/workflows/check/badge.svg + :target: https://github.com/CatalaLang/catleg/actions +.. |License| image:: https://img.shields.io/badge/license-Apache%202.0-blue.svg + :target: https://github.com/CatalaLang/catleg/blob/main/LICENSE + +.. toctree:: + :maxdepth: 3 + :caption: Contents: + + installation + cli_reference.md + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..6afa6cb --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,44 @@ +.. _installation: + +============== + Installation +============== + +``catleg`` is tested on Linux, macOS and Windows. + +.. _installation_homebrew: + + +Using pip +========= + +The `catleg package `__ can be installed using ``pip`` like so:: + + pip install catleg + +.. _installation_pipx: + +Using pipx +========== + +`pipx `__ is a tool for installing Python command-line applications in their own isolated environments. You can use ``pipx`` to install the ``catleg`` command-line tool like this:: + + pipx install catleg + +Providing Legifrance credentials +================================ + +``catleg`` uses the Legifrance API to access French legislative texts. + +This API is authenticated and requires credentials, which may be obtained by registering on `the Piste portal `__. + +To provide credentials to catleg, create a ``.catleg_secrets.toml`` file like so:: + + lf_client_id = "your_client_id" + lf_client_secret = "your_client_secret" + +Alternatively, you may define the environment variables ``CATLEG_LF_CLIENT_ID`` and ``CATLEG_LF_CLIENT_SECRET``. + +.. note:: + Legifrance authentication requires **oauth** credentials, not an API key. + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/pyproject.toml b/pyproject.toml index 8d8eb47..bdf9b9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,11 +34,16 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ + "hatch", "mypy", + "myst-parser", "pre-commit", "pytest", "ruff", + "sphinx", + "sphinx-rtd-theme", "tox", + "typer-cli" ] [project.scripts]