Skip to content

Commit 89fe8d2

Browse files
authored
Add clang-format configuration (#326)
* Add comments to Python structures to avoid wrapping on a single line when formatting with clang-format
1 parent c8820f4 commit 89fe8d2

13 files changed

+210
-32
lines changed

.clang-format

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Language: Cpp
2+
IndentWidth: 2
3+
UseTab: Never
4+
ColumnLimit: 120
5+
SortIncludes: false
6+
AccessModifierOffset: -2
7+
ReflowComments: false
8+
ConstructorInitializerIndentWidth: 2
9+
ContinuationIndentWidth: 2
10+
AllowShortFunctionsOnASingleLine: Inline
11+
BreakBeforeBraces: Custom
12+
BraceWrapping:
13+
AfterExternBlock: true
14+
AfterClass: true
15+
AfterFunction: true
16+
AfterNamespace: false
17+
AfterEnum: false
18+
AfterCaseLabel: true
19+
AfterControlStatement: MultiLine
20+
AfterStruct: false
21+
AfterUnion: false
22+
BeforeLambdaBody: false
23+
BeforeElse: false
24+
BeforeCatch: false
25+
BeforeWhile: false
26+
IndentBraces: false
27+
SplitEmptyFunction: true
28+
SplitEmptyRecord: false
29+
SplitEmptyNamespace: true
30+
PPIndentWidth: 2
31+
FixNamespaceComments: false
32+
IndentPPDirectives: BeforeHash
33+
SpaceBeforeParens: Custom
34+
SpaceBeforeParensOptions:
35+
AfterControlStatements: true
36+
AfterForeachMacros: true
37+
AfterFunctionDefinitionName: false
38+
AfterFunctionDeclarationName: false
39+
AfterIfMacros: true
40+
AfterOverloadedOperator: false
41+
AfterRequiresInClause: false
42+
AfterRequiresInExpression: false
43+
BeforeNonEmptyParentheses: false
44+
SpaceAfterCStyleCast: false
45+
SpaceAfterLogicalNot: false
46+
SpaceAfterTemplateKeyword: false
47+
SpaceAroundPointerQualifiers: Default
48+
SpaceBeforeAssignmentOperators: true
49+
SpaceBeforeCaseColon: false
50+
SpaceBeforeCpp11BracedList: true
51+
SpaceBeforeCtorInitializerColon: true
52+
SpaceBeforeInheritanceColon: true
53+
SpaceBeforeRangeBasedForLoopColon: true
54+
SpaceBeforeSquareBrackets: false
55+
SpaceInEmptyBlock: false
56+
SpaceInEmptyParentheses: false
57+
SpacesBeforeTrailingComments: 1
58+
SpacesInAngles: Never
59+
SpacesInConditionalStatement: false
60+
SpacesInContainerLiterals: true
61+
SpacesInCStyleCastParentheses: false
62+
SpacesInLineCommentPrefix:
63+
Minimum: 1
64+
Maximum: -1
65+
IndentCaseBlocks: false
66+
IndentCaseLabels: false
67+
AlignAfterOpenBracket: DontAlign
68+
BreakConstructorInitializers: BeforeComma
69+
AlwaysBreakTemplateDeclarations: true
70+
NamespaceIndentation: None
71+
AlignArrayOfStructures: None
72+
AlignConsecutiveAssignments:
73+
Enabled: false
74+
AcrossEmptyLines: false
75+
AcrossComments: false
76+
AlignCompound: false
77+
PadOperators: false
78+
AlignConsecutiveBitFields:
79+
Enabled: false
80+
AcrossEmptyLines: false
81+
AcrossComments: false
82+
AlignCompound: false
83+
PadOperators: false
84+
AlignConsecutiveDeclarations:
85+
Enabled: false
86+
AcrossEmptyLines: false
87+
AcrossComments: false
88+
AlignCompound: false
89+
PadOperators: false
90+
AlignConsecutiveMacros:
91+
Enabled: false
92+
AcrossEmptyLines: true
93+
AcrossComments: false
94+
AlignCompound: false
95+
PadOperators: false
96+
AlignEscapedNewlines: DontAlign
97+
AlignOperands: Align
98+
AlignTrailingComments: true
99+
AllowAllArgumentsOnNextLine: false
100+
AllowAllParametersOfDeclarationOnNextLine: true
101+
AllowShortBlocksOnASingleLine: Empty
102+
AllowShortCaseLabelsOnASingleLine: false
103+
AllowShortEnumsOnASingleLine: true
104+
AllowShortIfStatementsOnASingleLine: Never
105+
AllowShortLambdasOnASingleLine: All
106+
AllowShortLoopsOnASingleLine: false
107+
AlwaysBreakAfterDefinitionReturnType: None
108+
AlwaysBreakAfterReturnType: None
109+
AlwaysBreakBeforeMultilineStrings: false
110+
BinPackArguments: true
111+
BinPackParameters: true
112+
BitFieldColonSpacing: After
113+
BreakBeforeBinaryOperators: NonAssignment
114+
BreakBeforeConceptDeclarations: Always
115+
BreakBeforeTernaryOperators: true
116+
BreakInheritanceList: BeforeColon
117+
BreakStringLiterals: true
118+
CompactNamespaces: false
119+
Cpp11BracedListStyle: true
120+
PointerAlignment: Left
121+
QualifierAlignment: Leave
122+
ReferenceAlignment: Pointer
123+
DerivePointerAlignment: false
124+
DisableFormat: false
125+
EmptyLineAfterAccessModifier: Leave
126+
MaxEmptyLinesToKeep: 1
127+
EmptyLineBeforeAccessModifier: LogicalBlock
128+
ExperimentalAutoDetectBinPacking: false
129+
ForEachMacros:
130+
- foreach
131+
- Q_FOREACH
132+
StatementAttributeLikeMacros:
133+
- Q_EMIT
134+
StatementMacros:
135+
- Q_UNUSED
136+
- QT_REQUIRE_VERSION
137+
- Q_OBJECT
138+
- PyObject_HEAD
139+
IndentAccessModifiers: false
140+
IndentExternBlock: AfterExternBlock
141+
IndentGotoLabels: true
142+
IndentRequiresClause: true
143+
IndentWrappedFunctionNames: false
144+
InsertBraces: false
145+
InsertTrailingCommas: None
146+
KeepEmptyLinesAtTheStartOfBlocks: true
147+
LambdaBodyIndentation: OuterScope
148+
PackConstructorInitializers: BinPack
149+
RemoveBracesLLVM: false
150+
RequiresClausePosition: OwnLine
151+
SeparateDefinitionBlocks: Leave
152+
ShortNamespaceLines: 1
153+
SortUsingDeclarations: false
154+
SpacesInParentheses: false
155+
SpacesInSquareBrackets: false
156+
Standard: Latest

run-clang-format.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -xeuo pipefail
3+
which -a clang-format-20 > /dev/null \
4+
|| (echo -e "20.0.0\n$(clang-format${1+-$1} --version | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)')" | sort -CV ) \
5+
|| { echo "use '${0} <clang-format-version-not-less-than-20>' to call exact proper version" ; exit 1 ; }
6+
7+
IGNORED_DIRS=(
8+
"./generated_cpp_515"
9+
"./examples"
10+
"./generator/simplecpp"
11+
"./build"
12+
)
13+
14+
IGNORE_CMD=""
15+
16+
for DIR in "${IGNORED_DIRS[@]}"; do
17+
IGNORE_CMD+=" -path $DIR -o"
18+
done
19+
20+
IGNORE_CMD=${IGNORE_CMD% -o}
21+
22+
find . \( $IGNORE_CMD \) -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i

src/PythonQt.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,15 +1819,15 @@ static PyMethodDef PythonQtMethods[] = {
18191819
};
18201820

18211821
static PyModuleDef PythonQtModuleDef = {
1822-
PyModuleDef_HEAD_INIT,
1823-
"",
1824-
nullptr,
1825-
-1,
1826-
PythonQtMethods,
1827-
nullptr,
1828-
nullptr,
1829-
nullptr,
1830-
nullptr
1822+
PyModuleDef_HEAD_INIT, /* m_base */
1823+
"", /* m_name */
1824+
nullptr, /* m_doc */
1825+
-1, /* m_size */
1826+
PythonQtMethods, /* m_methods */
1827+
nullptr, /* m_slots */
1828+
nullptr, /* m_traverse */
1829+
nullptr, /* m_clear */
1830+
nullptr /* m_free */
18311831
};
18321832

18331833
void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName)

src/PythonQtBoolResult.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
103103
};
104104

105105
PyTypeObject PythonQtBoolResult_Type = {
106-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
107-
"BoolResult",
108-
sizeof(PythonQtBoolResultObject),
109-
0,
106+
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
107+
"BoolResult", /* tp_name */
108+
sizeof(PythonQtBoolResultObject), /* tp_basicsize */
109+
0, /* tp_itemsize */
110110
nullptr, /* tp_dealloc */
111111
0, /* tp_vectorcall_offset */
112112
nullptr, /* tp_getattr */
113113
nullptr, /* tp_setattr */
114-
nullptr,
114+
nullptr, /* tp_as_async */
115115
(reprfunc)PythonQtBoolResult_repr, /* tp_repr */
116116
&PythonQtBoolResult_as_number, /* tp_as_number */
117117
nullptr, /* tp_as_sequence */

src/PythonQtClassWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static PyObject * PythonQtClassWrapper_repr(PyObject * obj)
594594
*/
595595

596596
PyTypeObject PythonQtClassWrapper_Type = {
597-
PyVarObject_HEAD_INIT(nullptr, 0)
597+
PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/
598598
"PythonQt.PythonQtClassWrapper", /*tp_name*/
599599
sizeof(PythonQtClassWrapper), /*tp_basicsize*/
600600
0, /*tp_itemsize*/

src/PythonQtImporter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ Create a new PythonQtImporter instance. 'path' must be a valid path on disk/or i
495495
#define DEFERRED_ADDRESS(ADDR) nullptr
496496

497497
PyTypeObject PythonQtImporter_Type = {
498-
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
499-
"PythonQtImport.PythonQtImporter",
500-
sizeof(PythonQtImporter),
498+
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) /*tp_base*/
499+
"PythonQtImport.PythonQtImporter", /* tp_name */
500+
sizeof(PythonQtImporter), /* tp_basicsize */
501501
0, /* tp_itemsize */
502502
(destructor)PythonQtImporter_dealloc, /* tp_dealloc */
503503
0, /* tp_vectorcall_offset */
@@ -878,7 +878,7 @@ PyDoc_STRVAR(mlabimport_doc,
878878
"Imports python files into PythonQt, completely replaces internal python import");
879879

880880
static struct PyModuleDef PythonQtImport_def = {
881-
PyModuleDef_HEAD_INIT,
881+
PyModuleDef_HEAD_INIT, /* m_base */
882882
"PythonQtImport", /* m_name */
883883
mlabimport_doc, /* m_doc */
884884
-1, /* m_size */

src/PythonQtInstanceWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ static PyNumberMethods PythonQtInstanceWrapper_as_number = {
903903
};
904904

905905
PyTypeObject PythonQtInstanceWrapper_Type = {
906-
PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0)
906+
PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0) /*tp_base*/
907907
"PythonQt.PythonQtInstanceWrapper", /*tp_name*/
908908
sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/
909909
0, /*tp_itemsize*/

src/PythonQtProperty.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ PyDoc_STRVAR(PythonQtProperty_doc,
194194
" constant=False, final=False, notify=None) -> Property\n");
195195

196196
PyTypeObject PythonQtProperty_Type = {
197-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
197+
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
198198
"PythonQt.QtCore.Property", /*tp_name*/
199199
sizeof(PythonQtProperty), /*tp_basicsize*/
200200
0, /*tp_itemsize*/

src/PythonQtSignal.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ PyDoc_STRVAR(PythonQtSignalFunction_doc,
394394
"Signal(*types) -> Signal\n");
395395

396396
PyTypeObject PythonQtSignalFunction_Type = {
397-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
398-
"QtCore.Signal",
399-
sizeof(PythonQtSignalFunctionObject),
400-
0,
397+
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
398+
"QtCore.Signal", /* tp_name */
399+
sizeof(PythonQtSignalFunctionObject), /* tp_basicsize */
400+
0, /* tp_itemsize */
401401
(destructor)meth_dealloc, /* tp_dealloc */
402402
0, /* tp_vectorcall_offset */
403403
nullptr, /* tp_getattr */

src/PythonQtSlot.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ meth_descr_get(PyObject *descr, PyObject *obj, PyObject* type)
813813
}
814814

815815
PyTypeObject PythonQtSlotFunction_Type = {
816-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
817-
"builtin_qt_slot",
818-
sizeof(PythonQtSlotFunctionObject),
819-
0,
816+
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
817+
"builtin_qt_slot", /* tp_itemsize */
818+
sizeof(PythonQtSlotFunctionObject), /* tp_basicsize */
819+
0, /* tp_itemsize */
820820
(destructor)meth_dealloc, /* tp_dealloc */
821821
0, /* tp_vectorcall_offset */
822822
nullptr, /* tp_getattr */

0 commit comments

Comments
 (0)