Skip to content

Commit dc33c98

Browse files
authored
Rename (#7)
* ♻️ use only two names, reduce template complexity a bit * 🎨 describe and format cicd GitHub Action * 🎨 remove headings ( toc tree is not included in overview) * 🎨 update tutorial with some more comments * 🎨 add cross-reference to api doc and print docstring * 🎨 change link text * 💥 require minimal supported Python version, fix parameter in docstring
1 parent 8ac3af4 commit dc33c98

File tree

15 files changed

+201
-350
lines changed

15 files changed

+201
-350
lines changed

.github/workflows/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Workflows
2+
3+
## cicd
4+
5+
Basic continuous integration and deployment (CI/CD) workflow for Python packages.
6+
7+
- checks formatting (black)
8+
- checks linting (ruff)
9+
- run unit tests (pytest)
10+
- optional: add c extensions to a package
11+
- if all checks pass, build and deploy to PyPI if `tag` triggered the workflow

.github/workflows/cicd.yml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ name: Python application
66
on:
77
push:
88
pull_request:
9-
branches: [ "main" ]
9+
branches: ["main"]
1010
schedule:
11-
- cron: '0 2 * * 3'
11+
- cron: "0 2 * * 3"
1212

1313
permissions:
1414
contents: read
1515

16-
1716
jobs:
1817
format:
1918
runs-on: ubuntu-latest
2019
steps:
2120
- uses: actions/checkout@v4
22-
- uses: psf/black@stable
21+
- uses: psf/black@stable
2322
lint:
2423
name: Lint with ruff
2524
runs-on: ubuntu-latest
@@ -30,9 +29,9 @@ jobs:
3029
with:
3130
python-version: "3.11"
3231
- name: Install ruff
33-
run: |
32+
run: |
3433
pip install ruff
35-
- name: Lint with ruff
34+
- name: Lint with ruff
3635
run: |
3736
# stop the build if there are Python syntax errors or undefined names
3837
ruff check .
@@ -48,36 +47,36 @@ jobs:
4847
uses: actions/setup-python@v5
4948
with:
5049
python-version: ${{ matrix.python-version }}
51-
cache: 'pip' # caching pip dependencies
52-
cache-dependency-path: '**/pyproject.toml'
50+
cache: "pip" # caching pip dependencies
51+
cache-dependency-path: "**/pyproject.toml"
5352
- name: Install dependencies
5453
run: |
5554
python -m pip install --upgrade pip
5655
pip install pytest
5756
pip install -e .
5857
- name: Run tests
5958
run: python -m pytest tests
60-
59+
6160
build_source_dist:
6261
name: Build source distribution
6362
if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags')
6463
runs-on: ubuntu-latest
6564
steps:
66-
- uses: actions/checkout@v4
65+
- uses: actions/checkout@v4
6766

68-
- uses: actions/setup-python@v5
69-
with:
70-
python-version: "3.10"
67+
- uses: actions/setup-python@v5
68+
with:
69+
python-version: "3.10"
7170

72-
- name: Install build
73-
run: python -m pip install build
71+
- name: Install build
72+
run: python -m pip install build
7473

75-
- name: Run build
76-
run: python -m build --sdist
74+
- name: Run build
75+
run: python -m build --sdist
7776

78-
- uses: actions/upload-artifact@v4
79-
with:
80-
path: ./dist/*.tar.gz
77+
- uses: actions/upload-artifact@v4
78+
with:
79+
path: ./dist/*.tar.gz
8180
# Needed in case of building packages with external binaries (e.g. Cython, RUst-extensions, etc.)
8281
# build_wheels:
8382
# name: Build wheels on ${{ matrix.os }}
@@ -105,25 +104,25 @@ jobs:
105104
# path: ./wheels/*.whl
106105

107106
publish:
108-
name: Publish package
109-
if: startsWith(github.ref, 'refs/tags')
110-
needs:
111-
- format
112-
- lint
113-
- test
114-
- build_source_dist
115-
# - build_wheels
116-
runs-on: ubuntu-latest
117-
118-
steps:
119-
- uses: actions/download-artifact@v4
120-
with:
121-
name: artifact
122-
path: ./dist
123-
124-
- uses: pypa/gh-action-pypi-publish@release/v1
125-
with:
126-
# remove repository key to set the default to pypi (not test.pypi.org)
127-
repository-url: https://test.pypi.org/legacy/
128-
user: __token__
129-
password: ${{ secrets.PYPI_API_TOKEN }}
107+
name: Publish package
108+
if: startsWith(github.ref, 'refs/tags')
109+
needs:
110+
- format
111+
- lint
112+
- test
113+
- build_source_dist
114+
# - build_wheels
115+
runs-on: ubuntu-latest
116+
117+
steps:
118+
- uses: actions/download-artifact@v4
119+
with:
120+
name: artifact
121+
path: ./dist
122+
123+
- uses: pypa/gh-action-pypi-publish@release/v1
124+
with:
125+
# remove repository key to set the default to pypi (not test.pypi.org)
126+
repository-url: https://test.pypi.org/legacy/
127+
user: __token__
128+
password: ${{ secrets.PYPI_API_TOKEN }}

README.md

Lines changed: 11 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -5,126 +5,12 @@
55
Can be used as GitHub template repository,
66
see [GitHub documentation](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).
77

8-
You will need to find and replace occurences of
8+
You will need to find and replace occurences of
99

10-
- `mockup` -> `your_package_name`
11-
- `rasmussenlab-mockup` -> `your_package_name`
12-
- `RasmussenLab` -> `GitHub_user_name` (or organization)
1310
- `python_package` -> `your_package_name`
11+
- `RasmussenLab` -> `GitHub_user_name` (or `organization`)
1412

15-
with the name of your package and GitHub user name (or organization). This still might
16-
need further testing:
17-
18-
```bash
19-
# currently these are (v24.03)
20-
21-
pyproject.toml:
22-
5 description = "A small example package"
23-
6: name = "rasmussenlab-mockup"
24-
7 # This means: Load the version from the package itself.
25-
26-
README.md:
27-
7
28-
8: You will need to find and replace occurences of `mockup` with the name of your package. This still might
29-
9 need further testing.
30-
31-
22
32-
23: Install vom [TestPyPI](https://test.pypi.org/project/rasmussenlab-mockup):
33-
24
34-
25 ```
35-
26: pip install -i https://test.pypi.org/simple/ rasmussenlab-mockup
36-
27 ```
37-
28
38-
29: > The package on PyPI is call `rasmussenlab-mockup` and not `mockup` as the package name is already taken. The import is still `import mockup`.
39-
30
40-
41-
docs\conf.py:
42-
18
43-
19: project = "mockup"
44-
20 copyright = "2024, Jakob Nybo Nissen, Henry Webel"
45-
21 author = "Jakob Nybo Nissen, Henry Webel"
46-
22: PACKAGE_VERSION = metadata.version("rasmussenlab-mockup")
47-
23 version = PACKAGE_VERSION
48-
49-
119 PROJECT_ROOT = Path(__file__).parent.parent
50-
120: PACKAGE_ROOT = PROJECT_ROOT / "src" / "mockup"
51-
121
52-
53-
docs\index.rst:
54-
1: .. mockup documentation master file, created by
55-
2 sphinx-quickstart on Mon Aug 28 14:09:15 2023.
56-
57-
5
58-
6: The mockup package
59-
7 ==================================
60-
8
61-
9: Mockup is a Python package with some simple example code.
62-
10: To get started, explore the :class:`mockup.Circle` class.
63-
11
64-
65-
docs\README.md:
66-
27 # apidoc
67-
28: sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/mockup
68-
29 # build docs
69-
70-
docs\tutorial\tutorial.ipynb:
71-
6 "source": [
72-
7: "# Mockup tutorial"
73-
8 ]
74-
75-
15 "source": [
76-
16: "from mockup import mockup"
77-
17 ]
78-
79-
24 "source": [
80-
25: "mockup.add_one(-11)"
81-
26 ]
82-
83-
33 "source": [
84-
34: "list(mockup.flatten_ints([[9, 11], [12], [4, 5]]))"
85-
35 ]
86-
87-
42 "source": [
88-
43: "c2 = mockup.Circle.from_circumference(100)\n",
89-
44 "round(c2.radius, 3)"
90-
91-
src\mockup\__init__.py:
92-
6
93-
7: __version__ = metadata.version("rasmussenlab-mockup")
94-
8
95-
9: from .mockup import add_one, Circle
96-
10
97-
98-
tests\test_circle.py:
99-
1 import unittest
100-
2: from mockup.mockup import Circle
101-
3
102-
```
103-
104-
And additionally the author names:
105-
106-
```bash
107-
pyproject.toml:
108-
1 [project]
109-
2: authors = [
110-
3 {name = "Jakob Nybo Nissen", email = "[email protected]"},
111-
112-
README.md:
113-
37 20 copyright = "2024, Jakob Nybo Nissen, Henry Webel"
114-
38: 21 author = "Jakob Nybo Nissen, Henry Webel"
115-
39 22: PACKAGE_VERSION = metadata.version("rasmussenlab-mockup")
116-
117-
96
118-
97: And additionally the author names:
119-
98
120-
121-
docs\conf.py:
122-
20 copyright = "2024, Jakob Nybo Nissen, Henry Webel"
123-
21: author = "Jakob Nybo Nissen, Henry Webel"
124-
22 PACKAGE_VERSION = metadata.version("rasmussenlab-mockup")
125-
```
126-
127-
> Potentially a cookiecutter could be based on this template repository.
13+
with the name of your package and GitHub user name (or organization).
12814

12915
## Development environment
13016

@@ -134,20 +20,19 @@ Install package so that new code is picked up in a restared python interpreter:
13420
pip install -e ".[dev]"
13521
```
13622

137-
## TestPyPI
23+
## Basic usage
13824

139-
Install vom [TestPyPI](https://test.pypi.org/project/rasmussenlab-mockup):
140-
141-
```
142-
pip install -i https://test.pypi.org/simple/ rasmussenlab-mockup
25+
```python
26+
from python_package import hello_world
27+
print (python_package.__version__)
28+
print(hello_world(4))
14329
```
14430

145-
> The package on PyPI is call `rasmussenlab-mockup` and not `mockup` as the package name is already taken. The import is still `import mockup`.
146-
14731
## Readthedocs
14832

149-
The documentation is build using readthedocs automatically. See
150-
[project on Readthedocs](https://readthedocs.org/projects/rasmussenlab-python-package/).
33+
The documentation can be build using readthedocs automatically. See
34+
[project on Readthedocs](https://readthedocs.org/projects/rasmussenlab-python-package/) for the project. A new project needs
35+
to be registered.
15136

15237
- make sure to enable build from PRs in the settings (advanded settings)
15338
- checkout configuration file: [`.readthedocs.yaml`](.readthedocs.yaml)

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Options:
2525
```bash
2626
# pwd: docs
2727
# apidoc
28-
sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/mockup
28+
sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/python_package
2929
# build docs
3030
sphinx-build -n -W --keep-going -b html ./ ./_build/
3131
```

docs/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
# -- Project information -----------------------------------------------------
1717

18-
project = "mockup"
19-
copyright = "2024, Jakob Nybo Nissen, Henry Webel"
18+
project = "python_package"
19+
copyright = "2025, Jakob Nybo Nissen, Henry Webel"
2020
author = "Jakob Nybo Nissen, Henry Webel"
21-
PACKAGE_VERSION = metadata.version("rasmussenlab-mockup")
21+
PACKAGE_VERSION = metadata.version("python_package")
2222
version = PACKAGE_VERSION
2323
release = PACKAGE_VERSION
2424

@@ -128,7 +128,7 @@
128128
from pathlib import Path
129129

130130
PROJECT_ROOT = Path(__file__).parent.parent
131-
PACKAGE_ROOT = PROJECT_ROOT / "src" / "mockup"
131+
PACKAGE_ROOT = PROJECT_ROOT / "src" / "python_package"
132132

133133
def run_apidoc(_):
134134
from sphinx.ext import apidoc

docs/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Python Package Documentation
2+
3+
```{include} ../README.md
4+
:start-line: 0
5+
:relative-docs: docs
6+
:relative-images:
7+
```
8+
9+
<!-- hidden toc trees for sidebar -->
10+
11+
```{toctree}
12+
:maxdepth: 2
13+
:caption: "Tutorials"
14+
:hidden: true
15+
16+
tutorial/tutorial
17+
```
18+
19+
```{toctree}
20+
:maxdepth: 2
21+
:caption: "Reference"
22+
:hidden: true
23+
24+
reference/python_package
25+
```
26+
27+
```{toctree}
28+
:maxdepth: 2
29+
:caption: "Technical notes"
30+
:hidden: true
31+
32+
README
33+
```
34+
35+
## Indices and tables
36+
37+
- [Index](genindex)
38+
- [Module Index](modindex)
39+
- [Search](search)

0 commit comments

Comments
 (0)