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.
Steps done so far: format code create configs for isort, black, flake8 git-hyper-blame
Renamed all ucs-test-ucsschool tests that contain python code to end on .py so pre-commit realizes that they are python files
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
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
[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(-)
[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
All the changes made in this bug have long been in production use and the tests have been green.