generated from IMTEK-Simulation/python-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd8bde1
Showing
12 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install requirements | ||
run: | | ||
sudo apt-get install -y openmpi-bin libopenmpi-dev libfftw3-dev libfftw3-mpi-dev | ||
python -m pip install --upgrade pip | ||
pip install .[test] | ||
pip list | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*~ | ||
*.pyc | ||
*.cpython*.so | ||
__pycache__ | ||
../build | ||
dist | ||
*egg-info | ||
*.pyc | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lars Pastewka <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This file lists all changes to the code | ||
|
||
v0.0.1 | ||
------ | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Skeleton | ||
|
||
Skeleton for numerical projects with Python. This skeleton uses [numpy](https://numpy.org/) and [pytest](https://pytest.org). Rename the `python_skeleton` subdirectory to your module name. | ||
|
||
## Tests | ||
|
||
Before being able to run tests, you need to execute | ||
```python | ||
pip install -e .[test] | ||
``` | ||
to editably install the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# | ||
# | ||
|
||
|
||
import os | ||
import sys | ||
from collections import defaultdict | ||
from datetime import datetime | ||
from subprocess import Popen, PIPE | ||
|
||
root = os.path.dirname(sys.argv[0]) | ||
|
||
|
||
def read_authors(fn): | ||
return {email.strip('<>'): name for name, email in | ||
[line.rsplit(maxsplit=1) for line in open(fn, 'r')]} | ||
|
||
|
||
def parse_git_log(log, authors): | ||
committers = defaultdict(set) | ||
author = None | ||
date = None | ||
for line in log.decode('utf-8').split('\n'): | ||
if line.startswith('commit'): | ||
if date is not None and author is not None: | ||
committers[author].add(date.year) | ||
elif line.startswith('Author:'): | ||
email = line.rsplit('<', maxsplit=1)[1][:-1] | ||
elif line.startswith('Date:'): | ||
date = datetime.strptime(line[5:].rsplit(maxsplit=1)[0].strip(), | ||
'%a %b %d %H:%M:%S %Y') | ||
try: | ||
author = authors[email] | ||
except KeyError: | ||
author = email | ||
elif 'copyright' in line.lower() or 'license' in line.lower(): | ||
date = None | ||
if date is not None: | ||
committers[author].add(date.year) | ||
return committers | ||
|
||
|
||
def pretty_years(years): | ||
years = sorted(years) | ||
prev_year = prev_out = years[0] | ||
s = '{}'.format(prev_year) | ||
for year in years[1:]: | ||
if year - prev_year > 1: | ||
if year - prev_out > 1: | ||
if prev_year == prev_out: | ||
s = '{}, {}'.format(s, year) | ||
else: | ||
s = '{}-{}, {}'.format(s, prev_year, year) | ||
else: | ||
s = '{}, {}'.format(s, prev_year) | ||
prev_out = year | ||
prev_year = year | ||
if prev_year - prev_out == 1: | ||
s = '{}-{}'.format(s, prev_year) | ||
elif prev_year - prev_out > 1: | ||
s = '{}, {}'.format(s, prev_year) | ||
return s | ||
|
||
|
||
authors = read_authors('{}/../AUTHORS'.format(root)) | ||
|
||
process = Popen(['git', 'log', '--follow', sys.argv[1]], stdout=PIPE, | ||
stderr=PIPE) | ||
stdout, stderr = process.communicate() | ||
committers = parse_git_log(stdout, authors) | ||
|
||
prefix = 'Copyright' | ||
for name, years in committers.items(): | ||
print('{} {} {}'.format(prefix, pretty_years(years), name)) | ||
prefix = ' ' * len(prefix) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# | ||
|
||
|
||
import sys | ||
|
||
file_lines = open(sys.argv[1], 'r').readlines() | ||
header_lines = sys.stdin.readlines() | ||
|
||
while file_lines[0].startswith('#'): | ||
file_lines = file_lines[1:] | ||
|
||
file_lines.insert(0, '#\n') | ||
for header_line in header_lines[::-1]: | ||
file_lines.insert(0, '# {}'.format(header_line).strip() + '\n') | ||
file_lines.insert(0, '#\n') | ||
|
||
open(sys.argv[1], 'w').writelines(file_lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#! /bin/sh | ||
# Updates all Python files with license taken from README.md and copyright information obtained from the git log. | ||
|
||
for fn in setup.py `find python_skeleton test -name "*.py"`; do | ||
echo $fn | ||
python3 maintenance/copyright.py $fn | cat - LICENSE.md | python3 maintenance/replace_header.py $fn | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[build-system] | ||
requires = ["flit_core>=3.2"] | ||
build-backend = "flit_core.buildapi" | ||
|
||
[project] | ||
name = "python-skeleton" | ||
description = "Python skeleton project" | ||
readme = "README.md" | ||
license = { file = "LICENSE.md" } | ||
authors = [ | ||
{ name = "Lars Pastewka", email = "[email protected]" } | ||
] | ||
classifiers = [ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Programming Language :: Python" | ||
] | ||
requires-python = ">=3.8.0" | ||
dynamic = [ "version" ] | ||
dependencies = [ | ||
"numpy", | ||
"scipy" | ||
] | ||
|
||
[project.optional-dependencies] | ||
test = [ | ||
"flake8", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-flake8" | ||
] | ||
|
||
[tool.pytest.ini_options] | ||
pythonpath = [ | ||
"." | ||
] | ||
|
||
[project.urls] | ||
documentation = "https://imtek-simulation.github.io/python-skeleton/" | ||
repository = "https://github.com/imtek-simulation/python-skeleton" | ||
changelog = "https://github.com/imtek-simulation/python-skeleton/blob/master/CHANGELOG.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright 2021 Lars Pastewka | ||
# | ||
# MIT License | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
# | ||
|
||
""" | ||
The entry point for the code | ||
""" | ||
|
||
__version__ = '0.0.1' | ||
|
||
def hello_world(): | ||
return "Hello world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright 2021 Lars Pastewka | ||
# | ||
# MIT License | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
# | ||
|
||
""" | ||
Tests the hello world function | ||
""" | ||
|
||
from python_skeleton import hello_world | ||
|
||
|
||
def test_hello_world(): | ||
assert hello_world() == 'Hello world!' |