Skip to content

Commit 5df2b06

Browse files
authored
Add some text to packaging (#37)
1 parent 90f3073 commit 5df2b06

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

docs/part1/packaging.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,53 @@
22

33
To be able to create a python package, we need a folder with the name of the package (in this repository it is called `mypackage`, located under `src/mypackage`), and a `pyproject.toml` file.
44

5+
## Repository structure
6+
We recommend using the source layout. See [this chapter](https://py-pkgs.org/04-package-structure.html#the-source-layout) for justification.
7+
58

69
## Pyproject.toml
10+
A [toml](https://toml.io/en/) (Tom's Obivous Minimal Language) file is a plain-text file, consisting of [tables](https://toml.io/en/v1.0.0#table)
11+
which are a selection of key-value pairs.
12+
13+
An example is
14+
```toml
15+
[project]
16+
name = "catch_us"
17+
authors = [
18+
{name = "Per Ulv", email = "[email protected]"},
19+
{name = "Bippe Stankelbein", email = "[email protected]"}
20+
]
21+
version = "x.y.z"
22+
description = "Meep Meep"
23+
# "readme" the description field in your package,
24+
# see: https://python-poetry.org/docs/pyproject/#readme
25+
readme = "README.md"
26+
requires-python = ">=3.8"
27+
# Path to license file, see: https://spdx.org/licenses/
28+
# for a selection of licenses
29+
license = {file = "LICENSE"}
30+
# Direct dependencies
31+
dependencies = [
32+
'acme',
33+
'numpy'
34+
]
35+
```
36+
37+
### Optional dependencies
38+
The core functionality of a package (its classes and functions) might not depend on many other packages.
39+
40+
However, to be able to test the code, check for consistency and create coverage reports, one might meed additional dependencies.
41+
42+
One can therefore specify a second table in the `pyproject.toml` file, called
43+
[project.optional-depencies].
44+
This is treated as a sub-table of `project`.
45+
46+
For instance, if you want to test your package with [pytest](https://docs.pytest.org/en/7.1.x/), you can add
47+
```toml
48+
[project.optional-dependencies]
49+
test = ["pytest"]
50+
```
51+
Then, when installing the package, you call `pip3 install .[test]` instead of `pip3 install .` to get the additional dependencies.
752

53+
### Other tables
54+
For options related to coverage reports and code consistency, see the [Coverage](./coverage) and [Linting](./linting.md) section, respectively.

pyproject.toml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
[build-system] # Require setuptool version due to https://github.com/pypa/setuptools/issues/2938
22
requires = ["setuptools>=61.0.0", "wheel"]
33

4-
5-
[project] # See https://python-poetry.org/docs/pyproject/ for more keywords
6-
name = "mypackage" # Name of your package
7-
authors = [ # List of authors
8-
{name = "Jørgen S. Dokken", email = "[email protected]"}
4+
# See https://python-poetry.org/docs/pyproject/ for more keywords for the project table
5+
[project]
6+
# Name of your package
7+
name = "mypackage"
8+
authors = [
9+
{name = "Jørgen S. Dokken", email = "[email protected]"},
10+
{name = "Henrik N. Finsberg", email = "[email protected]"}
911
]
10-
version = "0.1.0" # Version number
11-
description = "Minimal package for adding two numbers" # Short description of package
12-
readme = "README.md" # Is used for the description field in your package, see: https://python-poetry.org/docs/pyproject/#readme
13-
requires-python = ">=3.8" # Set requirement for minimal python version
14-
license = {file = "LICENSE"} # Path to license file, see: https://spdx.org/licenses/ for options
12+
version = "0.1.0"
13+
description = "Minimal package for adding two numbers"
14+
# "readme" the description field in your package, see: https://python-poetry.org/docs/pyproject/#readme
15+
readme = "README.md"
16+
requires-python = ">=3.8"
17+
# Path to license file, see: https://spdx.org/licenses/ for options
18+
license = {file = "LICENSE"}
19+
# Direct dependencies
1520
dependencies = [
1621
'numpy'
1722
]
1823

1924

2025
[project.optional-dependencies]
2126
test = [
22-
"flake8", # Checks code for consistency, see: https://flake8.pycqa.org/en/latest/user/error-codes.html
23-
"mypy", # Makes sure that typing of input/output is consistent
24-
"pytest", # To run test
25-
"pytest-cov" # To create coverage reports
27+
"flake8", # Formatting: https://flake8.pycqa.org/en/latest/user/error-codes.html
28+
"mypy", # Input/Output consistency
29+
"pytest", # Testing suite
30+
"pytest-cov" # Coverage reports
2631
]
2732

2833
docs = [

0 commit comments

Comments
 (0)