Skip to content

Commit d77954b

Browse files
authored
Merge pull request #121 from adfinis/new-docs
docs: Generate documentation with sphinx
2 parents 99a8be4 + dabb6ea commit d77954b

20 files changed

+1267
-76
lines changed

.github/workflows/main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,45 @@ jobs:
6262
run: |
6363
HYPOTHESIS_PROFILE=ci make test
6464
65+
docs:
66+
runs-on: ubuntu-latest
67+
needs: [cache]
68+
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v4
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
with:
76+
buildkitd-flags: --debug
77+
78+
- name: Build container
79+
uses: docker/build-push-action@v5
80+
with:
81+
context: compose
82+
push: false
83+
load: true
84+
tags: ghcr.io/adfinis/pyaptly/cache:latest
85+
cache-from: type=registry,ref=ghcr.io/adfinis/pyaptly/cache:gha
86+
87+
- name: Generate the docs
88+
run: |
89+
make docs
90+
91+
- name: Upload artifacts
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: html-docs
95+
path: docs/_build/html/
96+
97+
- name: Deploy
98+
uses: peaceiris/actions-gh-pages@v4
99+
if: github.ref == 'refs/heads/main'
100+
with:
101+
github_token: ${{ secrets.GITHUB_TOKEN }}
102+
publish_dir: docs/_build/html
103+
65104
package:
66105
runs-on: ubuntu-latest
67106
needs: [test]

.github/workflows/pull-requests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,34 @@ jobs:
3131
- name: Run tests
3232
run: |
3333
HYPOTHESIS_PROFILE=ci make test
34+
35+
docs:
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
with:
45+
buildkitd-flags: --debug
46+
47+
- name: Build container
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: compose
51+
push: false
52+
load: true
53+
tags: ghcr.io/adfinis/pyaptly/cache:latest
54+
cache-from: type=registry,ref=ghcr.io/adfinis/pyaptly/cache:gha
55+
56+
- name: Generate the docs
57+
run: |
58+
make docs
59+
60+
- name: Upload artifacts
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: html-docs
64+
path: docs/_build/html/

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ __pycache__
33
/.dmypy.json
44
/.coverage
55
/dist
6+
docs/cli
7+
docs/sphinx-template
8+
docs/_build
9+
docs/Command_Line_Reference.md
10+
docs/Config_Reference.md

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ lint-code: ## check all linters
6363
.PHONY: test
6464
test: pytest mypy lint-code ## run all testing
6565

66+
67+
.PHONY: docs
68+
docs: poetry-install ## generate documentation
69+
rm -vrf docs/_build/* docs/cli/*
70+
[[ -d docs/sphinx-template ]] || git clone https://github.com/adfinis-sygroup/adsy-sphinx-template docs/sphinx-template
71+
@docker compose exec testing bash -c "poetry install --only docs"
72+
73+
# Currently md-click has a bad dependency on old click. We fix this with the next command
74+
@docker compose exec testing bash -c "poetry run pip install md-click==1.0.1"
75+
@docker compose exec testing bash -c "patch -f /root/.cache/pypoetry/virtualenvs/pyaptly-*-py3.11/lib/python3.11/site-packages/md_click/main.py md-click.patch || true"
76+
77+
# Generate CLI & Config docs
78+
@docker compose exec testing bash -c "mkdir -p docs/_temp && poetry run mdclick dumps --baseModule=pyaptly.cli --baseCommand=pyaptly --docsPath=./docs/_temp"
79+
@docker compose exec testing bash -c "poetry run jsonschema2md pyaptly/config.schema.json docs/Config_Reference.md"
80+
81+
@cat docs/_temp/pyaptly.md docs/_temp/pyaptly-*.md > docs/Command_Line_Reference.md
82+
# mdclick has not enough indentation
83+
@sed -i 's/^#/##/' docs/Command_Line_Reference.md
84+
# Add title, must happen after the above sed command
85+
@sed -i '1a<!-- This file is generated with mdclick -->\n# Command Line Reference' docs/Command_Line_Reference.md
86+
@docker compose exec testing bash -c "rm -r docs/_temp"
87+
88+
# SPHINX Render
89+
@docker compose exec testing bash -c 'cd docs/ && poetry run make html'
90+
6691
.PHONY: shell
6792
shell: poetry-install ## run shell
6893
@docker compose exec testing bash -c "SHELL=bash poetry shell"

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ input files.
88
- For for the old version [switch to the master branch](https://github.com/adfinis/pyaptly/tree/master)
99
- Main branch builds contain [alpha packages](https://github.com/adfinis/pyaptly/actions/runs/8147002919), see Artifacts
1010

11-
# Why & How
11+
## Why & How
1212

1313
[Aptly](https://www.aptly.info/) is great tool for creating Debian repositories.
1414
But as soon as it's required to maintain repositories for different [environments](https://en.wikipedia.org/wiki/Deployment_environment) it gets very complicated fast.
@@ -22,8 +22,6 @@ That means it's hard to roll back to a previous state if required.
2222
This problem is fixed by using fix timestamps in snapshot names.
2323
That behaviour also allows to define a fixed update spacing. It's possible to say for example "only update this snapshot once a week".
2424

25-
[Follow the Tutorial](./docs/TUTORIAL.md)
26-
2725
## Example commands
2826

2927
Initialize a new aptly server.

docs/Code_Reference.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Code Reference
2+
==============
3+
4+
The following code reference is extracted from the source code and mainly used for debugging/development.
5+
Users of `pyaptly` can ignore this.
6+
7+
Main
8+
----
9+
.. automodule:: pyaptly.main
10+
:members:
11+
12+
Mirror
13+
------
14+
.. automodule:: pyaptly.mirror
15+
:members:
16+
17+
Repo
18+
----
19+
.. automodule:: pyaptly.repo
20+
:members:
21+
22+
Snapshot
23+
--------
24+
.. automodule:: pyaptly.snapshot
25+
:members:
26+
27+
Publish
28+
-------
29+
.. automodule:: pyaptly.publish
30+
:members:
31+
32+
State Reader
33+
------------
34+
.. automodule:: pyaptly.state_reader
35+
:members:
36+
37+
Util
38+
----
39+
.. automodule:: pyaptly.util
40+
:members:
41+

docs/TUTORIAL.md renamed to docs/Getting_Started.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Getting Started
2+
13
> Note: This tutorial assumes basic knowledge of [Aptly](https://www.aptly.info/).
24
35
Pyaptly is capable of managing mirrors, snapshots and publishes.
@@ -6,11 +8,11 @@ But for the purpose of this tutorial we assume a clean [install of Aptly](https:
68

79
TODO: Note to jump to the relevant chapter if only a subset should be managed by aptly.
810

9-
# Installation
11+
## Installation
1012

1113
TODO (once packages are available)
1214

13-
# Aptly Mirror
15+
## Aptly Mirror
1416

1517
Pyaptly can create and update mirrors. Since mirrors are nor a very complicated construct, there's no extra logic not available within aptly.
1618
Configuring a mirror with pyaptly is pretty much the same as writing a command for aptly - except that it's declarative.
@@ -42,7 +44,7 @@ Pyaptly also takes care of downloading the gpp key if it isn't availble yet. If
4244

4345
> For a list of all configuration options of a mirror, check out [the reference](TODO: Reference link).
4446
45-
## updating mirrors
47+
### updating mirrors
4648

4749
We can also tell pyaptly to update all defined mirrors:
4850
```bash
@@ -52,9 +54,9 @@ pyaptly mirror ./config.toml update
5254
This is exactly the same as `aptly mirror update aptly` with the above config.
5355
But it will update all defined mirrors if more than one is defined, making it a bit more convenient than using `aptly` directly.
5456

55-
# Snapshots
57+
## Snapshots
5658

57-
## Basic snapshots
59+
### Basic snapshots
5860

5961
Pyaptly has some extra features for snapshots, but let's start by creating a very simple snapshot first.
6062

@@ -87,7 +89,7 @@ As you see, `pyaptly` first "rotates" the snapshot by just renaming and postfixi
8789

8890
> Similar to mirrors, pyaptly allows a variety of configuration options for snapshots. Check out [the reference](TODO: Link to reference).
8991
90-
## Snapshots with retention
92+
### Snapshots with retention
9193

9294
Snapshots with retention are a bit more complicated than simple snapshots.
9395
The retention time is either 1 day or 1 week. Other types of retention are currently not implemented.
@@ -134,7 +136,7 @@ It's also important to understand that `pyaptly snapshot config.toml update` wil
134136
If we were to patch our systems only once a week, then what we want is to uncomment the line `repeat-weekly: "mon"`. This way, our snapshot would be backdated a full day to `aptly-20240102T0000Z`.
135137
This means that pyaptly would only create a new snapshot once a week, no matter how often the command has run.
136138

137-
# Publish
139+
## Publish
138140

139141
Pyaptly publishes also come with some extra sugar building on the features of the snapshots. But let's start with a simple publish again:
140142
```bash

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

docs/_build/.gitkeep

Whitespace-only changes.

docs/conf.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
project = 'Pyaptly'
10+
copyright = 'Adfinis AG'
11+
author = 'Adfinis AG'
12+
release = '2.0'
13+
14+
# -- General configuration ---------------------------------------------------
15+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
16+
17+
extensions = [
18+
'myst_parser',
19+
'sphinx.ext.autosectionlabel',
20+
'sphinx.ext.autodoc',
21+
]
22+
myst_enable_extensions = [
23+
"linkify",
24+
"replacements",
25+
"smartquotes",
26+
]
27+
28+
# For autodoc
29+
import sys
30+
from pathlib import Path
31+
sys.path.insert(0, str(Path('..').resolve()))
32+
33+
autosectionlabel_prefix_document = True
34+
35+
templates_path = ['_templates']
36+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'sphinx-template']
37+
38+
# -- Options for HTML output -------------------------------------------------
39+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
40+
41+
html_theme = 'adsy'
42+
html_theme_path = ['sphinx-template/html']
43+
html_title = project
44+
html_static_path = ['sphinx-template/html/adsy/static/']
45+
46+
# Output file base name for HTML help builder.
47+
#htmlhelp_basename = 'test1234'
48+

docs/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. Pyaptly documentation master file, created by
2+
sphinx-quickstart on Thu Nov 7 16:17:24 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
.. include:: README.md
7+
:parser: myst_parser.sphinx_
8+
9+
.. toctree::
10+
:maxdepth: 3
11+
:caption: Contents:
12+
13+
README.md
14+
Getting_Started.md
15+
Config_Reference.md
16+
Command_Line_Reference.md
17+
Code_Reference.rst
18+
19+
.. automodule:: pyaptly
20+
:members:

md-click.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
+++ ./a ./b 2024-11-08 13:56:06.904479048 +0000
2+
@@ -49,12 +49,12 @@
3+
parent = helpdct.get("parent", "") or ''
4+
options = {
5+
opt.name: {
6+
- "usage": '\n'.join(opt.opts),
7+
- "prompt": opt.prompt,
8+
- "required": opt.required,
9+
- "default": opt.default,
10+
- "help": opt.help,
11+
- "type": str(opt.type)
12+
+ "usage": '\n'.join(opt.opts),
13+
+ "prompt": getattr(opt, "prompt", None),
14+
+ "required": getattr(opt, "required", None),
15+
+ "default": getattr(opt, "default", None),
16+
+ "help": getattr(opt, "help", None),
17+
+ "type": str(getattr(opt, "type", None))
18+
}
19+
for opt in helpdct.get('params', [])
20+
}

0 commit comments

Comments
 (0)