Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawkey committed Jan 9, 2024
1 parent 9da1796 commit e8e5933
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 20 deletions.
40 changes: 20 additions & 20 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
[kiui](https://kiui.moe/)'s notebook.

## Recent Updates
- [mkdocs.md](python\mkdocs/) <div style="text-align: right">2023-12-29 14:32:16.436796</div>
- [trojan.md](web\proxy\trojan/) <div style="text-align: right">2023-12-29 14:29:49.998239</div>
- [frp_reverse_proxy.md](web\proxy\frp_reverse_proxy/) <div style="text-align: right">2023-12-29 14:29:49.994726</div>
- [http.md](web\frontend\html\http/) <div style="text-align: right">2023-12-29 14:29:49.993438</div>
- [css.md](web\frontend\html\css/) <div style="text-align: right">2023-12-29 14:29:49.990813</div>
- [html.md](web\frontend\html\html/) <div style="text-align: right">2023-12-29 14:29:49.990813</div>
- [react-basics.md](web\frontend\react-basics/) <div style="text-align: right">2023-12-29 14:29:49.986814</div>
- [nodejs_basics.md](web\frontend\nodejs_basics/) <div style="text-align: right">2023-12-29 14:29:49.985230</div>
- [javascript_basics.md](web\frontend\javascript_basics/) <div style="text-align: right">2023-12-29 14:29:49.984229</div>
- [javascript_advanced.md](web\frontend\javascript_advanced/) <div style="text-align: right">2023-12-29 14:29:49.982230</div>
- [nginx.md](web\deploy\nginx/) <div style="text-align: right">2023-12-29 14:29:49.978239</div>
- [sql_sqlite.md](web\backend\sql_sqlite/) <div style="text-align: right">2023-12-29 14:29:49.977733</div>
- [python_flask.md](web\backend\python_flask/) <div style="text-align: right">2023-12-29 14:29:49.973222</div>
- [sql_mysql.md](web\backend\sql_mysql/) <div style="text-align: right">2023-12-29 14:29:49.973222</div>
- [transformation.md](vision\transformation/) <div style="text-align: right">2023-12-29 14:29:49.969222</div>
- [golang_basics.md](web\backend\golang_basics/) <div style="text-align: right">2023-12-29 14:29:49.969222</div>
- [golang_gin.md](web\backend\golang_gin/) <div style="text-align: right">2023-12-29 14:29:49.969222</div>
- [image_processing.md](vision\image_processing/) <div style="text-align: right">2023-12-29 14:29:49.968036</div>
- [colmap.md](vision\colmap/) <div style="text-align: right">2023-12-29 14:29:49.961324</div>
- [3d reconstruction and generation.md](readings\3d reconstruction and generation/) <div style="text-align: right">2023-12-29 14:29:49.957000</div>
- [sphinx_doc.md](python\sphinx_doc/) <div style="text-align: right">2024-01-09 22:31:34.777421</div>
- [basics.md](godot\basics/) <div style="text-align: right">2024-01-07 13:19:24.855045</div>
- [rebuttals.md](writings\rebuttals/) <div style="text-align: right">2024-01-07 13:19:24.838534</div>
- [review.md](writings\review/) <div style="text-align: right">2024-01-07 13:19:24.838534</div>
- [societal_impact.md](writings\societal_impact/) <div style="text-align: right">2024-01-07 13:19:24.838534</div>
- [web_overview.md](web\web_overview/) <div style="text-align: right">2024-01-07 13:19:24.837537</div>
- [xpath.md](web\scrape\xpath/) <div style="text-align: right">2024-01-07 13:19:24.837537</div>
- [cuda.md](windows\cuda/) <div style="text-align: right">2024-01-07 13:19:24.837537</div>
- [examples.md](writings\examples/) <div style="text-align: right">2024-01-07 13:19:24.837537</div>
- [pitfalls.md](writings\pitfalls/) <div style="text-align: right">2024-01-07 13:19:24.837537</div>
- [trojan-go.md](web\proxy\trojan-go/) <div style="text-align: right">2024-01-07 13:19:24.836251</div>
- [trojan.md](web\proxy\trojan/) <div style="text-align: right">2024-01-07 13:19:24.836251</div>
- [rsshub.md](web\rss\rsshub/) <div style="text-align: right">2024-01-07 13:19:24.836251</div>
- [ttrss.md](web\rss\ttrss/) <div style="text-align: right">2024-01-07 13:19:24.836251</div>
- [grab.md](web\scrape\grab/) <div style="text-align: right">2024-01-07 13:19:24.836251</div>
- [concepts.md](web\proxy\concepts/) <div style="text-align: right">2024-01-07 13:19:24.835251</div>
- [frp_reverse_proxy.md](web\proxy\frp_reverse_proxy/) <div style="text-align: right">2024-01-07 13:19:24.835251</div>
- [set_usual_apps_proxy.md](web\proxy\set_usual_apps_proxy/) <div style="text-align: right">2024-01-07 13:19:24.835251</div>
- [ss.md](web\proxy\ss/) <div style="text-align: right">2024-01-07 13:19:24.835251</div>
- [ip.md](web\ip/) <div style="text-align: right">2024-01-07 13:19:24.834251</div>
288 changes: 288 additions & 0 deletions docs/python/sphinx_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
## Sphinx

### install

```bash
pip install sphinx
```


### Layout

Run this at the root dir of your lib:

```bash
sphinx-quickstart docs
# separate source and build --> usually choose yes.
```

The layout will be:

```bash
mylib # <-- source code
setup.py
readme.md

# create by sphinx
docs
├── build # rendered doc
├── make.bat
├── Makefile
└── source
├── conf.py # important!
├── index.rst # welcome page
├── _static
└── _templates
```

Build the doc by:

```bash
sphinx-build -M html docs/source/ docs/build

# or in linux
cd docs
make html
```

Then you can open the built index html (e.g., right click and openning by vs code live server):

http://127.0.0.1:5500/docs/build/html/index.html


### Write docs

By default sphinx uses **ReStructuredText (.rst)** mark up language, which is less common. But we can use `m2r2` extension to convert markdown (.md) to rst formats:

```python
extensions = [
"m2r2",
]

source_suffix = [".rst", ".md"]
```


#### Narrative documentation

Just create a new file under `docs/source`, like `index.md`.

Remember to cross-reference it to `index.md` under `toctree`:

```rst
.. table of content trees
.. toctree::
:caption: Tutorials
:hidden:
:maxdepth: 1
:titlesonly:
./mesh.md
./camera.md
.. toctree::
:caption: API
:hidden:
:maxdepth: 1
:titlesonly:
./utils.md
./cli.md
```


#### Automatic documentation

To automatically document all APIs, use these extensions:

```python
extensions = [
'sphinx.ext.autodoc', # extract doc for single func/class
'sphinx.ext.autosummary', # extract doc for a file
]
```

These extensions will extract docstring from `py` source files.

There are different docstring styles, by default sphinx use a format as:

```python
def func(path):
"""
Func description.
:param path: The path of the file to wrap
:type path: str
:returns: A buffered writable file descriptor
:rtype: BufferedFileStorage
"""
...
```

Another popular format is Google Python style:

```python
def func(arg1: int, arg2: str) --> bool:
"""Summary line.
Extended description of function.
Args:
arg1 (int): Description of arg1
arg2 (str): Description of arg2
Returns:
bool: Description of return value
"""
return True
```

You need this extension to use it:

```python
extensions = ['sphinx.ext.napoleon']
```

To auto-generate the docs, you need to write in your doc file:

```rst
.. autodoc a func
.. autofunction:: kiui.func
.. autodoc a class
.. autoclass:: kiui.myClass()
.. autodoc a file (autosummary)
.. autosummary::
:toctree: generated
kiui
```

Note that `autodoc` will import the file to doc it! Ensure there are no side effects for any import.


### Publish

Use extension:

```python
extensions = [
"sphinx.ext.githubpages",
]
```


Create a doc building `docs/requirements.txt`:

```
sphinx
furo
m2r2
```


TODO


### Theme

For example:

```bash
pip install furo
```

Change conf.py:

```python
html_theme = 'furo'
```


### Example conf

```python
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------

project = 'kiui'
copyright = '2024, kiui'
author = 'kiui'

# The full version, including alpha/beta/rc tags
release = '0.2.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.githubpages",
"sphinx.ext.viewcode",
"m2r2",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_title = "kiuikit"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

sphinx_to_github = True
sphinx_to_github_verbose = True
sphinx_to_github_encoding = "utf-8"

napoleon_google_docstring = True
napoleon_numpy_docstring = False
napoleon_include_init_with_doc = False
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True
napoleon_preprocess_types = False
napoleon_type_aliases = None
napoleon_attr_annotations = True
```

0 comments on commit e8e5933

Please sign in to comment.