From 0498a06fd90230fb7a1066f978f650c1680587a3 Mon Sep 17 00:00:00 2001 From: ZigaMr Date: Mon, 2 Dec 2024 12:10:18 +0100 Subject: [PATCH] docs: Add python API reference --- .github/workflows/ci-docs.yaml | 49 ++++++++++++++++++++++++++++++++++ clients/py/.gitignore | 1 + clients/py/Makefile | 17 +++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-docs.yaml b/.github/workflows/ci-docs.yaml index 7756fdeba..02772e875 100644 --- a/.github/workflows/ci-docs.yaml +++ b/.github/workflows/ci-docs.yaml @@ -5,6 +5,7 @@ on: paths: - clients/js/** - contracts/** + - clients/py/** branches: - main @@ -127,3 +128,51 @@ jobs: commit_message: Deploy sol API reference ${{ github.event.head_commit.message }} user_name: github-actions[bot] user_email: 41898282+github-actions[bot]@users.noreply.github.com + + py-docs: + name: py-docs + runs-on: ubuntu-latest + services: + sapphire-localnet-ci: + image: ghcr.io/oasisprotocol/sapphire-localnet:latest + ports: + - 8545:8545 + options: >- + --rm + --health-cmd="test -f /CONTAINER_READY" + --health-start-period=90s + defaults: + run: + working-directory: ./clients/py + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements.dev.txt + pip install sphinx myst-parser + make + pip install dist/sapphire.py-*.whl + + - name: Build docs + run: | + make docs + + - name: Deploy to api-reference branch + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: clients/py/docs/build/html + publish_branch: api-reference + destination_dir: py + commit_message: Deploy Python API reference ${{ github.event.head_commit.message }} + user_name: github-actions[bot] + user_email: 41898282+github-actions[bot]@users.noreply.github.com diff --git a/clients/py/.gitignore b/clients/py/.gitignore index eabbb546f..dcca46e62 100644 --- a/clients/py/.gitignore +++ b/clients/py/.gitignore @@ -1,5 +1,6 @@ __pycache__ dist build +docs .mypy_cache *.egg-info diff --git a/clients/py/Makefile b/clients/py/Makefile index 0fe4ee862..4dddcf3b0 100644 --- a/clients/py/Makefile +++ b/clients/py/Makefile @@ -13,7 +13,7 @@ test: $(PYTHON) -munittest discover clean: - rm -rf sapphirepy/__pycache__ build dist sapphire.py.egg-info .mypy_cache + rm -rf sapphirepy/__pycache__ build dist sapphire.py.egg-info .mypy_cache docs lint: $(PYTHON) -mpylint $(MODULE) -d line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring @@ -22,3 +22,18 @@ build: wheel wheel: $(PYTHON) setup.py bdist_wheel + +docs: + @rm -rf docs; mkdir docs + @cd docs && sphinx-quickstart --quiet --sep --project=sapphirepy --author='team@oasisprotocol.org' --ext-autodoc --ext-viewcode + @sed -i "s/^copyright = .*/copyright = '$$(date +%Y), Oasis Protocol Foundation'/" docs/source/conf.py + @pip install furo + @sed -i "s/^html_theme = 'alabaster'/html_theme = 'furo'/" docs/source/conf.py + @sed -i "s/^extensions = \[/extensions = [\n 'myst_parser',/" docs/source/conf.py + @echo "source_suffix = {'.rst': 'restructuredtext', '.md': 'markdown'}" >> docs/source/conf.py + @sed -i '/Add your content/,/details/c\\n.. automodule:: sapphirepy\n :members:\n :undoc-members:\n :show-inheritance:\n\n.. include:: ../../README.md\n :parser: markdown' docs/source/index.rst + @echo "\n modules" >> docs/source/index.rst + @sphinx-apidoc -o docs/source/ $$(pip show sapphire-py | grep Location | cut -d' ' -f2)/sapphirepy + @$(MAKE) html -C docs + +.PHONY: all mypy ruff test clean lint build wheel docs