Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
Language: Cpp
IndentWidth: 2
UseTab: Never
ColumnLimit: 120
SortIncludes: false
AccessModifierOffset: -2
ReflowComments: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
AllowShortFunctionsOnASingleLine: Inline
BreakBeforeBraces: Custom
BraceWrapping:
AfterExternBlock: true
AfterClass: true
AfterFunction: true
AfterNamespace: false
AfterEnum: false
AfterCaseLabel: true
AfterControlStatement: MultiLine
AfterStruct: false
AfterUnion: false
BeforeLambdaBody: false
BeforeElse: false
BeforeCatch: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false
SplitEmptyNamespace: true
PPIndentWidth: 2
FixNamespaceComments: false
IndentPPDirectives: BeforeHash
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
IndentCaseBlocks: false
IndentCaseLabels: false
AlignAfterOpenBracket: DontAlign
BreakConstructorInitializers: BeforeComma
AlwaysBreakTemplateDeclarations: true
NamespaceIndentation: None
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: true
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: After
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: Always
BreakBeforeTernaryOperators: true
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
CompactNamespaces: false
Cpp11BracedListStyle: true
PointerAlignment: Left
QualifierAlignment: Leave
ReferenceAlignment: Pointer
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Leave
MaxEmptyLinesToKeep: 1
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
ForEachMacros:
- foreach
- Q_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
- Q_OBJECT
- PyObject_HEAD
IndentAccessModifiers: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentRequiresClause: true
IndentWrappedFunctionNames: false
InsertBraces: false
InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: OuterScope
PackConstructorInitializers: BinPack
RemoveBracesLLVM: false
RequiresClausePosition: OwnLine
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortUsingDeclarations: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
22 changes: 22 additions & 0 deletions run-clang-format.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to consider adding the clang-format hook to a pre-commit-config yaml as 3D Slicer and other related projects have adopted (see https://github.com/Slicer/Slicer/blob/1b1bbb22b4f858ff3d47d196de4ac491a0b9ea5c/.pre-commit-config.yaml#L27-L39). Pre-commit-config yml usage has been adopted by many projects and something that is generally called in a GitHub actions workflow file (e.g. lint.yml) using the pre-commit github action (https://github.com/pre-commit/action).

^This way new styling is applied consistently and enforced for every PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point! I'm using pre-commit in all Python projects, just didn't think about it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesobutler - pre-commit is added now, thanks for the suggestion!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Now just need a lint github workflow to run pre-commit where the workflow will fail if pre-commit detects issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had also enabled pre-commit.ci (as I do usually with pre-commit), so indeed the workflow will fail in this case.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -xeuo pipefail
which -a clang-format-20 > /dev/null \
|| (echo -e "20.0.0\n$(clang-format${1+-$1} --version | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)')" | sort -CV ) \
|| { echo "use '${0} <clang-format-version-not-less-than-20>' to call exact proper version" ; exit 1 ; }

IGNORED_DIRS=(
"./generated_cpp_515"
"./examples"
"./generator/simplecpp"
"./build"
)

IGNORE_CMD=""

for DIR in "${IGNORED_DIRS[@]}"; do
IGNORE_CMD+=" -path $DIR -o"
done

IGNORE_CMD=${IGNORE_CMD% -o}

find . \( $IGNORE_CMD \) -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i
18 changes: 9 additions & 9 deletions src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,15 +1819,15 @@ static PyMethodDef PythonQtMethods[] = {
};

static PyModuleDef PythonQtModuleDef = {
PyModuleDef_HEAD_INIT,
"",
nullptr,
-1,
PythonQtMethods,
nullptr,
nullptr,
nullptr,
nullptr
PyModuleDef_HEAD_INIT, /* m_base */
"", /* m_name */
nullptr, /* m_doc */
-1, /* m_size */
PythonQtMethods, /* m_methods */
nullptr, /* m_slots */
nullptr, /* m_traverse */
nullptr, /* m_clear */
nullptr /* m_free */
};

void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName)
Expand Down
10 changes: 5 additions & 5 deletions src/PythonQtBoolResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
};

PyTypeObject PythonQtBoolResult_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"BoolResult",
sizeof(PythonQtBoolResultObject),
0,
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
"BoolResult", /* tp_name */
sizeof(PythonQtBoolResultObject), /* tp_basicsize */
0, /* tp_itemsize */
nullptr, /* tp_dealloc */
0, /* tp_vectorcall_offset */
nullptr, /* tp_getattr */
nullptr, /* tp_setattr */
nullptr,
nullptr, /* tp_as_async */
(reprfunc)PythonQtBoolResult_repr, /* tp_repr */
&PythonQtBoolResult_as_number, /* tp_as_number */
nullptr, /* tp_as_sequence */
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtClassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ static PyObject * PythonQtClassWrapper_repr(PyObject * obj)
*/

PyTypeObject PythonQtClassWrapper_Type = {
PyVarObject_HEAD_INIT(nullptr, 0)
PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/
"PythonQt.PythonQtClassWrapper", /*tp_name*/
sizeof(PythonQtClassWrapper), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down
8 changes: 4 additions & 4 deletions src/PythonQtImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ Create a new PythonQtImporter instance. 'path' must be a valid path on disk/or i
#define DEFERRED_ADDRESS(ADDR) nullptr

PyTypeObject PythonQtImporter_Type = {
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"PythonQtImport.PythonQtImporter",
sizeof(PythonQtImporter),
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) /*tp_base*/
"PythonQtImport.PythonQtImporter", /* tp_name */
sizeof(PythonQtImporter), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)PythonQtImporter_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
Expand Down Expand Up @@ -878,7 +878,7 @@ PyDoc_STRVAR(mlabimport_doc,
"Imports python files into PythonQt, completely replaces internal python import");

static struct PyModuleDef PythonQtImport_def = {
PyModuleDef_HEAD_INIT,
PyModuleDef_HEAD_INIT, /* m_base */
"PythonQtImport", /* m_name */
mlabimport_doc, /* m_doc */
-1, /* m_size */
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtInstanceWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ static PyNumberMethods PythonQtInstanceWrapper_as_number = {
};

PyTypeObject PythonQtInstanceWrapper_Type = {
PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0)
PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0) /*tp_base*/
"PythonQt.PythonQtInstanceWrapper", /*tp_name*/
sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ PyDoc_STRVAR(PythonQtProperty_doc,
" constant=False, final=False, notify=None) -> Property\n");

PyTypeObject PythonQtProperty_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
"PythonQt.QtCore.Property", /*tp_name*/
sizeof(PythonQtProperty), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down
8 changes: 4 additions & 4 deletions src/PythonQtSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ PyDoc_STRVAR(PythonQtSignalFunction_doc,
"Signal(*types) -> Signal\n");

PyTypeObject PythonQtSignalFunction_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"QtCore.Signal",
sizeof(PythonQtSignalFunctionObject),
0,
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
"QtCore.Signal", /* tp_name */
sizeof(PythonQtSignalFunctionObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)meth_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
nullptr, /* tp_getattr */
Expand Down
8 changes: 4 additions & 4 deletions src/PythonQtSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,10 @@ meth_descr_get(PyObject *descr, PyObject *obj, PyObject* type)
}

PyTypeObject PythonQtSlotFunction_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"builtin_qt_slot",
sizeof(PythonQtSlotFunctionObject),
0,
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
"builtin_qt_slot", /* tp_itemsize */
sizeof(PythonQtSlotFunctionObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)meth_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
nullptr, /* tp_getattr */
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtSlotDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ PyDoc_STRVAR(PythonQtSlotDecorator_doc,
"Slot(*types, result=type) -> Slot\n");

PyTypeObject PythonQtSlotDecorator_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/
"PythonQt.QtCore.Slot", /*tp_name*/
sizeof(PythonQtSlotDecorator), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtStdIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static PyMemberDef PythonQtStdInRedirect_members[] = {
};

PyTypeObject PythonQtStdInRedirectType = {
PyVarObject_HEAD_INIT(nullptr, 0)
PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/
"PythonQtStdInRedirect", /*tp_name*/
sizeof(PythonQtStdInRedirect), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtStdOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static PyMemberDef PythonQtStdOutRedirect_members[] = {
};

PyTypeObject PythonQtStdOutRedirectType = {
PyVarObject_HEAD_INIT(nullptr, 0)
PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/
"PythonQtStdOutRedirect", /*tp_name*/
sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand Down