-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
pre-commit
to CI and fix all typing and linting (#306)
* Add pre-commit * Add relint file * Auto-linting * Auto-linting . files * Reactivating black, starting flake8 * Fixing codespell * Black reformatting * Fix flake8 issues * Incremental commit on mypy * Incremental commit on mypy * Incremental commit in mypy * Incremental commit on mypy * Incremental commit on mypy * Finish mypy, add isort and pyupgrade * Rerun all * black and isort are fighting! * Make isort profile for compatibility with black * Import annotations in setup * Fix typing import * Modify definition of NDArrayf for backward compatibility * Make typing backward compatible for Python 3.8 and before * Change typing with Python version * Remove type subscription before Python 3.9 * Fix choice order function and fitting tests * Fix test errors due to linting * Final linting * Fix isinstance syntax for python 3.8
- Loading branch information
Showing
76 changed files
with
4,394 additions
and
3,016 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,15 @@ | ||
name: Linting and formatting (pre-commit) | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/action@v2.0.0 |
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
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
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,113 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
exclude: \.txt$ | ||
- id: trailing-whitespace # Remove trailing whitespaces | ||
- id: check-merge-conflict | ||
|
||
# Fix common spelling mistakes | ||
- repo: https://github.com/codespell-project/codespell | ||
rev: v2.2.1 | ||
hooks: | ||
- id: codespell | ||
args: [ | ||
'--ignore-words-list', 'nd,alos', | ||
'--ignore-regex', '\bhist\b', | ||
'--' | ||
] | ||
types_or: [python, rst, markdown] | ||
files: ^(xdem|docs|tests)/ | ||
|
||
# Replace relative imports (e.g. 'from . import georaster' -> 'from geoutils import georaster') | ||
- repo: https://github.com/MarcoGorelli/absolufy-imports | ||
rev: v0.3.1 | ||
hooks: | ||
- id: absolufy-imports | ||
|
||
# Format the code aggressively using black | ||
- repo: https://github.com/psf/black | ||
rev: 22.8.0 | ||
hooks: | ||
- id: black | ||
args: [--line-length=120] | ||
|
||
# Lint the code using flake8 | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
hooks: | ||
- id: flake8 | ||
# More than one argument in the second list, so need to pass arguments as below (and -- to finish) | ||
args: [ | ||
'--max-line-length', '120', # we can write dicts however we want | ||
'--extend-ignore', 'E203,C408', # flake8 disagrees with black, so this should be ignored. | ||
'--' | ||
] | ||
additional_dependencies: | ||
- flake8-comprehensions==3.1.0 | ||
- flake8-bugbear==21.3.2 | ||
files: ^(xdem|tests) | ||
|
||
# Lint the code using mypy | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v0.971 | ||
hooks: | ||
- id: mypy | ||
args: [ | ||
--config-file=mypy.ini, | ||
--strict, | ||
--implicit-optional, | ||
--ignore-missing-imports, # Don't warn about stubs since pre-commit runs in a limited env | ||
--allow-untyped-calls, # Dynamic function/method calls are okay. Untyped function definitions are not okay. | ||
--show-error-codes, | ||
--no-warn-unused-ignores, # Ignore 'type: ignore' comments that are not used. | ||
--disable-error-code=attr-defined, # "Module has no attribute 'XXX'" occurs because of the pre-commit env. | ||
--disable-error-code=name-defined, # "Name 'XXX' is not defined" occurs because of the pre-commit env. | ||
--disable-error-code=var-annotated, | ||
--disable-error-code=no-any-return | ||
|
||
] | ||
additional_dependencies: [tokenize-rt==3.2.0, numpy==1.22] | ||
files: ^(xdem|tests|docs/code) | ||
|
||
|
||
# Sort imports using isort | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.10.1 | ||
hooks: | ||
- id: isort | ||
args: ["--profile", "black"] | ||
|
||
# Automatically upgrade syntax to a minimum version | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.38.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py37-plus] | ||
|
||
# Various formattings | ||
- repo: https://github.com/pre-commit/pygrep-hooks | ||
rev: v1.9.0 | ||
hooks: | ||
# Single backticks should apparently not be used | ||
- id: rst-backticks | ||
# Check that all directives end with double colon | ||
- id: rst-directive-colons | ||
types: [text] | ||
types_or: [python, rst] | ||
# Inline code should not touch normal text | ||
- id: rst-inline-touching-normal | ||
types: [text] | ||
types_or: [python, rst] | ||
# Eval should never be used (can do arbitrary code execution) | ||
- id: python-no-eval | ||
# Enforce the use of type annotations instead of docstring type comments | ||
- id: python-use-type-annotations | ||
|
||
# Add custom regex lints (see .relint.yml) | ||
- repo: https://github.com/codingjoe/relint | ||
rev: 1.4.0 | ||
hooks: | ||
- id: relint |
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,3 @@ | ||
- name: Type hint in docstring | ||
pattern: ':[r]?type ' | ||
filePattern: .*\.py |
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
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
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
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 |
---|---|---|
|
@@ -34,4 +34,3 @@ dependencies: | |
|
||
- pip: | ||
- git+https://github.com/GlacioHack/geoutils.git | ||
|
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
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
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
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ TODO: In construction | |
Terrain biases | ||
-------------- | ||
|
||
TODO: In construction | ||
TODO: In construction |
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
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
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
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
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
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
Oops, something went wrong.