diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..31af5b7c7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pycqa/flake8 + rev: '4.0.1' + hooks: + - id: flake8 + # stages: [push] + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 'v0.942' + hooks: + - id: mypy + # stages: [push] + +- repo: https://github.com/pycqa/isort + rev: '5.10.1' + hooks: + - id: isort + name: isort (python) + # stages: [push] diff --git a/docs/developer.md b/docs/developer.md index 2a7955953..1cc16294b 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -26,6 +26,9 @@ Alternatively (e.g. if your system is not supported by the setup.sh script), fol This will install all required tools for development, including `pytest`, `flake8`, `mypy`, and `coveralls`. +Then install the git hook scripts by running `pre-commit install`, so your changes will be verified locally before committing. +This avoids a lot of waiting for CI already, as some basic formatting checks are done locally on your machine. + Before opening a pull request, please familiarize yourself with our [Contributing Guidelines](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md). ### Devcontainer setup diff --git a/requirements-dev.txt b/requirements-dev.txt index 65de55b76..20fd420bd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,6 +7,7 @@ coveralls==3.3.1 flake8==4.0.1 flake8-tidy-imports==4.6.0 mypy==0.942 +pre-commit==2.18.1 pytest==7.1.1 pytest-asyncio==0.18.3 pytest-cov==3.0.0 @@ -26,4 +27,4 @@ types-requests==2.27.16 types-tabulate==0.8.6 # Extensions to datetime library -types-python-dateutil==2.8.10 \ No newline at end of file +types-python-dateutil==2.8.10 diff --git a/setup.sh b/setup.sh index ebfabaca5..2c3a6710b 100755 --- a/setup.sh +++ b/setup.sh @@ -51,6 +51,7 @@ function updateenv() { echo "pip install in-progress. Please wait..." ${PYTHON} -m pip install --upgrade pip read -p "Do you want to install dependencies for dev [y/N]? " + dev=$REPLY if [[ $REPLY =~ ^[Yy]$ ]] then REQUIREMENTS=requirements-dev.txt @@ -88,6 +89,12 @@ function updateenv() { fi echo "pip install completed" echo + if [[ $dev =~ ^[Yy]$ ]] then + ${PYTHON} -m pre-commit install + if [ $? -ne 0 ]; then + echo "Failed installing pre-commit" + exit 1 + fi } # Install tab lib