Skip to content

Commit 469647e

Browse files
Merge branch 'master' into django-flashcards-app
2 parents d7eb0da + 87a4437 commit 469647e

File tree

202 files changed

+33584
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+33584
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Build Your Python Project Documentation With MkDocs
2+
3+
This folder contains the source code and an example documentation built with [MkDocs](https://www.mkdocs.org), using the [Material for MkDocs](https://github.com/squidfunk/mkdocs-material) theme and the [mkdocstrings](https://mkdocstrings.github.io) plugin for docstring code discovery.
4+
5+
The code used is intentionally kept basic and represents an unnecessary reproduction of fundamental math operations. This is done to keep the focus on _documenting_ a Python project, rather than the project's code.
6+
7+
You should be able to follow the same process and use the same concepts for your own Python project with more interesting code.
8+
9+
## Setup
10+
11+
To view the documentation project, navigate to `source_code_final/` and install the dependencies into a new virtual environment:
12+
13+
**Linux, macOS:**
14+
15+
```bash
16+
$ cd source_code_final
17+
$ python3 -m venv venv
18+
$ source venv/bin/activate
19+
(venv) $ python -m pip install -r requirements.txt
20+
```
21+
22+
**Windows:**
23+
24+
```powershell
25+
PS> cd source_code_final
26+
PS> python -m venv venv
27+
PS> venv\bin\Activate.ps1
28+
(venv) PS> python -m pip install -r requirements.txt
29+
```
30+
31+
Once you're set up and you've installed the dependencies, you can serve the project:
32+
33+
```bash
34+
(venv) $ mkdocs serve
35+
```
36+
37+
Navigate to your localhost at port `8000` to view the generated documentation.
38+
39+
## Notes
40+
41+
Part of the documentation is auto-generated from docstrings in `source_code_final/calculator/`. The mkdocstrings package renders docstrings from module and package-level docstrings, as well as function docstrings in `calculations.py`.
42+
43+
You can find the relevant notation in `docs/index.md` and `docs/reference.md`.
44+
45+
The rest of the documentation is written in Markdown and split up across several files in the `docs/` directory.
46+
47+
In this project you can see that you can create project documentation that is partly auto-generated from your docstrings, interweaved with explanatory text and best-practice project documentation structure.
48+
49+
There is also an associated tutorial where you can learn how to [Build Your Python Project Documentation With MkDocs](https://realpython.com/python-project-documentation-with-mkdocs) step-by-step.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Do math with your own functions.
2+
3+
Modules exported by this package:
4+
5+
- `calculations`: Provide several sample math calculations.
6+
"""
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"""Provide several sample math calculations.
2+
3+
This module allows the user to make mathematical calculations.
4+
5+
Examples:
6+
>>> from calculator import calculations
7+
>>> calculations.add(2, 4)
8+
6.0
9+
>>> calculations.multiply(2.0, 4.0)
10+
8.0
11+
>>> from calculator.calculations import divide
12+
>>> divide(4.0, 2)
13+
2.0
14+
15+
The module contains the following functions:
16+
17+
- `add(a, b)` - Returns the sum of two numbers.
18+
- `subtract(a, b)` - Returns the difference of two numbers.
19+
- `multiply(a, b)` - Returns the product of two numbers.
20+
- `divide(a, b)` - Returns the quotient of two numbers.
21+
"""
22+
23+
from typing import Union
24+
25+
26+
def add(a: Union[float, int], b: Union[float, int]) -> float:
27+
"""Compute and return the sum of two numbers.
28+
29+
Examples:
30+
>>> add(4.0, 2.0)
31+
6.0
32+
>>> add(4, 2)
33+
6.0
34+
35+
Args:
36+
a: A number representing the first addend in the addition.
37+
b: A number representing the second addend in the addition.
38+
39+
Returns:
40+
A number representing the artihmetic sum of `a` and `b`.
41+
"""
42+
43+
return float(a + b)
44+
45+
46+
def subtract(a: Union[float, int], b: Union[float, int]) -> float:
47+
"""Calculate the difference of two numbers.
48+
49+
Examples:
50+
>>> subtract(4.0, 2.0)
51+
2.0
52+
>>> subtract(4, 2)
53+
2.0
54+
55+
Args:
56+
a: A number representing the minuend in the subtraction.
57+
b: A number representing the subtrahend in the subtraction.
58+
59+
Returns:
60+
A number representing the difference between `a` and `b`.
61+
"""
62+
63+
return float(a - b)
64+
65+
66+
def multiply(a: Union[float, int], b: Union[float, int]) -> float:
67+
"""Compute and return the product of two numbers.
68+
69+
Examples:
70+
>>> multiply(4.0, 2.0)
71+
8.0
72+
>>> multiply(4, 2)
73+
8.0
74+
75+
Args:
76+
a: A number representing the multiplicand in the multiplication.
77+
b: A number representing the multiplier in the multiplication.
78+
79+
Returns:
80+
A number representing the product of `a` and `b`.
81+
"""
82+
83+
return float(a * b)
84+
85+
86+
def divide(a: Union[float, int], b: Union[float, int]) -> float:
87+
"""Compute and return the quotient of two numbers.
88+
89+
Examples:
90+
>>> divide(4.0, 2.0)
91+
2.0
92+
>>> divide(4, 2)
93+
2.0
94+
>>> divide(4, 0)
95+
Traceback (most recent call last):
96+
...
97+
ZeroDivisionError: division by zero
98+
99+
Args:
100+
a: A number representing the dividend in the division.
101+
b: A number representing the divisor in the division.
102+
103+
Returns:
104+
A number representing the quotient of `a` and `b`.
105+
106+
Raises:
107+
ZeroDivisionError: An error occurs when the divisor is `0`.
108+
"""
109+
110+
if b == 0:
111+
raise ZeroDivisionError("division by zero")
112+
return float(a / b)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Explanation
2+
3+
This part of the project documentation focuses on an
4+
**understanding-oriented** approach. You'll get a
5+
chance to read about the background of the project,
6+
as well as reasoning about how it was implemented.
7+
8+
> **Note:** Expand this section by considering the
9+
> following points:
10+
11+
- Give context and background on your library
12+
- Explain why you created it
13+
- Provide multiple examples and approaches of how
14+
to work with it
15+
- Help the reader make connections
16+
- Avoid writing instructions or technical descriptions
17+
here
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# How-To Guides
2+
3+
This part of the project documentation focuses on a
4+
**problem-oriented** approach. You'll tackle common
5+
tasks that you might have, with the help of the code
6+
provided in this project.
7+
8+
## How To Add Two Numbers?
9+
10+
You have two numbers and you need to add them together.
11+
You're in luck! The `calculator` package can help you
12+
get this done.
13+
14+
Download the code from this GitHub repository and place
15+
the `calculator/` folder in the same directory as your
16+
Python script:
17+
18+
your_project/
19+
20+
├── calculator/
21+
│ ├── __init__.py
22+
│ └── calculations.py
23+
24+
└── your_script.py
25+
26+
Inside of `your_script.py` you can now import the
27+
`add()` function from the `calculator.calculations`
28+
module:
29+
30+
# your_script.py
31+
from calculator.calculations import add
32+
33+
After you've imported the function, you can use it
34+
to add any two numbers that you need to add:
35+
36+
# your_script.py
37+
from calculator.calculations import add
38+
39+
print(add(20, 22)) # OUTPUT: 42.0
40+
41+
You're now able to add any two numbers, and you'll
42+
always get a `float` as a result.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Calculator Docs
2+
3+
This site contains the project documentation for the
4+
`calculator` project that is a toy module used in the
5+
Real Python tutorial
6+
[Build Your Python Project Documentation With MkDocs](
7+
https://realpython.com/python-project-documentation-with-mkdocs/).
8+
Its aim is to give you a framework to build your
9+
project documentation using Python, MkDocs,
10+
mkdocstrings, and the Material for MkDocs theme.
11+
12+
## Table Of Contents
13+
14+
The documentation follows the best practice for
15+
project documentation as described by Daniele Procida
16+
in the [Diátaxis documentation framework](https://diataxis.fr/)
17+
and consists of four separate parts:
18+
19+
1. [Tutorials](tutorials.md)
20+
2. [How-To Guides](how-to-guides.md)
21+
3. [Reference](reference.md)
22+
4. [Explanation](explanation.md)
23+
24+
Quickly find what you're looking for depending on
25+
your use case by looking at the different pages.
26+
27+
## Project Overview
28+
29+
::: calculator.__init__
30+
31+
## Acknowledgements
32+
33+
I want to thank my house plants for providing me with
34+
a negligible amount of oxygen each day. Also, I want
35+
to thank the sun for providing more than half of their
36+
nourishment free of charge.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Reference
2+
3+
This part of the project documentation focuses on
4+
an **information-oriented** approach. Use it as a
5+
reference for the technical implementation of the
6+
`calculator` project code.
7+
8+
::: calculator.calculations
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Tutorials
2+
3+
This part of the project documentation focuses on a
4+
**learning-oriented** approach. You'll learn how to
5+
get started with the code in this project.
6+
7+
> **Note:** Expand this section by considering the
8+
> following points:
9+
10+
- Help newcomers with getting started
11+
- Teach readers about your library by making them
12+
write code
13+
- Inspire confidence through examples that work for
14+
everyone, repeatably
15+
- Give readers an immediate sense of achievement
16+
- Show concrete examples, no abstractions
17+
- Provide the minimum necessary explanation
18+
- Avoid any distractions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
site_name: Calculation Docs
2+
3+
theme:
4+
name: "material"
5+
6+
plugins:
7+
- mkdocstrings
8+
9+
nav:
10+
- Calculation Docs: index.md
11+
- tutorials.md
12+
- How-To Guides: how-to-guides.md
13+
- reference.md
14+
- explanation.md
15+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
click==8.1.3
2+
ghp-import==2.1.0
3+
importlib-metadata==4.11.3
4+
Jinja2==3.1.2
5+
Markdown==3.3.6
6+
MarkupSafe==2.1.1
7+
mergedeep==1.3.4
8+
mkdocs==1.3.0
9+
mkdocs-autorefs==0.4.1
10+
mkdocs-material==8.2.13
11+
mkdocs-material-extensions==1.0.3
12+
mkdocstrings==0.18.1
13+
mkdocstrings-python-legacy==0.2.2
14+
packaging==21.3
15+
Pygments==2.12.0
16+
pymdown-extensions==9.4
17+
pyparsing==3.0.8
18+
python-dateutil==2.8.2
19+
pytkdocs==0.16.1
20+
PyYAML==6.0
21+
pyyaml_env_tag==0.1
22+
six==1.16.0
23+
watchdog==2.1.7
24+
zipp==3.8.0

0 commit comments

Comments
 (0)