From a90c3daae9fb1ede33bac3ed690c0d774d47559f Mon Sep 17 00:00:00 2001 From: Abhinav Arora Date: Fri, 21 Jan 2022 01:38:46 -0800 Subject: [PATCH 1/4] Add Black and other auto formatters as pre-commit hooks --- .circleci/config.yml | 22 ++++++++++++++++++++++ .circleci/config.yml.in | 22 ++++++++++++++++++++++ .pre-commit-config.yaml | 20 ++++++++++++++++++++ pyproject.toml | 10 ++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.circleci/config.yml b/.circleci/config.yml index 9fae77d4eb..64f8fc4c5c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,6 +92,25 @@ jobs: python .circleci/regenerate.py git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1) + lint_python_and_config: + docker: + - image: circleci/python:3.7 + steps: + - checkout + - run: + name: Install pre-commit + command: pip install --user --progress-bar off pre-commit + - run: + name: Install pre-commit hooks + command: pre-commit install-hooks + - run: + name: Lint Python code and config files + command: pre-commit run --all-files + - run: + name: Required lint modifications + when: always + command: git --no-pager diff --color=always + binary_linux_wheel: <<: *binary_common docker: @@ -610,6 +629,9 @@ jobs: workflows: + lint: + jobs: + - lint_python_and_config build: jobs: - circleci_consistency diff --git a/.circleci/config.yml.in b/.circleci/config.yml.in index 3055fdc3c4..d6914b1371 100644 --- a/.circleci/config.yml.in +++ b/.circleci/config.yml.in @@ -92,6 +92,25 @@ jobs: python .circleci/regenerate.py git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1) + lint_python_and_config: + docker: + - image: circleci/python:3.7 + steps: + - checkout + - run: + name: Install pre-commit + command: pip install --user --progress-bar off pre-commit + - run: + name: Install pre-commit hooks + command: pre-commit install-hooks + - run: + name: Lint Python code and config files + command: pre-commit run --all-files + - run: + name: Required lint modifications + when: always + command: git --no-pager diff --color=always + binary_linux_wheel: <<: *binary_common docker: @@ -610,6 +629,9 @@ jobs: workflows: + lint: + jobs: + - lint_python_and_config build: jobs: - circleci_consistency diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..fe45e5d65c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-docstring-first + - id: check-toml + - id: check-yaml + exclude: packaging/.* + - id: mixed-line-ending + args: [--fix=lf] + - id: end-of-file-fixer + + + - repo: https://github.com/omnilib/ufmt + rev: v1.3.0 + hooks: + - id: ufmt + additional_dependencies: + - black == 21.9b0 + - usort == 0.6.4 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..4d3eabcae3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[tool.usort] + +first_party_detection = false + +[tool.black] + +line-length = 120 +target-version = ["py37"] + +[tool.ufmt] \ No newline at end of file From 9f1dd16a8831d6087d36df21aa2497a74e71b959 Mon Sep 17 00:00:00 2001 From: Abhinav Arora Date: Thu, 27 Jan 2022 21:26:58 -0800 Subject: [PATCH 2/4] Add new line at end of new files --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe45e5d65c..aa5d4c8f47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,4 +17,4 @@ repos: - id: ufmt additional_dependencies: - black == 21.9b0 - - usort == 0.6.4 \ No newline at end of file + - usort == 0.6.4 diff --git a/pyproject.toml b/pyproject.toml index 4d3eabcae3..bda3b89bb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,4 @@ first_party_detection = false line-length = 120 target-version = ["py37"] -[tool.ufmt] \ No newline at end of file +[tool.ufmt] From c8330f866b2abb162c5d0c2c0b2f2b8fd2910864 Mon Sep 17 00:00:00 2001 From: Abhinav Arora Date: Thu, 27 Jan 2022 23:59:00 -0800 Subject: [PATCH 3/4] Add clangformat --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aa5d4c8f47..8670a6127c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,3 +18,9 @@ repos: additional_dependencies: - black == 21.9b0 - usort == 0.6.4 + + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v13.0.0 + hooks: + - id: clang-format From 7bf0c6c08b53c834ec6d420f2ab67c56d99099b0 Mon Sep 17 00:00:00 2001 From: Abhinav Arora Date: Fri, 28 Jan 2022 00:21:21 -0800 Subject: [PATCH 4/4] Add clang-format options --- .clang-format | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..73304266bd --- /dev/null +++ b/.clang-format @@ -0,0 +1,88 @@ +--- +AccessModifierOffset: -1 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ] +IncludeCategories: + - Regex: '^<.*\.h(pp)?>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 2000000 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +...