From e33ad515aa29cc3fbaa1d81fe9d3092f67ff0f34 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 22 Nov 2017 13:43:56 +0100 Subject: [PATCH 1/4] Add indent.pro from cpython --- .indent.pro | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .indent.pro diff --git a/.indent.pro b/.indent.pro new file mode 100644 index 00000000..02cceb62 --- /dev/null +++ b/.indent.pro @@ -0,0 +1,24 @@ +--blank-lines-after-declarations +--blank-lines-after-procedures +--braces-after-func-def-line +--braces-on-if-line +--braces-on-struct-decl-line +--break-after-boolean-operator +--comment-indentation25 +--comment-line-length79 +--continue-at-parentheses +--dont-cuddle-do-while +--dont-cuddle-else +--indent-level4 +--line-length79 +--no-space-after-casts +--no-space-after-function-call-names +--no-space-after-parentheses +--no-tabs +--procnames-start-lines +--space-after-for +--space-after-if +--space-after-while +--swallow-optional-blank-lines +-T PyCFunction +-T PyObject From b0f364247cb2a42841d175b8949330f4eb360335 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 22 Nov 2017 13:57:22 +0100 Subject: [PATCH 2/4] Add Makefile and LDAP related types to indent.pro Makefile contains targets to run indent and autopep8. --- .indent.pro | 7 +++++++ Makefile | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.indent.pro b/.indent.pro index 02cceb62..4e8adc1b 100644 --- a/.indent.pro +++ b/.indent.pro @@ -22,3 +22,10 @@ --swallow-optional-blank-lines -T PyCFunction -T PyObject +-T PyMethodDef +-T LDAP +-T LDAPMod +-T LDAPMessage +-T LDAPControl +-T LDAPObject +-T sasl_interact_t diff --git a/Makefile b/Makefile index e4ff75ac..c4c2ca11 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ LCOV_REPORT_OPTIONS=--show-details -no-branch-coverage \ --title "python-ldap LCOV report" SCAN_REPORT=build/scan_report PYTHON_SUPP=/usr/share/doc/python3-devel/valgrind-python.supp +AUTOPEP8_OPTS=--aggressive .NOTPARALLEL: @@ -13,7 +14,7 @@ all: .PHONY: clean clean: - rm -rf build dist *.egg-info $(VENV) .tox MANIFEST + rm -rf build dist *.egg-info .tox MANIFEST rm -f .coverage .coverage.* find . \( -name '*.py[co]' -or -name '*.so*' -or -name '*.dylib' \) \ -delete @@ -77,3 +78,14 @@ valgrind: build $(PYTHON_SUPP) echo "Found definitive leak, see build/valgrind.log"; \ exit 1; \ fi + +# Code autoformatter +.PHONY: indent +indent: + indent Modules/*.c Modules/*.h + rm -f Modules/*.c~ Modules/*.h~ + +.PHONY: autopep8 +autopep8: + $(PYTHON) -m autopep8 -r -i -j0 $(AUTOPEP8_OPTS) \ + Demo Lib Tests setup.py From db242769139785e59cec1c5f8de95a2c2bae0a64 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 14 Mar 2018 12:49:26 +0100 Subject: [PATCH 3/4] Makefile: Add "autoformat" rule to format all the code --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c4c2ca11..2d3293e6 100644 --- a/Makefile +++ b/Makefile @@ -80,12 +80,13 @@ valgrind: build $(PYTHON_SUPP) fi # Code autoformatter -.PHONY: indent +.PHONY: autoformat indent autopep8 +autoformat: indent autopep8 + indent: indent Modules/*.c Modules/*.h rm -f Modules/*.c~ Modules/*.h~ -.PHONY: autopep8 autopep8: $(PYTHON) -m autopep8 -r -i -j0 $(AUTOPEP8_OPTS) \ Demo Lib Tests setup.py From 0473e8764215a6586aef36d470f4eaa7f81e3fdc Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 14 Mar 2018 12:54:24 +0100 Subject: [PATCH 4/4] Doc: Add `make autoformat` to the contributing guide --- Doc/contributing.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Doc/contributing.rst b/Doc/contributing.rst index 9061332d..badb9315 100644 --- a/Doc/contributing.rst +++ b/Doc/contributing.rst @@ -102,6 +102,17 @@ Specify a different one using, for example:: Notable targets are: +``make autoformat`` + Automatically re-formats C and Python code to conform to Python style + guides (`PEP 7`_ and `PEP 8`_). + Note that no backups are made – please commit any other changes before + using this target. + + Requires the ``indent`` program and the ``autopep8`` Python module. + +.. _PEP 7: https://www.python.org/dev/peps/pep-0007/ +.. _PEP 8: https://www.python.org/dev/peps/pep-0008/ + ``make lcov lcov-open`` Generate and view test coverage for C code. Requires LCOV_.