Bug 51459 - Introduce automatic code formatting into ucsschool repo
Summary: Introduce automatic code formatting into ucsschool repo
Status: VERIFIED FIXED
Alias: None
Product: UCS@school
Classification: Unclassified
Component: General
Version: UCS@school 4.4
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: Ole Schwiegert
QA Contact: Daniel Tröder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-09 14:29 CEST by Ole Schwiegert
Modified: 2021-02-20 16:12 CET (History)
3 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Customer ID:
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ole Schwiegert univentionstaff 2020-06-09 14:29:33 CEST
We want to adhere to the pep8-compatible code format introduced by black. To achieve that we want to install pre-commit and run isort, black and flake8 (restricted to tab recognition) on our ucsschool Repo. Additionally we want to enforce these rules on server side with an pre-receive or update hook.
Comment 1 Ole Schwiegert univentionstaff 2020-06-09 14:30:22 CEST
Steps done so far:
format code
create configs for isort, black, flake8 git-hyper-blame
Comment 2 Ole Schwiegert univentionstaff 2020-06-09 14:31:46 CEST
Renamed all ucs-test-ucsschool tests that contain python code to end on .py so pre-commit realizes that they are python files
Comment 3 Ole Schwiegert univentionstaff 2020-06-09 14:45:58 CEST
The following configs are used:

[flake8]
exclude = doc/doc-common/,venv
max-line-length = 105
ignore = E203,E231,E266,E501,W503
select = E1,E2,E3,E4,E5,W1,W2,W3,W5

[tool.black]
line-length = 105
target-version = ['py27']
exclude = 'venv/|doc/doc-common/'

isort:
[settings]
combine_as_imports=1
filter_files=1
force_grid_wrap=0
known_first_party=ucsschool,univention
known_third_party=ConfigParser,PyQt4,StringIO,apt,cStringIO,celery,colorlog,commands,cups,dateutil,django,django_filters,djcelery,dns,ipaddr,italc2,lazy_object_proxy,ldap,ldif,listener,magic,mock,netifaces,notifier,psutil,pycurl,pytest,requests,rest_framework,ruamel,samba,sip,six,smbpasswd,urllib3,urlparse,utils,wakeonlan
line_length=105
multi_line_output=3
include_trailing_comma=1
skip=doc/doc-common/,ucs-school-import/usr/share/doc/ucs-school-import-http-api/source/conf.py
skip_glob=venv/*
recursive=1
Comment 4 Tobias Wenzel univentionstaff 2020-06-18 14:02:25 CEST
Added ucs-test-ucsschool/90_ucsschool/112_import_user_pyhooks.py to .isort.cfg
, so the following import does not fail:

sys.path.append("/usr/share/ucs-school-import/pyhooks/")
from bdaytest import BIRTHDAYS, PRE_ACTION_BIRTHDAYS


Bug #51459: Add ucs-test 112 import user to isort skip
Comment 5 Philipp Hahn univentionstaff 2020-06-25 18:19:04 CEST
[4.4] e1ece9657 Bug #51459: Build pre-commit Docker image
 .gitlab-ci.yml                   | 21 +++++++++++++++++++++
 .gitlab-ci/Dockerfile.pre-commit | 23 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)
[4.4] 6ed296c53 Bug #51459: Build pre-commit Docker image FIX
 .gitlab-ci.yml                   | 6 +++++-
 .gitlab-ci/Dockerfile.pre-commit | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
Comment 6 Daniel Tröder univentionstaff 2021-02-20 16:12:20 CET
[4.4] c58bfe1c3 Bug #51459: Add configuration for pre-commit, isort, black, flake8
[4.4] dd705a196 Bug #51459: Rename tests
[4.4] fa7002fe7 Bug #51459: Reformat code base
[4.4] 1078d675b Bug #51459: Create ignore-refs for git-hyper-blame
[4.4] 1784e4c3b Bug #51459: Add ucs-test 112 import user to isort skip
[4.4] d68092825 Bug #51459: make flake8 happy
[4.4] 21b8e1883 Bug #51459: Add ucs-test changelog
[4.4] e1ece9657 Bug #51459: Build pre-commit Docker image
[4.4] 6ed296c53 Bug #51459: Build pre-commit Docker image FIX
[4.4] a20feb7ad Bug #51459: whitespace only reformatting
Comment 7 Daniel Tröder univentionstaff 2021-02-20 16:12:46 CET
All the changes made in this bug have long been in production use and the tests have been green.