Merge branch 'feature/server-side-render' into feature/server-side-render-actions-trade

This commit is contained in:
Cayo Puigdefabregas 2022-02-21 13:05:38 +01:00
commit 4ce359fec4
8 changed files with 89 additions and 24 deletions

View File

@ -47,9 +47,6 @@ jobs:
sudo apt-get update -qy sudo apt-get update -qy
sudo apt-get -y install postgresql-client sudo apt-get -y install postgresql-client
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install virtualenv
virtualenv env
source env/bin/activate
pip install flake8 pytest coverage pip install flake8 pytest coverage
pip install -r requirements.txt 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 citext SCHEMA public;"
psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm 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 - name: Run Tests
run: | run: |
export SECRET_KEY=`python3 -c 'import secrets; print(secrets.token_hex())'` export SECRET_KEY=`python3 -c 'import secrets; print(secrets.token_hex())'`

17
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,17 @@
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
- repo: https://github.com/conorfalvey/check_pdb_hook
rev: 0.0.9
hooks:
- id: check_pdb_hook

25
CONTRIBUTING.md Normal file
View File

@ -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`

View File

@ -1,34 +1,29 @@
import json
import copy import copy
import json
from json.decoder import JSONDecodeError 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 boltons.urlutils import URL
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.hash_reports import insert_hash from ereuse_devicehub.resources.action.models import RateComputer, Snapshot
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.rate.v1_0 import CannotRate from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
from ereuse_devicehub.resources.action.schemas import \ from ereuse_devicehub.resources.action.schemas import \
Snapshot as SnapshotSchema Snapshot as SnapshotSchema
from ereuse_devicehub.resources.action.views.snapshot import (move_json, from ereuse_devicehub.resources.action.views.snapshot import move_json, save_json
save_json)
from ereuse_devicehub.resources.device.models import (SAI, Cellphone, Computer, from ereuse_devicehub.resources.device.models import (SAI, Cellphone, Computer,
Device, Keyboard, Device, Keyboard, MemoryCardReader,
MemoryCardReader, Monitor, Mouse, Smartphone, Tablet)
Monitor, Mouse, from flask import g, request
Smartphone, Tablet) 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.device.sync import Sync
from ereuse_devicehub.resources.documents.models import DataWipeDocument
from ereuse_devicehub.resources.enums import Severity, SnapshotSoftware 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.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User

6
pyproject.toml Normal file
View File

@ -0,0 +1,6 @@
[tool.black]
skip-string-normalization = true
target-version = ['py38']
[tool.isort]
multi_line_output = 4

4
requirements-dev.txt Normal file
View File

@ -0,0 +1,4 @@
black
isort
flake8
pre-commit

View File

@ -22,7 +22,7 @@ pytest==3.7.2
pytest-runner==4.2 pytest-runner==4.2
python-dateutil==2.7.3 python-dateutil==2.7.3
python-stdnum==1.9 python-stdnum==1.9
PyYAML==3.13 PyYAML==5.4
requests[security]==2.27.1 requests[security]==2.27.1
requests-mock==1.5.2 requests-mock==1.5.2
SQLAlchemy==1.2.17 SQLAlchemy==1.2.17

10
tox.ini Normal file
View File

@ -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