Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #147

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/publish-document.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish document
on:
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout Repository
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
name: Setup Python
with:
python-version: 3.12
- name: Set Cache ID
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Restore/Save Cache
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- name: Install mkdocs dependencies
run: pip install tox
- name: Deploy documentation to GitHub Pages
run: tox -e docs -- gh-deploy --force
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ venv/

# Setuptools scm version
_version.py

# mkdocs documentation
/site
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to remove the leading / since I'm guessing this absolute path is only correct if developing inside a docker container

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, but I don't understand which docker container you are mentioning.

I do not use docker container for my development environment. I simply followed CONTRIBUTION.md, and it does not have any description for docker.

And when I build the document with mkdocs build command, it outputs the document into /site folder, so I updated gitignore to ignore this directory.

Is there a way to create the development environment with docker?

27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ To format and lint the codes,
tox -e fmt,lint
```

This repository uses [mkdocs](https://github.com/mkdocs/mkdocs/tree/master) to generate a documentation from python docstring. As long as you write the docstrings for your code, the document (API references section) will be updated whenever you run `tox -e docs` command. The document will be automatically published when your PR is merged into `main` branch.

To build the documentation based on your current codes, run the following command. This will outputs the documentation into `./site` folder.

```bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do go the route or scripting and tracking deps in pyproject this will need to be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have to chose this route. Please check #147 (comment)

tox -e docs
```

To run other mkdocs command,

```bash
tox -e docs -- <mkdocs command>

# For instance, serve the current documentation locally,
tox -e docs -- serve
...
INFO - [17:35:25] Serving on http://127.0.0.1:8000/
```

You can also manually edit or add pages to the documentation by modifying files under `./docs` folder.

For more information about mkdocs, please refer to their documentations:

- mkdocs: https://github.com/mkdocs/mkdocs/tree/master
- mkdocs material (material theme wrapper for mkdocs): https://github.com/squidfunk/mkdocs-material
- mkdocstrings (plugin to automatically generate documentation from docstrings): https://github.com/mkdocstrings/mkdocstrings

# Your First Contribution

Would you like to help drive the community forward? We will help you understand the organization of the project and direct you to the best places to get started. You'll be able to pick up issues, write code to fix them, and get your work reviewed and merged.
Expand Down
3 changes: 3 additions & 0 deletions docs/API References.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Auto generate API references with mkdocstrings https://mkdocstrings.github.io/usage/#usage -->

::: oper8
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Oper8

Oper8 is a framework for writing kubernetes operators in python. It implements many common patterns used by large cloud applications that are reusable across many operator design patterns ([GitHub](https://github.com/IBM/oper8/tree/main)).

For API details, please refer to the [API References](API References.md).
31 changes: 31 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
site_name: "oper8"
nav:
- Home: index.md
- API References: API References.md
theme:
name: material
font:
text: IBM Plex Sans
code: IBM Plex Mono
palette:
# Dark Mode
- scheme: slate
toggle:
icon: material/weather-sunny
name: Dark mode
primary: black
accent: deep purple
# Light Mode
- scheme: default
toggle:
icon: material/weather-night
name: Light mode
primary: white
accent: indigo
plugins:
- search
- mkdocstrings:
handlers:
python:
options:
show_submodules: true
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ dev-test = [
]

dev-docs = [
"sphinx>=4.0.2,<9.0",
"sphinx-autoapi>=2.1.0",
"sphinx-rtd-theme>=1.2.1,<3.1.0",
"mkdocs-material>=9.5.46",
"mkdocstrings-python>=1.12.2"
]

dev-fmt = [
Expand Down
22 changes: 22 additions & 0 deletions scripts/document.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$BASE_DIR"

mkdocs_opt=("$@")

if [[ ${#mkdocs_opt[@]} -eq 0 ]]; then
echo "No options provided. Running 'mkdocs build'..."
mkdocs build
exit 0
fi

# Modify set e because serve will be aborted with ctrl C.
if [[ "${mkdocs_opt[0]}" == "serve" ]]; then
set +e
echo "Serving the documentation. Abort with ctrl C."
fi

echo "Running 'mkdocs ${mkdocs_opt[@]}'..."
mkdocs "${mkdocs_opt[@]}"
17 changes: 6 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py, lint, fmt
envlist = py, lint, fmt, docs

[testenv]
description = run tests with pytest with coverage
Expand All @@ -20,16 +20,11 @@ allowlist_externals = ./scripts/run_tests.sh
; Without this, sdist packaging is tested so that's a start.
package=wheel

; TODO -- Enable docs!!
; [testenv:docs]
; recreate = True
; extras = dev-docs
; changedir = docs/source

; ; Disabled '-W' flag as warnings in the files
; ; TOTO: Add back in once build warnings fixed
; commands =
; sphinx-build -E -a -b html -T . _build/html
[testenv:docs]
description = build documentation
extras = dev-docs
commands = ./scripts/document.sh {posargs}
allowlist_externals = ./scripts/document.sh

[testenv:fmt]
description = format with pre-commit
Expand Down
Loading