From 0c66d04a43badd77ed51e6d029b07de94bbcb02c Mon Sep 17 00:00:00 2001 From: haiqi96 <14502009+haiqi96@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:15:11 -0500 Subject: [PATCH] feat(linting): Add Taskfile tasks to run linters. (#76) --- .clang-format | 164 ----------- .clang-tidy | 44 --- .gersemirc | 5 + .github/ISSUE_TEMPLATE/bug-report.yml | 67 ++--- .github/ISSUE_TEMPLATE/feature-request.yml | 35 ++- .github/workflows/build_wheels.yml | 311 ++++++++++----------- .gitmodules | 3 + README.md | 121 ++++---- Taskfile.yml | 30 +- docs/tasks.yml | 4 +- lint-tasks.yml | 202 +++++++++++++ requirements-dev.txt | 2 + src/clp_ffi_py/.clang-format | 20 ++ tools/yscope-dev-utils | 1 + 14 files changed, 523 insertions(+), 486 deletions(-) delete mode 100644 .clang-format delete mode 100644 .clang-tidy create mode 100644 .gersemirc create mode 100644 lint-tasks.yml create mode 100644 src/clp_ffi_py/.clang-format create mode 160000 tools/yscope-dev-utils diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 7a5e06df..00000000 --- a/.clang-format +++ /dev/null @@ -1,164 +0,0 @@ ---- -ColumnLimit: 100 -IndentWidth: 4 ---- -Language: "Cpp" -AccessModifierOffset: -4 -AlignAfterOpenBracket: "BlockIndent" -AlignArrayOfStructures: "None" -AlignConsecutiveAssignments: "None" -AlignConsecutiveBitFields: "None" -AlignConsecutiveDeclarations: "None" -AlignConsecutiveMacros: "None" -AlignEscapedNewlines: "DontAlign" -AlignOperands: "Align" -AlignTrailingComments: - Kind: "Never" -AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowBreakBeforeNoexceptSpecifier: "OnlyWithParen" -AllowShortBlocksOnASingleLine: "Always" -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: "Inline" -AllowShortIfStatementsOnASingleLine: "Never" -AllowShortLambdasOnASingleLine: "All" -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: "None" -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: "Yes" -BinPackArguments: false -BinPackParameters: false -BitFieldColonSpacing: "Both" -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: "MultiLine" - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterExternBlock: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyNamespace: false - SplitEmptyRecord: false -BreakAfterAttributes: "Never" -BreakBeforeBinaryOperators: "All" -BreakBeforeBraces: "Custom" -BreakBeforeConceptDeclarations: "Always" -BreakBeforeInlineASMColon: "OnlyMultiline" -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: "BeforeColon" -BreakInheritanceList: "BeforeColon" -BreakStringLiterals: true -CompactNamespaces: true -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 8 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: "Never" -EmptyLineBeforeAccessModifier: "LogicalBlock" -FixNamespaceComments: true -IncludeBlocks: "Regroup" -IncludeCategories: - # NOTE: A header is grouped by first matching regex - # Python header must be included before any others - - Regex: "^$" - Priority: -1 - # Project headers - - Regex: "^$" - Priority: 1 - # C++ standard libraries - - Regex: "^<.*>$" - Priority: 2 -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExternBlock: "NoIndent" -IndentGotoLabels: false -IndentPPDirectives: "BeforeHash" -IndentRequiresClause: false -IndentWrappedFunctionNames: false -InsertBraces: true -InsertNewlineAtEOF: true -IntegerLiteralSeparator: - Binary: 4 - BinaryMinDigits: 4 - Decimal: 3 - DecimalMinDigits: 5 - Hex: 4 - HexMinDigits: 4 -KeepEmptyLinesAtTheStartOfBlocks: false -LambdaBodyIndentation: "Signature" -LineEnding: "LF" -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: "None" -PPIndentWidth: -1 -PackConstructorInitializers: "CurrentLine" -PenaltyBreakOpenParenthesis: 25 -PenaltyBreakBeforeFirstCallParameter: 25 -PenaltyReturnTypeOnItsOwnLine: 100 -PointerAlignment: "Left" -QualifierAlignment: "Custom" -QualifierOrder: - - "static" - - "friend" - - "inline" - # constexpr west as explained in https://www.youtube.com/watch?v=z6s6bacI424 - - "constexpr" - - "type" - - "const" - - "volatile" -ReferenceAlignment: "Pointer" -ReflowComments: true -RemoveBracesLLVM: false -RemoveSemicolon: true -RequiresClausePosition: "OwnLine" -RequiresExpressionIndentation: "OuterScope" -SeparateDefinitionBlocks: "Always" -ShortNamespaceLines: 0 -SortIncludes: "CaseInsensitive" -SortUsingDeclarations: "Lexicographic" -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: "Default" -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: "ControlStatements" -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: "Custom" -SpacesInParensOptions: - InConditionalStatements: false - InCStyleCasts: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: "Latest" -TabWidth: 4 -UseTab: "Never" diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 43313201..00000000 --- a/.clang-tidy +++ /dev/null @@ -1,44 +0,0 @@ ---- -Checks: >- - bugprone-*, - -bugprone-easily-swappable-parameters, - cert-*, - clang-analyzer-*, - clang-diagnostic-*, - concurrency-*, - cppcoreguidelines-*, - -cppcoreguidelines-avoid-non-const-global-variables, - -cppcoreguidelines-pro-type-cstyle-cast, - -cppcoreguidelines-pro-type-vararg, - misc-*, - modernize-*, - -modernize-avoid-c-arrays, - performance-*, - portability-*, - readability-*, - -readability-identifier-length, - -readability-simplify-boolean-expr - -WarningsAsErrors: >- - * - -FormatStyle: file -CheckOptions: - readability-identifier-naming.ClassCase: "CamelCase" - readability-identifier-naming.ClassMemberCase: "lower_case" - readability-identifier-naming.ClassMemberPrefix: "m_" - readability-identifier-naming.ClassMethodCase: "lower_case" - readability-identifier-naming.ConstexprVariableCase: "CamelCase" - readability-identifier-naming.ConstexprVariablePrefix: "c" - readability-identifier-naming.EnumCase: "CamelCase" - readability-identifier-naming.EnumConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantPrefix: "c" - readability-identifier-naming.LocalVariableCase: "lower_case" - readability-identifier-naming.MemberCase: "lower_case" - readability-identifier-naming.MemberPrefix: "m_" - readability-identifier-naming.MethodCase: "lower_case" - readability-identifier-naming.ParameterCase: "lower_case" - readability-identifier-naming.StructCase: "CamelCase" - readability-identifier-naming.TypedefCase: "CamelCase" - readability-identifier-naming.UnionCase: "CamelCase" diff --git a/.gersemirc b/.gersemirc new file mode 100644 index 00000000..c6d6ef6c --- /dev/null +++ b/.gersemirc @@ -0,0 +1,5 @@ +# yamllint disable-line rule:line-length +# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json + +line_length: 100 +list_expansion: "favour-expansion" diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 29c7c357..2e05586c 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -1,40 +1,41 @@ name: "Bug Report" -description: Report software deficiencies +description: "Report software deficiencies" labels: ["bug"] body: -- type: markdown - attributes: - value: | - Use this form to report any functional or performance bugs you've found in the software. - - Be sure to check if your [issue](https://github.com/y-scope/clp-ffi-py/issues) has already been reported. + - type: "markdown" + attributes: + value: | + Use this form to report any functional or performance bugs you've found in the software. -- type: textarea - attributes: - label: Bug - description: "Describe what's wrong and if applicable, what you expected instead." - validations: - required: true + Be sure to check if your [issue](https://github.com/y-scope/clp-ffi-py/issues) has already + been reported. -- type: input - attributes: - label: clp-ffi-py version - description: "The release version number or development commit hash that has the bug." - placeholder: "Version number or commit hash" - validations: - required: true + - type: "textarea" + attributes: + label: "Bug" + description: "Describe what's wrong and if applicable, what you expected instead." + validations: + required: true -- type: textarea - attributes: - label: Environment - description: "The environment in which you're using clp-ffi-py." - placeholder: "OS version, docker version, etc." - validations: - required: true + - type: "input" + attributes: + label: "clp-ffi-py version" + description: "The release version number or development commit hash that has the bug." + placeholder: "Version number or commit hash" + validations: + required: true -- type: textarea - attributes: - label: Reproduction steps - description: "List each step required to reproduce the bug." - validations: - required: true + - type: "textarea" + attributes: + label: "Environment" + description: "The environment in which you're using clp-ffi-py." + placeholder: "OS version, docker version, etc." + validations: + required: true + + - type: "textarea" + attributes: + label: "Reproduction steps" + description: "List each step required to reproduce the bug." + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index 9484ca6f..4f22d915 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -1,23 +1,22 @@ name: "Feature/Change Request" -description: Request a feature or change +description: "Request a feature or change" labels: ["enhancement"] body: -- type: markdown - attributes: - value: | - Use this form to request a feature/change in the software, or the project as a whole. + - type: "markdown" + attributes: + value: | + Use this form to request a feature/change in the software, or the project as a whole. -- type: textarea - attributes: - label: Request - description: "Describe your request and why it's important." - validations: - required: true - -- type: textarea - attributes: - label: Possible implementation - description: "Describe any implementations you have in mind." - validations: - required: true + - type: "textarea" + attributes: + label: "Request" + description: "Describe your request and why it's important." + validations: + required: true + - type: "textarea" + attributes: + label: "Possible implementation" + description: "Describe any implementations you have in mind." + validations: + required: true diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index c606f3f2..a4c978cd 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -1,10 +1,8 @@ -name: Build +name: "Build" on: pull_request: paths: - - ".clang-format" - - ".clang-tidy" - ".github/workflows/build_wheels.yml" - ".gitmodules" - "CMakeLists.txt" @@ -16,8 +14,6 @@ on: - "tests/**" push: paths: - - ".clang-format" - - ".clang-tidy" - ".github/workflows/build_wheels.yml" - ".gitmodules" - "CMakeLists.txt" @@ -38,198 +34,189 @@ concurrency: jobs: linters: - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v4 + - uses: "actions/checkout@v4" + with: + submodules: "recursive" - - uses: actions/setup-python@v5 + - uses: "actions/setup-python@v5" with: python-version: "3.11" - run: | pip install --upgrade pip - pip install -r requirements-dev.txt - - - run: docformatter --check --diff clp_ffi_py tests - - - run: black --diff --check clp_ffi_py tests - - - run: ruff check --output-format=github clp_ffi_py tests - - run: mypy clp_ffi_py tests + - run: "npm install -g @go-task/cli" - - run: | - find src/clp_ffi_py/ -type f | xargs clang-format --dry-run --Werror - - - run: | - gersemi --check --line-length 100 --list-expansion favour-expansion CMakeLists.txt + - run: "task lint:check" build_wheels: - needs: [linters] - name: Build ${{ matrix.build.name }} - runs-on: ${{ matrix.build.os }} + needs: ["linters"] + name: "Build ${{ matrix.build.name }}" + runs-on: "${{ matrix.build.os }}" strategy: matrix: build: # macOS builds - - name: cp37-macosx_x86_64 - os: macos-14 - - name: cp38-macosx_arm64 - os: macos-14 - - name: cp38-macosx_universal2 - os: macos-14 - - name: cp38-macosx_x86_64 - os: macos-14 - - name: cp39-macosx_arm64 - os: macos-14 - - name: cp39-macosx_universal2 - os: macos-14 - - name: cp39-macosx_x86_64 - os: macos-14 - - name: cp310-macosx_arm64 - os: macos-14 - - name: cp310-macosx_universal2 - os: macos-14 - - name: cp310-macosx_x86_64 - os: macos-14 - - name: cp311-macosx_arm64 - os: macos-14 - - name: cp311-macosx_universal2 - os: macos-14 - - name: cp311-macosx_x86_64 - os: macos-14 - - name: cp312-macosx_arm64 - os: macos-14 - - name: cp312-macosx_universal2 - os: macos-14 - - name: cp312-macosx_x86_64 - os: macos-14 + - name: "cp37-macosx_x86_64" + os: "macos-14" + - name: "cp38-macosx_arm64" + os: "macos-14" + - name: "cp38-macosx_universal2" + os: "macos-14" + - name: "cp38-macosx_x86_64" + os: "macos-14" + - name: "cp39-macosx_arm64" + os: "macos-14" + - name: "cp39-macosx_universal2" + os: "macos-14" + - name: "cp39-macosx_x86_64" + os: "macos-14" + - name: "cp310-macosx_arm64" + os: "macos-14" + - name: "cp310-macosx_universal2" + os: "macos-14" + - name: "cp310-macosx_x86_64" + os: "macos-14" + - name: "cp311-macosx_arm64" + os: "macos-14" + - name: "cp311-macosx_universal2" + os: "macos-14" + - name: "cp311-macosx_x86_64" + os: "macos-14" + - name: "cp312-macosx_arm64" + os: "macos-14" + - name: "cp312-macosx_universal2" + os: "macos-14" + - name: "cp312-macosx_x86_64" + os: "macos-14" # Linux builds - - name: cp310-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp310-manylinux_i686 - os: ubuntu-22.04 - - name: cp310-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp310-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp310-musllinux_i686 - os: ubuntu-22.04 - - name: cp310-musllinux_x86_64 - os: ubuntu-22.04 - - name: cp311-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp311-manylinux_i686 - os: ubuntu-22.04 - - name: cp311-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp311-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp311-musllinux_i686 - os: ubuntu-22.04 - - name: cp311-musllinux_x86_64 - os: ubuntu-22.04 - - name: cp312-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp312-manylinux_i686 - os: ubuntu-22.04 - - name: cp312-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp312-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp312-musllinux_i686 - os: ubuntu-22.04 - - name: cp312-musllinux_x86_64 - os: ubuntu-22.04 - - name: cp37-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp37-manylinux_i686 - os: ubuntu-22.04 - - name: cp37-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp37-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp37-musllinux_i686 - os: ubuntu-22.04 - - name: cp37-musllinux_x86_64 - os: ubuntu-22.04 - - name: cp38-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp38-manylinux_i686 - os: ubuntu-22.04 - - name: cp38-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp38-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp38-musllinux_i686 - os: ubuntu-22.04 - - name: cp38-musllinux_x86_64 - os: ubuntu-22.04 - - name: cp39-manylinux_aarch64 - os: ubuntu-22.04 - - name: cp39-manylinux_i686 - os: ubuntu-22.04 - - name: cp39-manylinux_x86_64 - os: ubuntu-22.04 - - name: cp39-musllinux_aarch64 - os: ubuntu-22.04 - - name: cp39-musllinux_i686 - os: ubuntu-22.04 - - name: cp39-musllinux_x86_64 - os: ubuntu-22.04 + - name: "cp310-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp310-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp310-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp310-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp310-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp310-musllinux_x86_64" + os: "ubuntu-22.04" + - name: "cp311-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp311-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp311-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp311-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp311-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp311-musllinux_x86_64" + os: "ubuntu-22.04" + - name: "cp312-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp312-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp312-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp312-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp312-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp312-musllinux_x86_64" + os: "ubuntu-22.04" + - name: "cp37-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp37-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp37-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp37-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp37-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp37-musllinux_x86_64" + os: "ubuntu-22.04" + - name: "cp38-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp38-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp38-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp38-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp38-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp38-musllinux_x86_64" + os: "ubuntu-22.04" + - name: "cp39-manylinux_aarch64" + os: "ubuntu-22.04" + - name: "cp39-manylinux_i686" + os: "ubuntu-22.04" + - name: "cp39-manylinux_x86_64" + os: "ubuntu-22.04" + - name: "cp39-musllinux_aarch64" + os: "ubuntu-22.04" + - name: "cp39-musllinux_i686" + os: "ubuntu-22.04" + - name: "cp39-musllinux_x86_64" + os: "ubuntu-22.04" # Windows builds - - name: cp37-win_amd64 - os: windows-2022 - - name: cp38-win_amd64 - os: windows-2022 - - name: cp39-win_amd64 - os: windows-2022 - - name: cp310-win_amd64 - os: windows-2022 - - name: cp311-win_amd64 - os: windows-2022 - - name: cp312-win_amd64 - os: windows-2022 + - name: "cp37-win_amd64" + os: "windows-2022" + - name: "cp38-win_amd64" + os: "windows-2022" + - name: "cp39-win_amd64" + os: "windows-2022" + - name: "cp310-win_amd64" + os: "windows-2022" + - name: "cp311-win_amd64" + os: "windows-2022" + - name: "cp312-win_amd64" + os: "windows-2022" steps: - - name: Checkout - uses: actions/checkout@v4 + - name: "Checkout" + uses: "actions/checkout@v4" with: - submodules: recursive + submodules: "recursive" - - name: Set up QEMU - if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v3 + - name: "Set up QEMU" + if: "runner.os == 'Linux'" + uses: "docker/setup-qemu-action@v3" with: - platforms: all + platforms: "all" - - name: Build wheels - uses: pypa/cibuildwheel@v2.21 + - name: "Build wheels" + uses: "pypa/cibuildwheel@v2.21" env: - CIBW_BUILD: ${{ matrix.build.name }} + CIBW_BUILD: "${{ matrix.build.name }}" - - uses: actions/upload-artifact@v4 + - uses: "actions/upload-artifact@v4" with: - name: wheel-${{ matrix.build.name }} - path: ./wheelhouse/*.whl + name: "wheel-${{ matrix.build.name }}" + path: "./wheelhouse/*.whl" retention-days: 1 combine-wheels: - needs: [build_wheels] - name: Combine wheels - runs-on: ubuntu-latest + needs: ["build_wheels"] + name: "Combine wheels" + runs-on: "ubuntu-latest" env: - WHEEL_DIR: /tmp/wheels + WHEEL_DIR: "/tmp/wheels" steps: - - uses: actions/download-artifact@v4 + - uses: "actions/download-artifact@v4" with: - path: ${{env.WHEEL_DIR}} + path: "${{env.WHEEL_DIR}}" merge-multiple: true - - uses: actions/upload-artifact@v4 + - uses: "actions/upload-artifact@v4" with: - name: all-wheels - path: ${{env.WHEEL_DIR}} + name: "all-wheels" + path: "${{env.WHEEL_DIR}}" diff --git a/.gitmodules b/.gitmodules index d2958bff..c43e8a8d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,9 @@ [submodule "src/clp"] path = src/clp url = https://github.com/y-scope/clp.git +[submodule "tools/yscope-dev-utils"] + path = tools/yscope-dev-utils + url = https://github.com/y-scope/yscope-dev-utils.git [submodule "src/msgpack"] path = src/msgpack url = https://github.com/msgpack/msgpack-c diff --git a/README.md b/README.md index 0b75cb3d..c7bf189b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # clp-ffi-py -[![PyPI platforms][badge_pypi]][16] +[![PyPI platforms][badge_pypi]][7] [![Build status][badge_build_status]][clp_ffi_py_gh_actions] [![Downloads][badge_total_downloads]][pepy/clp_ffi_py] [![Downloads][badge_monthly_downloads]][pepy/clp_ffi_py] @@ -27,7 +27,7 @@ Note: - Tested on Linux, macOS and Windows. To install an older version or download the prebuilt `whl` package, check the -project homepage on PyPI [here][16]. +project homepage on PyPI [here][7]. ## Compatibility @@ -36,7 +36,7 @@ version >= 3.7. ## API Reference -The API reference for this library can be found on our [docs hub][19]. +The API reference for this library can be found on our [docs hub][10]. ## Building/Packaging @@ -51,7 +51,13 @@ To manually build a package for distribution, follow the steps below. * python3 * python3-dev * python3-venv -* [Task][18] >= 3.35.1 +* [Task][9] >= 3.38.0 + +### Set up +* Initialize and update yscope-dev-utils submodules: + ```shell + git submodule update --init --recursive tools/yscope-dev-utils + ``` ### Build commands @@ -188,7 +194,7 @@ help(SubstringWildcardQuery) ### Streaming Deserialize/Search Directly from S3 Remote Storage When working with CLP IR files stored on S3-compatible storage systems, -[smart_open][17] can be used to open and read the IR stream for the following +[smart_open][8] can be used to open and read the IR stream for the following benefits: - It only performs stream operation and does not download the file to the disk. @@ -235,9 +241,9 @@ closed. ### Parallel Processing -The `Query` and `LogEvent` classes can be serialized by [pickle][15]. Therefore, +The `Query` and `LogEvent` classes can be serialized by [pickle][6]. Therefore, deserializing and searching can be parallelized across streams/files using libraries -such as [multiprocessing][13] and [tqlm][14]. +such as [multiprocessing][4] and [tqlm][5]. ## Testing @@ -271,7 +277,7 @@ python -m unittest -bv ## Build and Test with cibuildwheel -This project utilizes [cibuildwheel][7] configuration. Whenever modifications +This project utilizes [cibuildwheel][3] configuration. Whenever modifications are made and committed to GitHub, the cibuildwheel Action will automatically initiate, building this library for several Python environments across diverse OS and architectures. You can access the build outcomes (wheel files) via the @@ -279,61 +285,56 @@ GitHub Action page. For instructions on customizing the build targets or running cibuildwheel locally, please refer to the official documentation of cibuildwheel. -## Contributing - -Before submitting a pull request, run the following error-checking and -formatting tools (found in [pyproject.toml]): - -* [mypy][3]: `mypy clp_ffi_py` - * mypy checks for typing errors. You should resolve all typing errors or if an - error cannot be resolved (e.g., it's due to a third-party library), you - should add a comment `# type: ignore` to [silence][4] the error. -* [docformatter][11]: `docformatter -i clp_ffi_py tests` - * This formats docstrings. You should review and add any changes to your PR. -* [Black][5]: `black clp_ffi_py` - * This formats the Python code according to Black's code-style rules. You - should review and add any changes to your PR. -* [clang-format][6]: `clang-format -i src/clp_ffi_py/**` - * This formats the C++ code according to the code-style rules specified in - `.clang-format`. You should review and add any changes to your PR. -* [ruff][10]: `ruff check --fix clp_ffi_py tests` - * This performs linting according to PEPs. You should review and add any - changes to your PR. -* [gersemi][9]: `gersemi -i -l 100 --list-expansion favour-expansion CMakeLists.txt` - * This formats CMakeLists.txt. You should review and add any changes to your PR. - -Note that `docformatter` should be run before `black` to give Black the -[last][12]. - -Additionally, the following tools can be useful during development. However, -they cannot be installed using `pip`. Developers need to install them using -other package management tools such as `apt-get`: - -* [clang-tidy][8]: `clang-tidy --extra-arg=-std=c++17 PATH_TO_THE_FILE` - * This static analysis tool catches improper coding behaviors based on the - rules specified in `.clang-tidy`, and sends suggestions corresponding to - each warning. Developers should manually review all the warnings and try - with their best effort to fix the reasonable ones. +## Adding files +Certain file types need to be added to our linting rules manually: + +- **CMake**. If adding a CMake file, add it (or its parent directory) as an argument to the + `gersemi` command in [lint-tasks.yaml](lint-tasks.yaml). + - If adding a directory, the file must be named `CMakeLists.txt` or use the `.cmake` extension. +- **YAML**. If adding a YAML file (regardless of its extension), add it as an argument to the + `yamllint` command in [lint-tasks.yaml](lint-tasks.yaml). +## Linting +Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any +violations or suppressed the warning. + +To run all linting checks: +```shell +task lint:check +``` + +To run all linting checks AND automatically fix any fixable issues: +```shell +task lint:fix +``` + +### Running specific linters +The commands above run all linting checks, but for performance you may want to run a subset (e.g., +if you only changed C++ files, you don't need to run the YAML linting checks) using one of the tasks +in the table below. + +| Task | Description | +|-------------------------|----------------------------------------------------------| +| `lint:cmake-check` | Runs the CMake linters. | +| `lint:cmake-fix` | Runs the CMake linters and fixes any violations. | +| `lint:cpp-check` | Runs the C++ linters (formatters and static analyzers). | +| `lint:cpp-fix` | Runs the C++ linters and fixes some violations. | +| `lint:cpp-format-check` | Runs the C++ formatters. | +| `lint:cpp-format-fix` | Runs the C++ formatters and fixes some violations. | +| `lint:py-check` | Runs the Python linters. | +| `lint:py-fix` | Runs the Python linters and fixes some violations. | +| `lint:yml-check` | Runs the YAML linters. | +| `lint:yml-fix` | Runs the YAML linters and fixes some violations. | [1]: https://github.com/y-scope/clp/tree/main/components/core [2]: https://github.com/y-scope/clp -[3]: https://mypy.readthedocs.io/en/stable/index.html -[4]: https://mypy.readthedocs.io/en/stable/common_issues.html#spurious-errors-and-locally-silencing-the-checker -[5]: https://black.readthedocs.io/en/stable/index.html -[6]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html -[7]: https://cibuildwheel.readthedocs.io/en/stable/ -[8]: https://clang.llvm.org/extra/clang-tidy/ -[9]: https://github.com/BlankSpruce/gersemi -[10]: https://beta.ruff.rs/docs/ -[11]: https://docformatter.readthedocs.io/en/latest/ -[12]: https://docformatter.readthedocs.io/en/latest/faq.html#interaction-with-black -[13]: https://docs.python.org/3/library/multiprocessing.html -[14]: https://tqdm.github.io/ -[15]: https://docs.python.org/3/library/pickle.html -[16]: https://pypi.org/project/clp-ffi-py/ -[17]: https://github.com/RaRe-Technologies/smart_open -[18]: https://taskfile.dev/installation/ -[19]: https://docs.yscope.com/clp-ffi-py/main/api/clp_ffi_py.html +[3]: https://cibuildwheel.readthedocs.io/en/stable/ +[4]: https://docs.python.org/3/library/multiprocessing.html +[5]: https://tqdm.github.io/ +[6]: https://docs.python.org/3/library/pickle.html +[7]: https://pypi.org/project/clp-ffi-py/ +[8]: https://github.com/RaRe-Technologies/smart_open +[9]: https://taskfile.dev/installation/ +[10]: https://docs.yscope.com/clp-ffi-py/main/api/clp_ffi_py.html [badge_build_status]: https://github.com/y-scope/clp-ffi-py/workflows/Build/badge.svg [badge_monthly_downloads]: https://static.pepy.tech/badge/clp-ffi-py/month diff --git a/Taskfile.yml b/Taskfile.yml index a3ed1280..f246644c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,23 +1,47 @@ version: "3" includes: - docs: - taskfile: "docs/tasks.yml" + docs: "docs/tasks.yml" + lint: "lint-tasks.yml" + utils: "tools/yscope-dev-utils/taskfiles/utils.yml" vars: # Paths BUILD_DIR: "{{.ROOT_DIR}}/build" + CLP_FFI_PY_CMAKE_BUILD_DIR: "{{.BUILD_DIR}}/cmake_build" + CLP_FFI_PY_CMAKE_CACHE: "{{.CLP_FFI_PY_CMAKE_BUILD_DIR}}/CMakeCache.txt" + CLP_FFI_PY_COMPILE_COMMANDS_DB: "{{.CLP_FFI_PY_CMAKE_BUILD_DIR}}/compile_commands.json" + CLP_FFI_PY_CPP_SRC_DIR: "{{.ROOT_DIR}}/src/clp_ffi_py" WHEEL_BUILD_DIR: "{{.BUILD_DIR}}/dist" WHEEL_VENV_DIR: "{{.BUILD_DIR}}/wheel-venv" tasks: default: - deps: ["wheel"] + deps: ["init", "wheel"] clean: cmds: - "rm -rf '{{.BUILD_DIR}}'" + config-cmake-project: + internal: true + deps: + - "init" + - "submodules" + sources: + - "{{.TASKFILE}}" + - "CMakeLists.txt" + generates: + - "{{.CLP_FFI_PY_CMAKE_CACHE}}" + - "{{.CLP_FFI_PY_COMPILE_COMMANDS_DB}}" + cmd: "cmake -S '{{.ROOT_DIR}}' -B '{{.CLP_FFI_PY_CMAKE_BUILD_DIR}}'" + + init: + internal: true + silent: true + run: "once" + cmds: ["mkdir -p '{{.BUILD_DIR}}'"] + wheel: vars: CHECKSUM_FILE: "{{.BUILD_DIR}}/{{.TASK}}.md5" diff --git a/docs/tasks.yml b/docs/tasks.yml index 4847a41d..d692e413 100644 --- a/docs/tasks.yml +++ b/docs/tasks.yml @@ -8,12 +8,12 @@ vars: # Other variables PYTHON_VERSION: - sh: python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" + sh: "python3 -c \"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')\"" tasks: api-docs: dir: "{{.TASKFILE_DIR}}" - deps: [ "docs-venv" ] + deps: ["docs-venv"] cmds: - |- . "{{.DOCS_VENV_DIR}}/bin/activate" diff --git a/lint-tasks.yml b/lint-tasks.yml new file mode 100644 index 00000000..6c004666 --- /dev/null +++ b/lint-tasks.yml @@ -0,0 +1,202 @@ +version: "3" + +vars: + G_LINT_VENV_DIR: "{{.BUILD_DIR}}/lint-venv" + G_LINT_VENV_CHECKSUM_FILE: "{{.BUILD_DIR}}/lint#venv.md5" + # Linter target dirs + G_CPP_LINT_DIRS: ["{{.CLP_FFI_PY_CPP_SRC_DIR}}"] + G_PYTHON_LINT_DIRS: ["{{.ROOT_DIR}}/clp_ffi_py", "{{.ROOT_DIR}}/tests"] + +tasks: + check: + cmds: + - task: "cmake-check" + - task: "cpp-check" + - task: "py-check" + - task: "yml-check" + + fix: + cmds: + - task: "cmake-fix" + - task: "cpp-fix" + - task: "py-fix" + - task: "yml-fix" + + cmake-check: + deps: ["venv"] + cmds: + - task: "cmake" + vars: + FLAGS: "--check" + + cmake-fix: + deps: ["venv"] + cmds: + - task: "cmake" + vars: + FLAGS: "--in-place" + + cpp-configs: + # TODO: remove this once all clang-tidy has been fixed + deps: [":config-cmake-project"] + cmds: + - "tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh" + + cpp-check: + cmds: + - task: "cpp-format-check" + # TODO: re-enable this once all clang-tidy has been fixed + # - task: "cpp-static-check" + + cpp-fix: + cmds: + - task: "cpp-format-fix" + # TODO: re-enable this once all clang-tidy has been fixed + # - task: "cpp-static-fix" + + cpp-format-check: + sources: &cpp_format_src_files + - "{{.G_LINT_VENV_CHECKSUM_FILE}}" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.cpp" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.h" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.hpp" + - "src/clp_ffi_py/.clang-format" + - "{{.TASKFILE}}" + - ".clang-format" + deps: ["cpp-configs", "venv"] + cmds: + - task: ":utils:clang-format" + vars: + FLAGS: "--dry-run" + SRC_PATHS: + ref: ".G_CPP_LINT_DIRS" + VENV_DIR: "{{.G_LINT_VENV_DIR}}" + + cpp-format-fix: + sources: *cpp_format_src_files + deps: ["cpp-configs", "venv"] + cmds: + - task: ":utils:clang-format" + vars: + FLAGS: "-i" + SRC_PATHS: + ref: ".G_CPP_LINT_DIRS" + VENV_DIR: "{{.G_LINT_VENV_DIR}}" + + cpp-static-check: + # Alias task to `cpp-static-fix` since we don't currently support automatic fixes. + # NOTE: clang-tidy does have the ability to fix some errors, but the fixes can be inaccurate. + # When we eventually determine which errors can be safely fixed, we'll allow clang-tidy to + # fix them. + aliases: ["cpp-static-fix"] + sources: + - "{{.G_LINT_VENV_CHECKSUM_FILE}}" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.cpp" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.h" + - "{{.CLP_FFI_PY_CPP_SRC_DIR}}/**/*.hpp" + - "{{.CLP_FFI_PY_CMAKE_CACHE}}" + - "{{.CLP_FFI_PY_COMPILE_COMMANDS_DB}}" + - "{{.TASKFILE}}" + - "Taskfile.yml" + - ".clang-tidy" + deps: [":config-cmake-project", "cpp-configs", "venv"] + cmds: + - task: ":utils:clang-tidy" + vars: + FLAGS: "--config-file={{.ROOT_DIR}}/.clang-tidy -p {{.CLP_FFI_PY_COMPILE_COMMANDS_DB}}" + SRC_PATHS: + ref: ".G_CPP_LINT_DIRS" + VENV_DIR: "{{.G_LINT_VENV_DIR}}" + + py-check: + cmds: + - task: "py" + vars: + DOCFORMATTER_FLAGS: "--check --diff" + BLACK_FLAGS: "--check --diff" + RUFF_FLAGS: "--output-format=github" + SRC_DIRS: + ref: ".G_PYTHON_LINT_DIRS" + + py-fix: + cmds: + - task: "py" + vars: + DOCFORMATTER_FLAGS: "-i" + BLACK_FLAGS: "" + RUFF_FLAGS: "--fix" + SRC_DIRS: + ref: ".G_PYTHON_LINT_DIRS" + + yml: + aliases: + - "yml-check" + - "yml-fix" + deps: ["venv"] + cmds: + - |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + yamllint \ + --config-file "tools/yscope-dev-utils/lint-configs/.yamllint.yml" \ + --strict \ + .gersemirc \ + .github \ + docs/tasks.yml \ + lint-tasks.yml \ + src/clp_ffi_py/.clang-format \ + Taskfile.yml + + cmake: + internal: true + requires: + vars: ["FLAGS"] + cmd: |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + gersemi {{.FLAGS}} CMakeLists.txt {{.CLP_FFI_PY_CPP_SRC_DIR}} + + py: + internal: true + requires: + vars: ["DOCFORMATTER_FLAGS", "BLACK_FLAGS", "RUFF_FLAGS", "SRC_DIRS"] + deps: ["venv"] + dir: "{{.ROOT_DIR}}" + cmds: + - for: + var: "SRC_DIRS" + cmd: |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + mypy {{.ITEM}} + docformatter {{.DOCFORMATTER_FLAGS}} --recursive {{.ITEM}} + black --color --line-length 100 {{.BLACK_FLAGS}} {{.ITEM}} + ruff check {{.RUFF_FLAGS}} {{.ITEM}} + + venv: + internal: true + vars: + CHECKSUM_FILE: "{{.G_LINT_VENV_CHECKSUM_FILE}}" + OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}" + sources: + - "{{.ROOT_DIR}}/Taskfile.yml" + - "{{.TASKFILE}}" + - "requirements-dev.txt" + generates: ["{{.CHECKSUM_FILE}}"] + deps: + - ":init" + - task: ":utils:validate-checksum" + vars: + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + DATA_DIR: "{{.OUTPUT_DIR}}" + cmds: + - task: ":utils:create-venv" + vars: + LABEL: "lint" + OUTPUT_DIR: "{{.OUTPUT_DIR}}" + # TODO: Separate the current requirements-dev.txt into linter & dev requirements. + # Let linter venv install both linter and dev requirements, and let build_wheel install + # only dev requirements. + REQUIREMENTS_FILE: "requirements-dev.txt" + # This command must be last + - task: ":utils:compute-checksum" + vars: + DATA_DIR: "{{.OUTPUT_DIR}}" + OUTPUT_FILE: "{{.CHECKSUM_FILE}}" diff --git a/requirements-dev.txt b/requirements-dev.txt index 3066434a..70faa1b0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,6 +3,7 @@ build>=0.8.0 cibuildwheel>=2.16.2 # Lock to v18.x until we can upgrade our code to meet v19's formatting standards. clang-format~=18.1 +clang-tidy>=19.1.0 docformatter>=1.7.5 gersemi>=0.16.2 # Lock to v0.3.0 to support Python3.7 @@ -14,4 +15,5 @@ ruff>=0.4.6 smart_open==6.4.0 types-Deprecated>=1.2.9 types-python-dateutil>=2.8 +yamllint>=1.35.1 zstandard>=0.18.0 diff --git a/src/clp_ffi_py/.clang-format b/src/clp_ffi_py/.clang-format new file mode 100644 index 00000000..20b6c95c --- /dev/null +++ b/src/clp_ffi_py/.clang-format @@ -0,0 +1,20 @@ +BasedOnStyle: "InheritParentConfig" + +IndentExternBlock: "NoIndent" +IncludeCategories: + # NOTE: A header is grouped by first matching regex + # Python header must be included before any others + - Regex: "^$" + Priority: -1 + # Project headers + - Regex: "^$" + Priority: 1 + # C++ standard libraries + - Regex: "^<.*>$" + Priority: 2 diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils new file mode 160000 index 00000000..ad576e43 --- /dev/null +++ b/tools/yscope-dev-utils @@ -0,0 +1 @@ +Subproject commit ad576e43c1a43d7a6afde79fc9c3c952b7bf28bd