diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a69e0bc3e..26542daa4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,11 +24,11 @@ jobs: - name: Install dependencies run: pip install -e .[dev] - name: Lint with isort - run: isort --profile black --length-sort --line-width 120 -c . + run: pre-commit run isort - name: Lint with black - run: black -l 120 --check . + run: pre-commit run black - name: Check types with mypy - run: mypy --config-file .github/mypy/mypy.ini --check-untyped-defs floss/ scripts/ tests/ + run: pre-commit run mypy tests: name: Tests in ${{ matrix.python-version }} on ${{ matrix.os }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bdaaab6e8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,59 @@ +repos: +- repo: local + hooks: + - id: isort + name: isort + stages: [commit, push] + language: system + entry: isort + args: + - "--length-sort" + - "--profile" + - "black" + - "--line-length=120" + - "." + always_run: true + pass_filenames: false + +- repo: local + hooks: + - id: black + name: black + stages: [commit, push] + language: system + entry: black + args: + - "--line-length=120" + - "." + always_run: true + pass_filenames: false + +- repo: local + hooks: + - id: mypy + name: mypy + stages: [push] + language: system + entry: mypy + args: + - "--check-untyped-defs" + - "--config-file=.github/mypy/mypy.ini" + - "floss/" + - "scripts/" + - "tests/" + always_run: true + pass_filenames: false + +- repo: local + hooks: + - id: pytest + name: pytest + stages: [] + language: system + pass_filenames: false + always_run: true + entry: pytest + args: + - "--verbose" + - "tests/" + diff --git a/doc/installation.md b/doc/installation.md index 599063263..b9fc0e903 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -103,6 +103,35 @@ Or use the manual option: - `$ cd /local/path/to/src` - `$ git submodule update --init tests/data` +We use the following tools to ensure consistent code style and formatting: + + - [black](https://github.com/psf/black) code formatter + - [isort](https://pypi.org/project/isort/) code formatter + - [mypy](https://mypy-lang.org/) type checking + +We use [pre-commit](https://pre-commit.com/) so that its trivial to run the same linters & configuration locally as in CI. + +Run all linters liks: + ❯ pre-commit run --all-files + isort....................................................................Passed + black....................................................................Passed + mypy.....................................................................Passed + +Or run a single linter like: + ❯ pre-commit run --all-files isort + isort....................................................................Passed + +Importantly, you can configure pre-commit to run automatically before every commit by running: + + ❯ pre-commit install --hook-type pre-commit + pre-commit installed at .git/hooks/pre-commit + + ❯ pre-commit install --hook-type pre-push + pre-commit installed at .git/hooks/pre-push + +This way you can ensure that you don't commit code style or formatting offenses. +You can always temporarily skip the checks by using the `-n`/`--no-verify` git option. + ### Step 4: Building standalone executables diff --git a/setup.py b/setup.py index 595180618..0a4e92398 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,7 @@ install_requires=requirements, extras_require={ "dev": [ + "pre-commit==2.21.0", "pyyaml==6.0.1", "pytest==7.4.0", "pytest-sugar==0.9.4",