From b6acb5a372b010e3e2b0ad67f8db1ec7991beba5 Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 14:31:43 +0100 Subject: [PATCH 1/8] add black to pre-commit --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index edd042705..be0ccb278 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: stable + hooks: + - id: black + language_version: python3 + args: [-l, "120"] + - repo: https://github.com/MarcoGorelli/cython-lint rev: v0.10.1 hooks: From 29d8c5a7cb6548561ef7e6985791f7cfd7ea1c75 Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 14:31:59 +0100 Subject: [PATCH 2/8] add black to pre-commit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index c1c1963f7..8f77f867b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -53,7 +53,7 @@ steps: - 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 From 4d7958f16e20da5acf0220b39039f7355f4624fb Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 14:41:25 +0100 Subject: [PATCH 3/8] add black config to pyproject.toml --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) 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' From d496da2451a2625eef82b4e57771a9ebe06ca682 Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 14:50:46 +0100 Subject: [PATCH 4/8] specify black version in pre-commit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be0ccb278..76dcb9d5b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: - repo: https://github.com/psf/black - rev: stable + rev: 23.1.0 hooks: - id: black language_version: python3 From 16a8a187cd18b561fbead3a456606f513a47ab3c Mon Sep 17 00:00:00 2001 From: pgibertini <56967597+pgibertini@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:11:18 +0100 Subject: [PATCH 5/8] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76dcb9d5b..507725956 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: rev: 23.1.0 hooks: - id: black - language_version: python3 + language_version: python3.9 args: [-l, "120"] - repo: https://github.com/MarcoGorelli/cython-lint From fde29cf25c6bd7b8f0c04ae44e6447e7a5791938 Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 16:30:52 +0100 Subject: [PATCH 6/8] add "check black step formatting" to drone --- .drone.yml | 6 ++++++ code_black.sh | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 code_black.sh diff --git a/.drone.yml b/.drone.yml index 8f77f867b..8f9bb4841 100644 --- a/.drone.yml +++ b/.drone.yml @@ -50,6 +50,12 @@ 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: diff --git a/code_black.sh b/code_black.sh new file mode 100755 index 000000000..f8c5f5ce4 --- /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 ru, '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 From a20b2517922ebd1086b00fb94e8088a40ee23069 Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 16:33:45 +0100 Subject: [PATCH 7/8] fix typo --- code_black.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_black.sh b/code_black.sh index f8c5f5ce4..aad70bc45 100755 --- a/code_black.sh +++ b/code_black.sh @@ -6,7 +6,7 @@ if black --check .; then else echo -e "\nBlack found formatting errors." - echo "Please ru, 'pre-commit run -a' to format the code (install pre-commit with pip)" + 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." From 4e8824179ec038516a11627d99b3796186b45c8c Mon Sep 17 00:00:00 2001 From: Pierre Gibertini Date: Fri, 17 Feb 2023 20:04:57 +0100 Subject: [PATCH 8/8] fix pep8 --- .pep8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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