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

chore: set up pre-commit hooks (DEV-2393) #420

Merged
merged 12 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry self add poetry-exec-plugin

- name: Set up Python 3.9
uses: actions/setup-python@v4
Expand All @@ -44,7 +45,6 @@ jobs:
- name: check external links in docs
run: |
npm install -g markdown-link-validator
poetry self add poetry-exec-plugin
poetry exec check-links

- name: markdownlint
Expand Down
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Configuration of https://pre-commit.com/

repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
# It is recommended to specify the latest version of Python supported by your project here,
# or alternatively use pre-commit's default_language_version,
# see https://pre-commit.com/#top_level-default_language_version
language_version: python3.9

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, main]
- id: fix-byte-order-marker
- id: detect-private-key
- id: check-symlinks
- id: destroyed-symlinks
- id: mixed-line-ending

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
hooks:
- id: markdownlint
args: [--config, .markdownlint.yml, --ignore, CHANGELOG.md]
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ More details can be found in the



## Quick start

To get started quickly, without reading the details, just execute these commands:

- `curl -sSL https://install.python-poetry.org | python3 -`
- `poetry self add poetry-exec-plugin`
- `poetry install`
- `pre-commit install`



## Using poetry for dependency management

Curious what poetry is and why we use it?
Expand Down Expand Up @@ -141,8 +152,13 @@ We use
These 4 linters are integrated in the GitHub CI pipeline,
so that every pull request is checked for code style violations.

In addition, there are [pre-commit hooks](#pre-commit-hooks)
that run black and markdownlint locally before every commit.
This prevents you from committing code style violations.

To locally check your code for style violations, follow the instructions depending on your IDE:


### VSCode

In VSCode,
Expand Down Expand Up @@ -176,6 +192,24 @@ Make sure to set the docstring format to "Google notypes" in the PyCharm setting
PyCharm > Settings > Tools > Python Integrated Tools > Docstring format: Google notypes



## Pre-commit hooks

We use [pre-commit hooks](https://pre-commit.com/).
They are configured in `.pre-commit-config.yaml`.

If you try to make a commit,
the pre-commit hooks will be executed before the commit is created.

If a hook fails, the commit will be aborted.
Check the Git output to see what needs to be fixed.

If a hook modifies a file, the commit will be aborted.
You can then stage the changes made by the hook,
and commit again.



## Contributing to the documentation

The documentation is a collection of [Markdown](https://en.wikipedia.org/wiki/Markdown) files in the `docs` folder.
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![PyPI version](https://badge.fury.io/py/dsp-tools.svg)](https://badge.fury.io/py/dsp-tools)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# DSP-TOOLS documentation

Expand Down
121 changes: 120 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ types-lxml = "^2023.3.28"
types-jsonschema = "^4.17.0.8"
types-openpyxl = "^3.1.0.7"
types-regex = "^2023.5.5.0"
pre-commit = "^3.3.3"


[tool.poetry.scripts]
dsp-tools = "dsp_tools.dsp_tools:main" # definition of the CLI entry point


[tool.poetry-exec-plugin.commands]
# plugin (https://github.com/keattang/poetry-exec-plugin) to define commands available for the developers, e.g. `poetry exec check-links`
check-links = "markdown-link-validator ./docs -i \\.\\/assets\\/.+ -i .+github\\.com\\/dasch\\-swiss\\/dsp-tools\\/settings"
# plugin (https://github.com/keattang/poetry-exec-plugin) to define commands available for the developers,
# e.g. `poetry exec check-links`
check-links = """
markdown-link-validator \
./docs \
-i \\.\\/assets\\/.+ \
-i .+github\\.com\\/dasch\\-swiss\\/dsp-tools\\/settings\
"""


[build-system]
Expand Down
2 changes: 1 addition & 1 deletion testdata/bitstreams/test.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
artwork;;
artwork;;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove UTF-8 Byte Order Mark (made by one of the pre-commit hooks)

vehicles;;
nature;;
nature;humans;
Expand Down