Skip to content

Commit 76124eb

Browse files
committed
2 parents 9d8bce4 + 6f92a88 commit 76124eb

32 files changed

+748
-437
lines changed

.github/workflows/parse_changelog.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import re
2+
import sys
3+
4+
5+
def parse_changelog(contents):
6+
"""
7+
Parse the CHANGELOG.md and return a mapping from version to the section of the file
8+
corresponding to that version.
9+
10+
:param contents: The contents of CHANGELOG.md.
11+
"""
12+
result = {}
13+
14+
# Split the changelog into sections based on lines starting with '## '
15+
for section in re.split(r'\n## ', contents):
16+
# Clean up each part by removing the compare links at the bottom of the file, and by
17+
# stripping whitespace
18+
section = re.split(r'\[Unreleased\]', section)[0].strip()
19+
20+
# Add back the heading that was removed by re.split()
21+
section = '## ' + section
22+
23+
# Parse out the version of this section. Any section which doesn't have a version (such as
24+
# the '## Unreleased' section or the top introduction) are not kept.
25+
version_match = re.search(r'## \[([0-9.]+)\].*', section)
26+
if version_match and len(version_match.groups()) >= 1:
27+
result[version_match.group(1)] = section
28+
29+
return result
30+
31+
32+
if __name__ == '__main__':
33+
if len(sys.argv) < 4:
34+
print('Error: too few arguments.')
35+
sys.exit(1)
36+
37+
changelog_path = sys.argv[1]
38+
version = sys.argv[2].removeprefix('v')
39+
output_path = sys.argv[3]
40+
41+
with open(changelog_path, 'r') as f:
42+
changelog_sections = parse_changelog(f.read())
43+
44+
current_section = changelog_sections.get(version)
45+
if not current_section:
46+
print(f'Error: could not find changelog section for version {version}')
47+
sys.exit(2)
48+
49+
with open(output_path, 'w') as output:
50+
output.write(current_section)

.github/workflows/release.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
name: Release
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python 3.10
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.10"
23+
24+
- name: Install dependencies
25+
run: python -m pip install --upgrade pip build
26+
27+
- name: Build package
28+
run: python -m build .
29+
30+
- name: Parse changelog for release notes
31+
run: python .github/workflows/parse_changelog.py CHANGELOG.md ${{ github.ref_name }} body.md
32+
33+
- name: Publish package to PyPI
34+
if: startsWith(github.ref, 'refs/tags')
35+
uses: pypa/gh-action-pypi-publish@release/v1
36+
with:
37+
password: ${{ secrets.PYPI_API_TOKEN }}
38+
39+
- name: Create GitHub release
40+
uses: ncipollo/release-action@v1
41+
with:
42+
artifacts: "dist/*"
43+
bodyFile: "body.md"
44+
draft: true
45+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/run-examples.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: examples
2+
3+
on:
4+
push:
5+
# branches: [ master ]
6+
pull_request:
7+
# branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
13+
name: Run examples
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version: ["3.7", "3.8", "3.9", "3.10"]
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install .[examples]
32+
# The pyqt5 package may not be needed for non-interactive runs (such as
33+
# in this CI), but may be needed as a backend for Matplotlib to run
34+
# interactively.
35+
# pip install pyqt5
36+
37+
- name: Run examples
38+
run: |
39+
cd examples/water_boiler/
40+
NO_DISPLAY=1 python water_boiler.py
41+
42+
- name: Upload resulting figures
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: result-py${{ matrix.python-version }}.png
46+
path: examples/water_boiler/result-py${{ matrix.python-version }}.png

.github/workflows/run-tests.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
13+
name: Run tests
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.9"]
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install flake8 mypy pytest black colorama
32+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
34+
- name: Run tests with pytest
35+
run: |
36+
python -m pytest -v
37+
38+
- name: Lint with flake8
39+
run: |
40+
python -m flake8 . --count --statistics
41+
42+
- name: Run mypy
43+
run: |
44+
python -m mypy --strict simple_pid
45+
46+
- name: Run black
47+
run: |
48+
python -m black -l 100 -S --check --diff --color --exclude "docs/" .

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build/
99
.tox/
1010
*.pyc
1111
.idea/
12+
.vscode/
1213
.envrc
1314
build.sh
1415
total_downloads.py

.readthedocs.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.11"
13+
14+
# Build documentation in the docs/ directory with Sphinx
15+
sphinx:
16+
configuration: docs/source/conf.py
17+
18+
# Optionally declare the Python requirements required to build your docs
19+
python:
20+
install:
21+
- requirements: docs/requirements.txt

.travis.yml

-18
This file was deleted.

CHANGELOG.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [2.0.0] - 2023-04-28
11+
12+
### Added
13+
14+
- Ability to override the time function by setting PID.time_fn to whichever function to use
15+
- Black is now run in CI to detect formatting problems
16+
- Project is now defined by a pyproject.toml file instead of the old setup.py. The setup.cfg file remains for flake8 configuration for now.
17+
- Ability to give the PID a starting guess for its output, when you start controlling a system that is already at the setpoint and don't want the PID to start outputting 0
18+
- Option for specifying differential_on_measurement, to choose between calculating the derivative term on the input (default) or on the error (classic PID)
19+
20+
### Changed
21+
22+
- Rename the module `PID` to `pid` to avoid the shadowing from the `PID` class
23+
- CI migrated from Travis to GitHub Actions
24+
- The [documentation](https://simple-pid.readthedocs.io/) has gotten an overhaul and a new look. Much of the detailed documentation in README.md has been moved to a dedicated user guide.
25+
26+
### Fixed
27+
28+
- Fix mypy issue by explicitly exporting `PID`
29+
- Remove duplicated definition of `output_limits` in type stubs
30+
31+
### Deprecated
32+
33+
- Official support for Python 2 is dropped. While the code will likely keep working in Python 2 going forward, it's no longer tested in CI and no guarantees are given.
34+
35+
## [1.0.1] - 2021-04-11
36+
37+
### Fixed
38+
39+
- Added type information for public instance variables to typing stub
40+
41+
## [1.0.0] - 2021-03-20
42+
1043
### Added
1144

12-
- Function to map the erro value, now is possibly to clip the error value, i.e., [-pi, pi[
45+
- Function to map the error value to a different domain
1346

1447
- Typing information through a stub file so that users of the library can use e.g.
1548
[mypy](https://github.com/python/mypy) to type check their code
1649

1750
- This project now uses the [Black code style](https://github.com/psf/black)
1851

19-
- The PID class now has a \_\_repr\_\_() method, meaning that objects of this type can be printed
52+
- The PID class now has a `__repr__()` method, meaning that objects of this type can be printed
2053
directly for use during development
54+
55+
- MANIFEST.in file to ensure all necessary files are included in the source distribution
2156

2257
### Fixed
2358

@@ -79,7 +114,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
79114

80115
- Initial implementation
81116

82-
[Unreleased]: https://github.com/m-lundberg/simple-pid/compare/v0.2.4...HEAD
117+
[Unreleased]: https://github.com/m-lundberg/simple-pid/compare/v2.0.0...HEAD
118+
[2.0.0]: https://github.com/m-lundberg/simple-pid/compare/v1.0.1...v2.0.0
119+
[1.0.1]: https://github.com/m-lundberg/simple-pid/compare/v1.0.0...v1.0.1
120+
[1.0.0]: https://github.com/m-lundberg/simple-pid/compare/v0.2.4...v1.0.0
83121
[0.2.4]: https://github.com/m-lundberg/simple-pid/compare/v0.2.3...v0.2.4
84122
[0.2.3]: https://github.com/m-lundberg/simple-pid/compare/v0.2.2...v0.2.3
85123
[0.2.2]: https://github.com/m-lundberg/simple-pid/compare/v0.2.1...v0.2.2

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Martin Lundberg
3+
Copyright (c) 2018-2023 Martin Lundberg
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MANIFEST.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include CHANGELOG.md
2+
include LICENSE.md
3+
include README.md
4+
5+
recursive-exclude * __pycache__
6+
recursive-exclude * *.py[co]
7+
8+
recursive-include docs *.rst *.md conf.py requirements.txt
9+
recursive-include examples *.md *.txt *.py
10+
recursive-include tests *.py
11+
12+
include simple_pid/*.pyi
13+
include simple_pid/py.typed

0 commit comments

Comments
 (0)