From f1553337f73a1b46e1f3ad42c258933d576388d7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 00:15:25 +0200 Subject: [PATCH 01/10] add pre-commit --- .pre-commit-config.yaml | 11 +++++++++++ requirements.txt | 1 + tasks.py | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..0e8a58ece0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: mixed-line-ending diff --git a/requirements.txt b/requirements.txt index 5065b4f877..2a4f557e3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,6 +39,7 @@ inventree # Install the latest version of the Inve markdown==3.3.4 # Force particular version of markdown pep8-naming==0.11.1 # PEP naming convention extension pillow==9.0.1 # Image manipulation +pre-commit==2.19.0 # Git pre-commit py-moneyed==0.8.0 # Specific version requirement for py-moneyed pygments==2.7.4 # Syntax highlighting python-barcode[images]==0.13.1 # Barcode generator diff --git a/tasks.py b/tasks.py index 2ed0b4d35e..db3a68d503 100644 --- a/tasks.py +++ b/tasks.py @@ -98,6 +98,19 @@ def install(c): # Install required Python packages with PIP c.run('pip3 install -U -r requirements.txt') +def setup_dev(c): + """ + Sets up everything needed for the dev enviroment + """ + + print("Installing required python packages from 'requirements.txt'") + + # Install required Python packages with PIP + c.run('pip3 install -U -r requirements.txt') + + # Install pre-commit hook + c.run('pre-commit install') + @task def shell(c): """ @@ -253,7 +266,7 @@ def update(c): - static - clean_settings """ - + # Recompile the translation files (.mo) # We do not run 'invoke translate' here, as that will touch the source (.po) files too! manage(c, 'compilemessages', pty=True) From a67a6c55c28bddc413659c13b6121679a806e636 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 00:19:03 +0200 Subject: [PATCH 02/10] declare as task --- tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks.py b/tasks.py index db3a68d503..4a5c7b8c65 100644 --- a/tasks.py +++ b/tasks.py @@ -98,6 +98,7 @@ def install(c): # Install required Python packages with PIP c.run('pip3 install -U -r requirements.txt') +@task def setup_dev(c): """ Sets up everything needed for the dev enviroment From cc2081bf504b79646ce8d129b4b42220dfcbf1d1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 00:19:37 +0200 Subject: [PATCH 03/10] add hook auto-update to setup --- tasks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks.py b/tasks.py index 4a5c7b8c65..e0c6f8d018 100644 --- a/tasks.py +++ b/tasks.py @@ -112,6 +112,9 @@ def setup_dev(c): # Install pre-commit hook c.run('pre-commit install') + # Update all the hooks + c.run('pre-commit autoupdate') + @task def shell(c): """ From 55ee0836f8dccb7b9f3010a0b6f344cf30b5a285 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 00:20:07 +0200 Subject: [PATCH 04/10] add flake8 to the hooks --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e8a58ece0..fa65238f9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,8 @@ repos: - id: check-yaml - id: check-added-large-files - id: mixed-line-ending +- repo: https://github.com/pycqa/flake8 + rev: '4.0.1' + hooks: + - id: flake8 + additional_dependencies: [flake8-docstrings] From 552622fb475ce7b163008cf7d80e2b6929045cb0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 00:21:35 +0200 Subject: [PATCH 05/10] remove docstring tests --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa65238f9a..48e530b22b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,4 +13,3 @@ repos: rev: '4.0.1' hooks: - id: flake8 - additional_dependencies: [flake8-docstrings] From c5db595b54f8e1fe8ab6fae7f6836562fdf24036 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 01:13:04 +0200 Subject: [PATCH 06/10] add isort --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48e530b22b..1dc2ba3f70 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,3 +13,7 @@ repos: rev: '4.0.1' hooks: - id: flake8 +- repo: https://github.com/pycqa/isort + rev: '5.10.1' + hooks: + - id: isort From a07fdb7c16d1df4838b3ca15301e37ae5923e68a Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 01:18:55 +0200 Subject: [PATCH 07/10] add docstring comment --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c36c11b62b..12e6b6674b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,7 +90,8 @@ The various github actions can be found in the `./github/workflows` directory ## Code Style -Sumbitted Python code is automatically checked against PEP style guidelines. Locally you can run `invoke style` to ensure the style checks will pass, before submitting the PR. +Sumbitted Python code is automatically checked against PEP style guidelines. Locally you can run `invoke style` to ensure the style checks will pass, before submitting the PR. +Please write docstrings for each function and class - we follow the [google doc-style](https://google.github.io/styleguide/pyguide.html#244-decision) for python. Docstrings for general javascript code is encouraged! Docstyles are checked by `invoke style`. ## Documentation From da36af2021340da5c43b96f74b0ba1530bd48a80 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 01:19:07 +0200 Subject: [PATCH 08/10] fix link --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12e6b6674b..bff9dda73c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -91,7 +91,7 @@ The various github actions can be found in the `./github/workflows` directory ## Code Style Sumbitted Python code is automatically checked against PEP style guidelines. Locally you can run `invoke style` to ensure the style checks will pass, before submitting the PR. -Please write docstrings for each function and class - we follow the [google doc-style](https://google.github.io/styleguide/pyguide.html#244-decision) for python. Docstrings for general javascript code is encouraged! Docstyles are checked by `invoke style`. +Please write docstrings for each function and class - we follow the [google doc-style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for python. Docstrings for general javascript code is encouraged! Docstyles are checked by `invoke style`. ## Documentation From 545756eacb626447be8a3e687b51f4b4c4e025c6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 01:20:04 +0200 Subject: [PATCH 09/10] add docstring testing --- requirements.txt | 1 + setup.cfg | 3 +++ 2 files changed, 4 insertions(+) diff --git a/requirements.txt b/requirements.txt index 2a4f557e3b..ee6899e92b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,6 +33,7 @@ django-weasyprint==1.0.1 # django weasyprint integration djangorestframework==3.12.4 # DRF framework django-xforwardedfor-middleware==2.0 # IP forwarding metadata flake8==3.8.3 # PEP checking +flake8-docstrings==1.6.0 # docstring format testing gunicorn>=20.1.0 # Gunicorn web server importlib_metadata # Backport for importlib.metadata inventree # Install the latest version of the InvenTree API python library diff --git a/setup.cfg b/setup.cfg index b4b0af8836..f57040d151 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,8 +15,11 @@ ignore = N806, # - N812 - lowercase imported as non-lowercase N812, + # - D415 - First line should end with a period, question mark, or exclamation point + D415, exclude = .git,__pycache__,*/migrations/*,*/lib/*,*/bin/*,*/media/*,*/static/* max-complexity = 20 +docstring-convention=google [coverage:run] source = ./InvenTree From f98ec6cf3515b8d0dcacba9502de3aa1f408506f Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 19 May 2022 01:34:39 +0200 Subject: [PATCH 10/10] Add pre-commit comment --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bff9dda73c..e6a58dba54 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,9 @@ Please read the contribution guidelines below, before submitting your first pull request to the InvenTree codebase. +## Setup + +Please run `invoke setup_dev` in the root directory of your InvenTree code base to set up your development setup before starting to contribute. This will install and set up pre-commit to run some checks before each commit and help reduce the style errors. + ## Branches and Versioning InvenTree roughly follow the [GitLab flow](https://docs.gitlab.com/ee/topics/gitlab_flow.html) branching style, to allow simple management of multiple tagged releases, short-lived branches, and development on the main branch.