Skip to content

Commit 6fb67a5

Browse files
Patrick Kidger Botpatrick-kidger
authored andcommitted
Add mkdocs documentation site
1 parent 931be62 commit 6fb67a5

27 files changed

Lines changed: 886 additions & 17 deletions

.github/workflows/build_docs.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
python-version: [ 3.11 ]
13+
os: [ ubuntu-latest ]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install '.[docs]'
28+
29+
- name: Build docs
30+
run: |
31+
mkdocs build
32+
33+
- name: Upload docs
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: docs
37+
path: site # where `mkdocs build` puts the built site

.github/workflows/run_tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
26-
python -m pip install '.[dev,tests]'
26+
python -m pip install '.[dev,docs,tests]'
2727
2828
- name: Checks with pre-commit
2929
run: |
@@ -32,3 +32,7 @@ jobs:
3232
- name: Test with pytest
3333
run: |
3434
pytest
35+
36+
- name: Check that documentation can be built.
37+
run: |
38+
mkdocs build

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ git push
3838

3939
Finally, open a pull request on GitHub!
4040

41+
---
42+
43+
**If you're making changes to the documentation:**
44+
45+
Make your changes. You can then build the documentation by doing
46+
47+
```bash
48+
pip install -e '.[docs]'
49+
mkdocs serve
50+
```
51+
52+
You can then see your local copy of the documentation by navigating to `localhost:8000` in a web browser.
53+

docs/.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ErrorDocument 404 /tinyio/404.html
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% import "partials/language.html" as lang with context %}
2+
<a href="{{ config.repo_url }}" title="{{ lang.t('source.link.title') }}" class="md-source" data-md-component="source">
3+
<div class="md-source__icon md-icon">
4+
{% set icon = config.theme.icon.repo or "fontawesome/brands/git-alt" %}
5+
{% include ".icons/" ~ icon ~ ".svg" %}
6+
</div>
7+
<div class="md-source__repository">
8+
{{ config.repo_name }}
9+
</div>
10+
</a>
11+
<a href="{{ config.theme.twitter_url }}" title="Go to Twitter" class="md-source">
12+
<div class="md-source__icon md-icon">
13+
{% include ".icons/fontawesome/brands/twitter.svg" %}
14+
</div>
15+
</a>
16+
<a href="{{ config.theme.bluesky_url }}" title="Go to Bluesky" class="md-source">
17+
<div class="md-source__icon md-icon">
18+
{% include ".icons/fontawesome/brands/bluesky.svg" %}
19+
</div>
20+
<div class="md-source__repository">
21+
{{ config.theme.twitter_bluesky_name }}
22+
</div>
23+
</a>

docs/_static/custom_css.css

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/* Fix /page#foo going to the top of the viewport and being hidden by the navbar */
2+
html {
3+
scroll-padding-top: 50px;
4+
}
5+
6+
/* Fit the Twitter handle alongside the GitHub one in the top right. */
7+
8+
div.md-header__source {
9+
width: revert;
10+
max-width: revert;
11+
}
12+
13+
a.md-source {
14+
display: inline-block;
15+
}
16+
17+
.md-source__repository {
18+
max-width: 100%;
19+
}
20+
21+
/* Emphasise sections of nav on left hand side */
22+
23+
nav.md-nav {
24+
padding-left: 5px;
25+
}
26+
27+
nav.md-nav--secondary {
28+
border-left: revert !important;
29+
}
30+
31+
.md-nav__title {
32+
font-size: 0.9rem;
33+
}
34+
35+
.md-nav__item--section > .md-nav__link {
36+
font-size: 0.9rem;
37+
}
38+
39+
/* Indent autogenerated documentation */
40+
41+
div.doc-contents {
42+
padding-left: 25px;
43+
border-left: 4px solid rgba(230, 230, 230);
44+
}
45+
46+
/* Increase visibility of splitters "---" */
47+
48+
[data-md-color-scheme="default"] .md-typeset hr {
49+
border-bottom-color: rgb(0, 0, 0);
50+
border-bottom-width: 1pt;
51+
}
52+
53+
[data-md-color-scheme="slate"] .md-typeset hr {
54+
border-bottom-color: rgb(230, 230, 230);
55+
}
56+
57+
/* More space at the bottom of the page */
58+
59+
.md-main__inner {
60+
margin-bottom: 1.5rem;
61+
}
62+
63+
/* Remove prev/next footer buttons */
64+
65+
.md-footer__inner {
66+
display: none;
67+
}
68+
69+
/* Change font sizes */
70+
71+
html {
72+
/* Decrease font size for overall webpage
73+
Down from 137.5% which is the Material default */
74+
font-size: 110%;
75+
}
76+
77+
.md-typeset .admonition {
78+
/* Increase font size in admonitions */
79+
font-size: 100% !important;
80+
}
81+
82+
.md-typeset details {
83+
/* Increase font size in details */
84+
font-size: 100% !important;
85+
}
86+
87+
.md-typeset h1 {
88+
font-size: 1.6rem;
89+
}
90+
91+
.md-typeset h2 {
92+
font-size: 1.5rem;
93+
}
94+
95+
.md-typeset h3 {
96+
font-size: 1.3rem;
97+
}
98+
99+
.md-typeset h4 {
100+
font-size: 1.1rem;
101+
}
102+
103+
.md-typeset h5 {
104+
font-size: 0.9rem;
105+
}
106+
107+
.md-typeset h6 {
108+
font-size: 0.8rem;
109+
}
110+
111+
/* Bugfix: remove the superfluous parts generated when doing:
112+
113+
??? Blah
114+
115+
::: library.something
116+
*/
117+
118+
.md-typeset details .mkdocstrings > h4 {
119+
display: none;
120+
}
121+
122+
.md-typeset details .mkdocstrings > h5 {
123+
display: none;
124+
}
125+
126+
/* Change default colours for <a> tags */
127+
128+
[data-md-color-scheme="default"] {
129+
--md-typeset-a-color: rgb(0, 189, 164) !important;
130+
}
131+
[data-md-color-scheme="slate"] {
132+
--md-typeset-a-color: rgb(0, 189, 164) !important;
133+
}
134+
135+
/* Highlight functions, classes etc. type signatures. Really helps to make clear where
136+
one item ends and another begins. */
137+
138+
[data-md-color-scheme="default"] {
139+
--doc-heading-color: #DDD;
140+
--doc-heading-border-color: #CCC;
141+
--doc-heading-color-alt: #F0F0F0;
142+
}
143+
[data-md-color-scheme="slate"] {
144+
--doc-heading-color: rgb(25,25,33);
145+
--doc-heading-border-color: rgb(25,25,33);
146+
--doc-heading-color-alt: rgb(33,33,44);
147+
--md-code-bg-color: rgb(38,38,50);
148+
}
149+
150+
h4.doc-heading {
151+
/* NOT var(--md-code-bg-color) as that's not visually distinct from other code blocks.*/
152+
background-color: var(--doc-heading-color);
153+
border: solid var(--doc-heading-border-color);
154+
border-width: 1.5pt;
155+
border-radius: 2pt;
156+
padding: 0pt 5pt 2pt 5pt;
157+
}
158+
h5.doc-heading, h6.heading {
159+
background-color: var(--doc-heading-color-alt);
160+
border-radius: 2pt;
161+
padding: 0pt 5pt 2pt 5pt;
162+
}
163+
164+
/* Fix spurious whitespace at the end of mkdocstrings output */
165+
166+
div.output_wrapper > div.output > div.output_area > div.output_subarea > pre {
167+
white-space: normal;
168+
}
169+
170+
div.output_wrapper > div.output > div.output_area > div.output_subarea > pre > code {
171+
white-space: pre;
172+
}

docs/_static/favicon.png

690 Bytes
Loading

docs/_static/mathjax.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
window.MathJax = {
2+
tex: {
3+
inlineMath: [["\\(", "\\)"]],
4+
displayMath: [["\\[", "\\]"]],
5+
processEscapes: true,
6+
processEnvironments: true
7+
},
8+
options: {
9+
ignoreHtmlClass: ".*|",
10+
processHtmlClass: "arithmatex"
11+
}
12+
};
13+
14+
document$.subscribe(() => {
15+
MathJax.typesetPromise()
16+
})

docs/api/async_context_managers.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Asynchronous context managers
2+
3+
You can use the following pattern to implement context managers with asynchronous entry:
4+
5+
```python
6+
def my_coro():
7+
with (yield my_context_manager(x=5)) as val:
8+
print(f"Got val {val}")
9+
```
10+
where:
11+
```python
12+
def my_context_manager(x):
13+
print("Initialising...")
14+
yield tinyio.sleep(1)
15+
print("Initialised")
16+
return make_context_manager(x)
17+
18+
@contextlib.contextmanager
19+
def make_context_manager(x):
20+
try:
21+
yield x
22+
finally:
23+
print("Cleaning up")
24+
```
25+
26+
This isn't anything fancier than just using a coroutine that returns a regular `with`-compatible context manager. See the source code for [`tinyio.Semaphore`][] for an example of this pattern.

docs/api/async_iterators.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Asynchronous iterators
2+
3+
You can use the following pattern to implement asynchronous iterators:
4+
5+
```python
6+
def my_coro():
7+
for x in slow_range(5):
8+
x = yield x
9+
print(f"Got {x}")
10+
```
11+
where:
12+
```python
13+
def slow_range(x): # this function is an iterator-of-coroutines
14+
for i in range(x):
15+
yield slow_range_i(i) # this `yield` statement is seen by the `for` loop
16+
17+
def slow_range_i(i): # this function is a coroutine
18+
yield tinyio.sleep(1) # this `yield` statement is seen by the `tinyio.Loop()`
19+
return i
20+
```
21+
22+
Here we just have `yield` being used in a couple of different ways that you're already used to:
23+
24+
- as a regular Python generator/iterator;
25+
- as a `tinyio` coroutine.
26+
27+
For an example of this, see the source code for [`tinyio.as_completed`][].

0 commit comments

Comments
 (0)