From e2a42d30272f872f28dd17c7991becf8fc6e932b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Sun, 3 Apr 2022 18:57:58 +0530 Subject: [PATCH 1/5] added pre-commit --- .pre-commit-config.yaml | 15 +++++++++++++++ requirements-dev.txt | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..93583de50 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +# 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 + args: + - max-line-length = 100, + - max-complexity = 12 +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 'v0.942' + hooks: + - id: mypy + args: [--ignore-missing-imports] diff --git a/requirements-dev.txt b/requirements-dev.txt index 063cfaa45..5266ad003 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,10 +3,12 @@ -r requirements-plot.txt -r requirements-hyperopt.txt + 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 From 57af08fde727231a878d32149bdf4a628ab48cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Tue, 5 Apr 2022 10:21:07 +0530 Subject: [PATCH 2/5] updated requested changes in PR #6636 --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++---- CONTRIBUTING.md | 2 ++ setup.sh | 7 +++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 93583de50..28eb0ae38 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,30 @@ repos: rev: '4.0.1' hooks: - id: flake8 - args: - - max-line-length = 100, - - max-complexity = 12 + stages: [push] + - repo: https://github.com/pre-commit/mirrors-mypy rev: 'v0.942' hooks: - id: mypy - args: [--ignore-missing-imports] + stages: [push] + +- repo: https://github.com/pycqa/isort + rev: '5.10.1' + hooks: + - id: isort + name: isort (python) + stages: [push] + +# https://github.com/pre-commit/pre-commit/issues/761#issuecomment-394167542 +- repo: local + hooks: + - id: pytest + name: pytest + entry: venv/bin/pytest + language: script + pass_filenames: false + # alternatively you could `types: [python]` so it only runs when python files change + # though tests might be invalidated if you were to say change a data file + always_run: true + stages: [push] \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4e0bc024..ae9c5d81e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,6 +20,8 @@ Best start by reading the [documentation](https://www.freqtrade.io/) to get a fe ## Before sending the PR +Do the following if you disabled pre-commit hook when commiting. + ### 1. Run unit tests All unit tests must pass. If a unit test is broken, change your code to 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 From 0d93916f79bc57528066fe96a245bb26d72a337a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Tue, 5 Apr 2022 11:28:22 +0530 Subject: [PATCH 3/5] Update developer.md --- docs/developer.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/developer.md b/docs/developer.md index ee4bac5c2..18465238f 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -26,6 +26,8 @@ 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` + Before opening a pull request, please familiarize yourself with our [Contributing Guidelines](https://github.com/freqtrade/freqtrade/blob/develop/CONTRIBUTING.md). ### Devcontainer setup From b8556498efb22529438594cf8fb68cbcf899127c Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 8 Apr 2022 17:46:53 +0200 Subject: [PATCH 4/5] Fix pre-commit to actually work --- .pre-commit-config.yaml | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28eb0ae38..31af5b7c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,30 +5,17 @@ repos: rev: '4.0.1' hooks: - id: flake8 - stages: [push] + # stages: [push] - repo: https://github.com/pre-commit/mirrors-mypy rev: 'v0.942' hooks: - id: mypy - stages: [push] + # stages: [push] - repo: https://github.com/pycqa/isort rev: '5.10.1' hooks: - id: isort name: isort (python) - stages: [push] - -# https://github.com/pre-commit/pre-commit/issues/761#issuecomment-394167542 -- repo: local - hooks: - - id: pytest - name: pytest - entry: venv/bin/pytest - language: script - pass_filenames: false - # alternatively you could `types: [python]` so it only runs when python files change - # though tests might be invalidated if you were to say change a data file - always_run: true - stages: [push] \ No newline at end of file + # stages: [push] From ecb0e43c2a29d4dc9912eaf49b97dbb7214796a7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 8 Apr 2022 17:50:32 +0200 Subject: [PATCH 5/5] Improve pre-commit docs --- CONTRIBUTING.md | 2 -- docs/developer.md | 3 ++- requirements-dev.txt | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae9c5d81e..b4e0bc024 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,8 +20,6 @@ Best start by reading the [documentation](https://www.freqtrade.io/) to get a fe ## Before sending the PR -Do the following if you disabled pre-commit hook when commiting. - ### 1. Run unit tests All unit tests must pass. If a unit test is broken, change your code to diff --git a/docs/developer.md b/docs/developer.md index 18465238f..0434ecb3e 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -26,7 +26,8 @@ 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` +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). diff --git a/requirements-dev.txt b/requirements-dev.txt index 5266ad003..c510b107d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,6 @@ -r requirements-plot.txt -r requirements-hyperopt.txt - coveralls==3.3.1 flake8==4.0.1 flake8-tidy-imports==4.6.0 @@ -28,4 +27,4 @@ types-requests==2.27.15 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