Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hooks to the repo #212

Merged
merged 38 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7e026b6
setting up pre-commit hooks, autopep8 as first hook
TomTomRixRix Apr 4, 2023
6a37333
Add autopep8 config, line length default to 120
TomTomRixRix Apr 4, 2023
086a7a3
Added markdown link checker and cff validator, including licenses and…
TomTomRixRix Apr 4, 2023
a273f6d
Added yaml checker
TomTomRixRix Apr 4, 2023
68d4f37
Added commit message checking
TomTomRixRix Apr 4, 2023
80222b7
try adding speiseplan
TomTomRixRix Apr 4, 2023
ec0e112
add git config email checker
TomTomRixRix Apr 4, 2023
90f4588
by default, don't check git config email
TomTomRixRix Apr 4, 2023
8b9e7da
Automatically insert license header to python files if not already me…
TomTomRixRix Apr 5, 2023
bb7179a
Added gitlint as pre-commit hook
TomTomRixRix Apr 5, 2023
4f0ffde
Added very flexible gitlint configuration
TomTomRixRix Apr 5, 2023
8f3596d
Added type to markdown checker and moved it to the end. Removed outco…
TomTomRixRix Apr 5, 2023
d67b463
Install pre-commit and commit-msg hooks when running pre-commit install
TomTomRixRix Apr 5, 2023
5acb161
Added description on how to enable git config user email address hook
TomTomRixRix Apr 5, 2023
addd564
Added documentation about pre-commit hooks in readme
TomTomRixRix Apr 5, 2023
0c286a0
Updated readme header design and sample mail address
TomTomRixRix Apr 6, 2023
2cdbf3a
Enable manuall triggering of tests
TomTomRixRix Apr 6, 2023
7a9463f
Run tests every Friday morning
TomTomRixRix Apr 6, 2023
ef698e4
Added configuration to weekly check for updates of pip dependencies a…
TomTomRixRix Apr 6, 2023
2afac25
Refactored automatic tests workflow to support multiple jobs being ba…
TomTomRixRix Apr 6, 2023
ae0b2d0
Fixed workflow path
TomTomRixRix Apr 6, 2023
e4a5e44
Fixed python setup on macOS
TomTomRixRix Apr 6, 2023
69c1b7f
The missing s
TomTomRixRix Apr 6, 2023
a14054b
Revert "The missing s"
TomTomRixRix Apr 6, 2023
3845bb5
Revert "Fixed python setup on macOS"
TomTomRixRix Apr 6, 2023
affb2fe
Revert "Fixed workflow path"
TomTomRixRix Apr 6, 2023
91cf264
Revert "Refactored automatic tests workflow to support multiple jobs …
TomTomRixRix Apr 6, 2023
da96bc7
Added pylic license checking as setp
TomTomRixRix Apr 6, 2023
e3987e1
Added pylic package and config
TomTomRixRix Apr 6, 2023
5c8c3b8
Revert "Added pylic package and config"
TomTomRixRix Apr 6, 2023
636fb2a
Revert "Added pylic license checking as setp"
TomTomRixRix Apr 6, 2023
d8b9666
Adds action to upload package to PyPI on pushes and merges to the mai…
TomTomRixRix Apr 6, 2023
35e657d
Merge branch 'main' into T165_PreCommitHooks
kdreher Jul 25, 2023
e38b049
remove looking for version number as this keeps causing problems
kdreher Jul 25, 2023
2648ff8
executed autopep8 pre-commit formatting
kdreher Jul 25, 2023
fcd469f
Moved installation instructions of pre-commit hooks to the CONTRIBUTI…
kdreher Jul 25, 2023
c6442b7
Deleted VERSION file
kdreher Jul 25, 2023
aea6fac
Added empty line at end of yml file
TomTomRixRix Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
7 changes: 7 additions & 0 deletions .github/workflows/automatic_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
name: SIMPA tests

on:
# run SIMPA tests on pushes to the main or develop branch
push:
branches: [ main, develop ]
# and on all pull requests to the main or develop branch
pull_request:
branches: [ main, develop ]
# as well as upon manual triggers through the 'Actions' tab of the Github UI
workflow_dispatch:
# Additionally, run Friday morning 6AM, so that we can react quickly if things break
schedule:
- cron: "0 5 * * 5"

jobs:
build:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Uploads the current version of the package to PyPI when commit are pushed to main (including merges via pull requests)

name: Upload to PyPI

on:
push:
branches:
- main

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.16
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
7 changes: 7 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Configuration file for gitlint, used via pre-commit
# Configuration docs: http://jorisroovers.github.io/gitlint/configuration/
# Default rules: https://github.com/jorisroovers/gitlint/blob/master/docs/rules.md

[general]
# Ignore certain rules, you can reference them by their id or by their full name
ignore=title-max-length, title-trailing-punctuation, body-is-missing, body-max-line-length, body-first-line-empty, body-min-length, body-changed-file-mention
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks # Uses MIT-License (MIT compatible)
rev: v4.4.0
hooks:
- id: check-yaml # checks is yaml file is valid
- id: check-added-large-files # prevents adding large files, above 500kB

- repo: https://github.com/pre-commit/mirrors-autopep8 # Uses MIT-License (MIT compatible)
rev: v2.0.2 # Use the sha / tag you want to point at
hooks:
- id: autopep8 # formats code according to PEP8 standard. Lets commit fail if it needs to reformat code. Config for autopep8 is done in myproject.toml

- repo: https://github.com/citation-file-format/cff-converter-python # Uses Apache 2.0-License (MIT compatible)
rev: "44e8fc9"
hooks:
- id: validate-cff # validates cff citation files

- repo: https://github.com/Lucas-C/pre-commit-hooks # Uses MIT License (MIT compatible)
rev: v1.5.1
hooks:
- id: insert-license # Checks if the license header specified at license_header.txt is added in the first lines of each python file. If not, it suggests to insert them.
types: [python]
args:
- --license-filepath
- license_header.txt # defaults to: LICENSE.txt

- repo: https://github.com/jorisroovers/gitlint # Uses MIT License (MIT compatible)
rev: v0.19.1
hooks:
- id: gitlint

- repo: https://github.com/tcort/markdown-link-check # Uses ISC-License (MIT compatible)
rev: v3.10.3
hooks:
- id: markdown-link-check # checks if links in markdown files work
exclude: docs/
types: [markdown]

# toggle comment to perform git config user email check. Note that you have to place the check-email.sh script in your .git/hooks/ folder
# - repo: local
# hooks:
# - id: git-config-email-check # checks if git config user email address is valid according to specified domains in check-email.sh script
# name: git-config-email-check
# entry: .git/hooks/check-email.sh
# language: script
38 changes: 34 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ In general the following steps are involved during a contribution:
5. Perform test driven development on feature branch.
A new implemented feature / a bug fix should be accompanied by a test.
Additionally, all previously existing tests must still pass after the contribution.
6. Once development is finished, create a pull request including your changes.
6. Run pre-commit hooks and make sure all hooks are passing.
7. Once development is finished, create a pull request including your changes.
For more information on how to create pull request, see GitHub's [about pull requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).
7. A member of the core development team will review your pull request and potentially require further changes
8. A member of the core development team will review your pull request and potentially require further changes
(see [Contribution review and integration](#contribution-review-and-integration)).
Once all remarks have been resolved, your changes will be merged into the develop branch.

Expand Down Expand Up @@ -86,8 +87,37 @@ In case already existing commits need to be signed off, you can make use of the

`git commit --amend --signoff`

### Install pre-commit hooks

In your SIMPA root directory run `pre-commit install` to set up the pre-commit hooks defined in `.pre-commit-config.yaml`. This will generate pre-commit hooks in `.git/hooks/` and run them for every commit. To run them manually before you commit, call `pre-commit run --all-files`.

<details>
<summary>Further information on pre-commit hooks</summary>

#### git config user email address checking
The `git-config-email-check` hook is by default commented out in `pre-commit-config.yaml`. If you want to get a warning when you are not using a specified git config user email address domain, then you might want to comment this hook in. Then you would have to place a file according to the given path, e.g. at `.git/hooks/check-email.sh` with the following content:

```shell
#!/bin/bash
PWD=`pwd`
EMAIL=$(git config user.email)
if [[ $EMAIL == *"@yourdomain.com"* ]]; then
echo "[INFO] Verified email: $EMAIL"
else
echo "[ERROR] Invalid email: $EMAIL => Please configure the company email and retry."
echo "Steps:"
echo " cd $PWD"
echo ' git config user.email "<user>@yourdomain.com"'
echo ""
exit 1;
fi;
```

Change the domain in lines 4 and 10 according to your specific domain (e.g. corporate email domain) or even whole email address.
</details>

### Contribution review and integration
To ensure correctness and high quality of the submitted code, each contribution will be reviewed by a member of the core development team regarding among others the following aspects:
To ensure correctness and high quality of the submitted code, each contribution will be checked by pre-commit hooks and reviewed by a member of the core development team regarding among others the following aspects:
- The code is correct and implements the described feature / fixes the described issue.
- The code follows the [SIMPA coding style](#coding-style)
- The code is [documented appropriately](#documenting-your-code)
Expand All @@ -104,7 +134,7 @@ We also have a Slack workspace that you can join if you are interested to contri

## Coding style

When writing code for SIMPA, please use the [PEP 8](https://www.python.org/dev/peps/pep-0008/) python coding conventions
When writing code for SIMPA, please use the [PEP 8](https://www.python.org/dev/peps/pep-0008/) python coding conventions (which will be checked with the [autopep8 pre-commit hook](https://github.com/pre-commit/mirrors-autopep8))
and consider using the following structures in your code in order to make a new
developer or someone external always know exactly what to expect.

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<div align="center">

![Logo](docs/source/images/simpa_logo.png?raw=true "Logo")

[![Documentation Status](https://readthedocs.org/projects/simpa/badge/?version=develop)](https://simpa.readthedocs.io/en/develop/?badge=develop)
![Build Status](https://github.com/IMSY-DKFZ/simpa/actions/workflows/automatic_testing.yml/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/IMSY-DKFZ/simpa/blob/main/LICENSE.md)

[![Pypi Badge](https://img.shields.io/pypi/v/simpa)](https://pypi.org/project/simpa/)
[![PyPI downloads](https://img.shields.io/pypi/dw/simpa?color=gr&label=pypi%20downloads)](https://pypi.org/project/simpa/)

![Logo](docs/source/images/simpa_logo.png?raw=true "Logo")
</div>

# The toolkit for Simulation and Image Processing for Photonics and Acoustics (SIMPA)

Expand Down Expand Up @@ -177,7 +180,7 @@ To contribute to SIMPA, please fork the SIMPA github repository and create a pul
suggested changes. The core developers will then review the suggested changes and integrate these into the code
base.

Please make sure that you have included unit tests for your code and that all previous tests still run through.
Please make sure that you have included unit tests for your code and that all previous tests still run through. Please also run the pre-commit hooks and make sure they are passing.

There is a regular SIMPA status meeting every Friday on even calendar weeks at 10:00 CET/CEST, and you are very welcome to participate and
raise any issues or suggest new features. If you want to join this meeting, write one of the core developers.
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

6 changes: 4 additions & 2 deletions docs/source/clean_up_rst_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
if os.path.exists(os.path.join(current_dir, "simpa_examples.rst")):
os.remove(os.path.join(current_dir, "simpa_examples.rst"))
simpa_examples_rst_file = open(os.path.join(current_dir, "simpa_examples.rst"), "w")
simpa_examples_rst_file.write("simpa\_examples\n=========================================\n\n.. toctree::\n :maxdepth: 2\n\n")
simpa_examples_rst_file.write(
"simpa\_examples\n=========================================\n\n.. toctree::\n :maxdepth: 2\n\n")
examples = glob.glob(os.path.join(current_dir, "../" + folder_level + "simpa_examples/*.py"))
for example in examples:
example_file_name = example.split("/")[-1]
Expand All @@ -51,7 +52,8 @@
if os.path.exists(os.path.join(current_dir, example_file_name_rst)):
os.remove(os.path.join(current_dir, example_file_name_rst))
example_rst_file = open(os.path.join(current_dir, example_file_name_rst), "a")
example_rst_file.write("{}\n=========================================\n\n.. literalinclude:: ../{}\n :language: python\n :lines: 1-\n\n".format(example_file_name, f'../simpa_examples/{example_file_name}.py'))
example_rst_file.write("{}\n=========================================\n\n.. literalinclude:: ../{}\n :language: python\n :lines: 1-\n\n".format(
example_file_name, f'../simpa_examples/{example_file_name}.py'))
example_rst_file.close()
simpa_examples_rst_file.writelines(" {}\n".format(example_file_name))

Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

project = 'SIMPA'
_copyright = '2020-2021, IMSY (Division of Intelligent Medical Systems), DKFZ, Heidelberg and ' \
'Janek Groehl'
'Janek Groehl'
author = 'IMSY (Division of Intelligent Medical Systems), DKFZ, Heidelberg and ' \
'Janek Groehl'

# The full version
# SIMPA syntax: RELEASE.MAJOR.MINOR
with open('../../VERSION', 'r') as readme_file:
version = readme_file.read()
with open('../../pyproject.toml', 'r') as py_project_file:
version = py_project_file.readlines()[2].split('\"')[-2]

# -- General configuration ---------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions license_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2021 Division of Intelligent Medical Systems, DKFZ
SPDX-FileCopyrightText: 2021 Janek Groehl
SPDX-License-Identifier: MIT
Loading