From dd15860b6e972199aafd68360e986cd33aace3db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:31:08 +0000 Subject: [PATCH 1/7] Bump pyyaml from 3.13 to 5.4 Bumps [pyyaml](https://github.com/yaml/pyyaml) from 3.13 to 5.4. - [Release notes](https://github.com/yaml/pyyaml/releases) - [Changelog](https://github.com/yaml/pyyaml/blob/master/CHANGES) - [Commits](https://github.com/yaml/pyyaml/compare/3.13...5.4) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6c83262f..8e1abffe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ pytest==3.7.2 pytest-runner==4.2 python-dateutil==2.7.3 python-stdnum==1.9 -PyYAML==3.13 +PyYAML==5.4 requests[security]==2.27.1 requests-mock==1.5.2 SQLAlchemy==1.2.17 From d66e2b77fdaaa87e98d894d1e4d7d9a3fd28a728 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Feb 2022 11:16:57 +0100 Subject: [PATCH 2/7] Run flake8 linter on github workflow --- .github/workflows/flask.yml | 14 +++++++++++--- tox.ini | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 151cc26d..328533a8 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -47,9 +47,6 @@ jobs: sudo apt-get update -qy sudo apt-get -y install postgresql-client python -m pip install --upgrade pip - pip install virtualenv - virtualenv env - source env/bin/activate pip install flake8 pytest coverage pip install -r requirements.txt @@ -65,6 +62,17 @@ jobs: psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION citext SCHEMA public;" psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm SCHEMA public;" + - name: Lint with flake8 + run: | + # stop the build if: + # - E9,F63,F7,F82: Python syntax errors or undefined names + # - E501: line longer than 120 characters + # - C901: complexity greater than 10 + # - F401: modules imported but unused + # See: https://flake8.pycqa.org/en/latest/user/error-codes.html + flake8 . --select=E9,F63,F7,F82,E501,C901,F401 + flake8 . --exit-zero + - name: Run Tests run: | export SECRET_KEY=`python3 -c 'import secrets; print(secrets.token_hex())'` diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..2f5d68fc --- /dev/null +++ b/tox.ini @@ -0,0 +1,8 @@ +[flake8] +count = True +exclude = + migrations +max-complexity = 10 +max-line-length = 120 +show-source = True +statistics = True From df4c6f740732d80f73ca0bb481ce59a61f53e8e0 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Feb 2022 11:29:47 +0100 Subject: [PATCH 3/7] flake8: remove unused imports & sort them --- ereuse_devicehub/inventory/forms.py | 35 +++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index a90ecf1b..8959ae93 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1,34 +1,29 @@ -import json import copy +import json from json.decoder import JSONDecodeError -from flask import g, request -from flask_wtf import FlaskForm -from sqlalchemy.util import OrderedSet -from wtforms.fields import FormField -from wtforms import (DateField, FloatField, HiddenField, IntegerField, - MultipleFileField, FileField, SelectField, StringField, - TextAreaField, BooleanField, URLField, validators, Form) - from boltons.urlutils import URL from ereuse_devicehub.db import db -from ereuse_devicehub.resources.hash_reports import insert_hash -from ereuse_devicehub.resources.documents.models import DataWipeDocument -from ereuse_devicehub.resources.action.models import (Action, RateComputer, - Snapshot, VisualTest, - DataWipe) +from ereuse_devicehub.resources.action.models import RateComputer, Snapshot from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate from ereuse_devicehub.resources.action.schemas import \ Snapshot as SnapshotSchema -from ereuse_devicehub.resources.action.views.snapshot import (move_json, - save_json) +from ereuse_devicehub.resources.action.views.snapshot import move_json, save_json from ereuse_devicehub.resources.device.models import (SAI, Cellphone, Computer, - Device, Keyboard, - MemoryCardReader, - Monitor, Mouse, - Smartphone, Tablet) + Device, Keyboard, MemoryCardReader, + Monitor, Mouse, Smartphone, Tablet) +from flask import g, request +from flask_wtf import FlaskForm +from sqlalchemy.util import OrderedSet +from wtforms import (BooleanField, DateField, FileField, FloatField, Form, + HiddenField, IntegerField, MultipleFileField, SelectField, + StringField, TextAreaField, URLField, validators) +from wtforms.fields import FormField + from ereuse_devicehub.resources.device.sync import Sync +from ereuse_devicehub.resources.documents.models import DataWipeDocument from ereuse_devicehub.resources.enums import Severity, SnapshotSoftware +from ereuse_devicehub.resources.hash_reports import insert_hash from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.user.exceptions import InsufficientPermission From 9cfcbd1c22af4de03a2d4919073abb601732c4c5 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Feb 2022 11:36:34 +0100 Subject: [PATCH 4/7] flake8: exclude legacy code --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 2f5d68fc..d9fa1946 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,8 @@ count = True exclude = migrations + resources # exclude code that will be deprecated + tests # exclude code that will be deprecated max-complexity = 10 max-line-length = 120 show-source = True From e31104d0384b7c3232035243eda3ab2f9b1cc8cd Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Feb 2022 14:05:26 +0100 Subject: [PATCH 5/7] Add pre-commit hook to run black, flake8 & isort --- .pre-commit-config.yaml | 13 +++++++++++++ pyproject.toml | 6 ++++++ tox.ini | 10 ++++++++++ 3 files changed, 29 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml create mode 100644 tox.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..13fbf401 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: + - repo: https://github.com/psf/black + rev: 22.1.0 + hooks: + - id: black + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 + hooks: + - id: flake8 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..442cc5af --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.black] +skip-string-normalization = true +target-version = ['py38'] + +[tool.isort] +multi_line_output = 4 diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..d9fa1946 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[flake8] +count = True +exclude = + migrations + resources # exclude code that will be deprecated + tests # exclude code that will be deprecated +max-complexity = 10 +max-line-length = 120 +show-source = True +statistics = True From e2d412c7d0e7cde809e88811163944a6129b2398 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 10 Feb 2022 20:30:40 +0100 Subject: [PATCH 6/7] Add CONTRIBUTING.nd & requirements-dev.txt --- CONTRIBUTING.md | 25 +++++++++++++++++++++++++ requirements-dev.txt | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 requirements-dev.txt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..16e3dfea --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,25 @@ +; SHARED on https://pad.cas.cat/usody-devicehub-contributing + +# Contributing to devicehub + +## Writing code + +### Coding style + +#### Python style +- Unless otherwise specified, follow [PEP 8](https://www.python.org/dev/peps/pep-0008). Use [flake8](https://pypi.org/project/flake8/) to check for problems in this area. +- Use [isort](https://github.com/PyCQA/isort#readme) to automate import sorting. + +To automatize this work just configure `pre-commit` hooks in your development environment: +```bash +# on your virtual environment +pip install -r requirements-dev.txt +pre-commit install +``` + +#### HTML (templates) +- Template file names should be all lowercase, using underscores instead of camelCase. + + Do this: `device_detail.html` + + Don't do this: `DeviceDetail.html`, `Device-detail.html` diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..02778f7d --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +black +isort +flake8 +pre-commit From 36da72ac6bac6dac6e210c6a8b68d5f16bb9f73a Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 11 Feb 2022 11:30:57 +0100 Subject: [PATCH 7/7] Add check pdb as pre-commit hook Avoid commits with pdb.set_trace() statements --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13fbf401..63a0458c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,7 @@ repos: rev: 4.0.1 hooks: - id: flake8 + - repo: https://github.com/conorfalvey/check_pdb_hook + rev: 0.0.9 + hooks: + - id: check_pdb_hook