Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting #1769

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
192 changes: 192 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 88
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: Never
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

29 changes: 26 additions & 3 deletions .github/workflows/analysis_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,33 @@ on:
- "**/*.md"

jobs:

run_linting_checks:
name: Linting checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Install linters
run: |
python3 build_tooling/format.py --install-tools

- name: Lint Python
if: always()
vasil-pashov marked this conversation as resolved.
Show resolved Hide resolved
run: |
python3 build_tooling/format.py --check --type python

- name: Lint C++
if: always()
run: |
python3 build_tooling/format.py --check --type cpp

get_commits_to_benchmark:
name: Get tag commits
name: Get tag commits
runs-on: ubuntu-latest
steps:
- name: Checkout code
steps:
- name: Get tag commits
uses: actions/[email protected]
with:
fetch-depth: 0
Expand All @@ -27,6 +49,7 @@ jobs:
id: get_tags
run: |
python3 build_tooling/get_commits_for_benchmark.py ${{ inputs.run_all_benchmarks == true && '--run_all_benchmarks' || ''}}

outputs:
matrix: ${{ steps.get_tags.outputs.commits }}

Expand Down
127 changes: 127 additions & 0 deletions build_tooling/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""Linting tools for ArcticDB.

Usage:

First bootstrap by installing the linting tools:

python build_tooling/format.py --install-tools

Then see the help section for how to run the linters:

python build_tooling/format.py --help

Or just run them on everything:

python build_tooling/format.py --in-place --type all

"""
import argparse
import pathlib
import sys
import subprocess


black_version = "24.8.0"
clang_format_version = "18.1.8"


def install_tools():
black = subprocess.run(["pip", "install", f"black=={black_version}"]).returncode
clang = subprocess.run(["pip", "install", f"clang-format=={clang_format_version}"]).returncode
return black or clang


def lint_python(in_place: bool):
try:
import black
assert black.__version__ == black_version
except ImportError:
raise RuntimeError("black not installed. Run this script with --install-tools then try again")

if in_place:
return subprocess.run(["black", "python/"]).returncode
else:
return subprocess.run(["black", "--check", "python/"]).returncode


def lint_cpp(in_place: bool):
try:
import clang_format
except ImportError:
raise RuntimeError("clang-format not installed. Run this script with --install-tools then try again")

files = []
root = pathlib.Path("cpp", "arcticdb")
for e in ("*.cpp", "*.hpp"):
for f in root.rglob(e):
files.append(str(f))

args = ["clang-format"]
if in_place:
args.append("-i")
else:
args.append("--dry-run")
args.append("-Werror")

print(f"Running {args} over {len(files)} files")
args += files

return subprocess.run(args).returncode


def main(type: str, in_place: bool):
if type == "python":
return lint_python(in_place)
elif type == "cpp":
return lint_cpp(in_place)
else:
return lint_python(in_place) or lint_cpp(in_place)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="ArcticDBLint",
description="Linter for ArcticDB"
)
parser.add_argument(
'--install-tools',
action='store_true',
help="Install the linters we need"
)
parser.add_argument(
'-t',
'--type',
help="Type of files to format. {python,cpp,all}"
)
parser.add_argument(
'-c',
'--check',
action='store_true',
help="Just check that your code is compliant. Do not change files."
)
parser.add_argument(
'-i',
'--in-place',
action='store_true',
help="Apply linting rules to your working copy. Changes files."
)
args = parser.parse_args()

if args.install_tools:
sys.exit(install_tools())

if args.check and args.in_place:
raise RuntimeError("Cannot specify both --check and --in-place")
if not args.check and not args.in_place:
raise RuntimeError("Must specify exactly on of --check and --in-place")
if not args.type:
raise RuntimeError("Must specify --type")
if args.type not in ("python", "cpp", "all"):
raise RuntimeError("Invalid --type")

return_code = main(
type=args.type,
in_place=args.in_place,
)

sys.exit(return_code)
Loading
Loading