diff --git a/.drone.yml b/.drone.yml index c1c1963f7..8f9bb4841 100644 --- a/.drone.yml +++ b/.drone.yml @@ -50,10 +50,16 @@ steps: from_secret: email_password from: technical@dessia.tech +- name: check black formatting + image: python:3.9 + commands: + - pip install black[jupyter]==23.1.0 + - bash code_black.sh + - name: check code complexity image: dessia/python-ci:3.9 commands: - - pip install pylint==2.16.1 pydocstyle==6.3.0 pre-commit shellcheck-py cython-lint pyenchant==3.2.2 + - pip install pylint==2.16.1 pydocstyle==6.3.0 pre-commit shellcheck-py cython-lint pyenchant==3.2.2 black[jupyter] - python code_pylint.py - python code_pydocstyle.py - pre-commit run -a diff --git a/.pep8 b/.pep8 index fcaeb4bfe..676f98d68 100644 --- a/.pep8 +++ b/.pep8 @@ -1,6 +1,6 @@ [pycodestyle] max_line_length = 120 -ignore = E402, E722, E126, E731 +ignore = E402, E722, E126, E731, E203 recursive = true aggressive = 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index edd042705..507725956 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,13 @@ # to enable run `pip install pre-commit && pre-commit install` repos: + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + language_version: python3.9 + args: [-l, "120"] + - repo: https://github.com/MarcoGorelli/cython-lint rev: v0.10.1 hooks: diff --git a/code_black.sh b/code_black.sh new file mode 100755 index 000000000..aad70bc45 --- /dev/null +++ b/code_black.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# check black formatting on all files + +if black --check .; then + echo -e "\nBlack found no formatting errors." +else + echo -e "\nBlack found formatting errors." + + echo "Please run 'pre-commit run -a' to format the code (install pre-commit with pip)" + + echo -e "\nAlternatively, you can run 'black .' (black v23.1.0) in source directory to format the code." + echo "You can run 'black --check --diff --color .' to see the difference with expected formatting." + + echo -e "\nNote: Black is configurated in 'pyproject.toml' to have a 120 character line length." + echo "It is equivalent than using the 'l120' argument: 'black -l120 .'" + + exit 1 +fi diff --git a/pyproject.toml b/pyproject.toml index b51802b05..95e5682eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,6 @@ [build-system] requires = ["setuptools", "Cython"] + +[tool.black] +line-length = 120 +exclude = 'venv'