diff --git a/.clang-format b/.clang-format index 6019a6f3d..26b9a5bf4 100644 --- a/.clang-format +++ b/.clang-format @@ -15,7 +15,7 @@ AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: true +AllowShortBlocksOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: All @@ -27,7 +27,7 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: false +BinPackArguments: false BinPackParameters: false BraceWrapping: AfterClass: false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..723c5b8b1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +python/rmm/_version.py export-subst diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 44656683c..3c02b406c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -11,7 +11,7 @@ python/ @rapidsai/rmm-python-codeowners **/cmake/ @rapidsai/rmm-cmake-codeowners #build/ops code owners -.github/ @rapidsai/ops-codeowners +.github/ @rapidsai/ops-codeowners ci/ @rapidsai/ops-codeowners conda/ @rapidsai/ops-codeowners **/Dockerfile @rapidsai/ops-codeowners diff --git a/.github/ISSUE_TEMPLATE/documentation-request.md b/.github/ISSUE_TEMPLATE/documentation-request.md index 29445495e..24215eceb 100644 --- a/.github/ISSUE_TEMPLATE/documentation-request.md +++ b/.github/ISSUE_TEMPLATE/documentation-request.md @@ -30,4 +30,3 @@ A clear and concise description of what documentation is needed and why. **Steps taken to search for needed documentation** List any steps you have taken. - diff --git a/.github/ops-bot.yaml b/.github/ops-bot.yaml index 6f542f418..57bdd6110 100644 --- a/.github/ops-bot.yaml +++ b/.github/ops-bot.yaml @@ -8,4 +8,3 @@ release_drafter: true copy_prs: true rerun_tests: true recently_updated: true - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 356c35db7..027ce9857 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,31 +1,49 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. repos: - - repo: https://github.com/pycqa/isort + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - repo: https://github.com/PyCQA/isort rev: 5.10.1 hooks: - id: isort - args: ["--settings-path=python/setup.cfg"] + args: ["--config-root=python/", "--resolve-all-configs"] files: python/.* - exclude: __init__.py$ - types: [text] - types_or: [python, cython] + types_or: [python, cython, pyi] - repo: https://github.com/ambv/black rev: 22.3.0 hooks: - id: black args: ["--config=python/pyproject.toml"] - repo: https://github.com/PyCQA/flake8 - rev: 3.8.3 + rev: 5.0.4 hooks: - id: flake8 - alias: flake8 - name: flake8 - args: ["--config=python/.flake8"] - types: [python] - - id: flake8 - alias: flake8-cython - name: flake8-cython - args: ["--config=python/.flake8.cython"] - types: [cython] + args: ["--config=python/setup.cfg"] + files: python/.*$ + types: [file] + types_or: [python, cython] + additional_dependencies: ["flake8-force"] + - repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.1.10 + hooks: + - id: cython-lint + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v11.1.0 + hooks: + - id: clang-format + types_or: [c, c++, cuda] + args: ["-fallback-style=none", "-style=file", "-i"] + - repo: https://github.com/sirosen/texthooks + rev: 0.4.0 + hooks: + - id: fix-smartquotes + exclude: | + (?x)^( + ^benchmarks/utilities/cxxopts.hpp + ) - repo: local hooks: - id: cmake-format diff --git a/ci/check_style.sh b/ci/check_style.sh index ef8565ded..66f961d41 100755 --- a/ci/check_style.sh +++ b/ci/check_style.sh @@ -14,126 +14,10 @@ rapids-dependency-file-generator \ rapids-mamba-retry env create --force -f env.yaml -n checks conda activate checks -set +e +FORMAT_FILE_URL=https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-23.02/cmake-format-rapids-cmake.json +export RAPIDS_CMAKE_FORMAT_FILE=/tmp/rapids_cmake_ci/cmake-formats-rapids-cmake.json +mkdir -p $(dirname ${RAPIDS_CMAKE_FORMAT_FILE}) +wget -O ${RAPIDS_CMAKE_FORMAT_FILE} ${FORMAT_FILE_URL} -# Run isort and get results/return code -ISORT=$(isort --check-only python --settings-path=python/setup.cfg) -ISORT_RETVAL=$? - -# Run black and get results/return code -BLACK=$(black --config python/pyproject.toml --check python) -BLACK_RETVAL=$? - -# Run flake8 and get results/return code -FLAKE=$(flake8 --config=python/.flake8 python) -FLAKE_RETVAL=$? - -# Run flake8-cython and get results/return code -FLAKE_CYTHON=$(flake8 --config=python/.flake8.cython) -FLAKE_CYTHON_RETVAL=$? - -# Run clang-format and check for a consistent code format -CLANG_FORMAT=$(python scripts/run-clang-format.py 2>&1) -CLANG_FORMAT_RETVAL=$? - -# Run cmake-format / cmake-lint and get results/return code -CMAKE_FILES=($(find . | grep -E "^.*\.cmake(\.in)?$|^.*/CMakeLists.txt$")) - -CMAKE_FORMATS=() -CMAKE_FORMAT_RETVAL=0 - -CMAKE_LINTS=() -CMAKE_LINT_RETVAL=0 - -CURRENT_TAG=$(git tag --merged HEAD | grep -xE '^v.*' | sort --version-sort | tail -n 1 | tr -d 'v') -CURRENT_MAJOR=$(echo "${CURRENT_TAG}" | awk '{split($0, a, "."); print a[1]}') -CURRENT_MINOR=$(echo "${CURRENT_TAG}" | awk '{split($0, a, "."); print a[2]}') -CURRENT_SHORT_TAG="${CURRENT_MAJOR}.${CURRENT_MINOR}" -rapids-retry curl -s "https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${CURRENT_SHORT_TAG}/cmake-format-rapids-cmake.json" -o cmake/rapids-cmake.json - -for cmake_file in "${CMAKE_FILES[@]}"; do - cmake-format --in-place --config-files cmake/config.json cmake/rapids-cmake.json -- "${cmake_file}" - TMP_CMAKE_FORMAT=$(git diff --color --exit-code -- "${cmake_file}") - TMP_CMAKE_FORMAT_RETVAL=$? - if [ "$TMP_CMAKE_FORMAT_RETVAL" != "0" ]; then - CMAKE_FORMAT_RETVAL=1 - CMAKE_FORMATS+=("$TMP_CMAKE_FORMAT") - fi - - TMP_CMAKE_LINT=$(cmake-lint --config-files cmake/config.json cmake/rapids-cmake.json -- "${cmake_file}") - TMP_CMAKE_LINT_RETVAL=$? - if [ "$TMP_CMAKE_LINT_RETVAL" != "0" ]; then - CMAKE_LINT_RETVAL=1 - CMAKE_LINTS+=("$TMP_CMAKE_LINT") - fi -done - - -# Output results if failure otherwise show pass -if [ "$ISORT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: isort style check; begin output\n\n" - echo -e "$ISORT" - echo -e "\n\n>>>> FAILED: isort style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: isort style check\n\n" -fi - -if [ "$BLACK_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: black style check; begin output\n\n" - echo -e "$BLACK" - echo -e "\n\n>>>> FAILED: black style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: black style check\n\n" -fi - -if [ "$FLAKE_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: flake8 style check; begin output\n\n" - echo -e "$FLAKE" - echo -e "\n\n>>>> FAILED: flake8 style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: flake8 style check\n\n" -fi - -if [ "$FLAKE_CYTHON_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: flake8-cython style check; begin output\n\n" - echo -e "$FLAKE_CYTHON" - echo -e "\n\n>>>> FAILED: flake8-cython style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: flake8-cython style check\n\n" -fi - -if [ "$CLANG_FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: clang format check; begin output\n\n" - echo -e "$CLANG_FORMAT" - echo -e "\n\n>>>> FAILED: clang format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: clang format check\n\n" -fi - -if [ "$CMAKE_FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: cmake format check; begin output\n\n" - for CMAKE_FORMAT in "${CMAKE_FORMATS[@]}"; do - echo -e "$CMAKE_FORMAT" - echo -e "\n" - done - echo -e "\n\n>>>> FAILED: cmake format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: cmake format check\n\n" -fi - -if [ "$CMAKE_LINT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: cmake lint check; begin output\n\n" - for CMAKE_LINT in "${CMAKE_LINTS[@]}"; do - echo -e "$CMAKE_LINT" - echo -e "\n" - done - echo -e "\n\n>>>> FAILED: cmake lint check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: cmake lint check\n\n" -fi - -RETVALS=($ISORT_RETVAL $BLACK_RETVAL $FLAKE_RETVAL $FLAKE_CYTHON_RETVAL $CLANG_FORMAT_RETVAL $CMAKE_FORMAT_RETVAL $CMAKE_LINT_RETVAL) -IFS=$'\n' -RETVAL=$(echo "${RETVALS[*]}" | sort -nr | head -n1) - -exit "${RETVAL}" +# Run pre-commit checks +pre-commit run --hook-stage manual --all-files --show-diff-on-failure diff --git a/ci/docs/build.sh b/ci/docs/build.sh index 972dc7391..eed509dc5 100644 --- a/ci/docs/build.sh +++ b/ci/docs/build.sh @@ -54,10 +54,9 @@ for PROJECT in ${PROJECTS[@]}; do if [ ! -d "api/$PROJECT/$BRANCH_VERSION" ]; then mkdir -p api/$PROJECT/$BRANCH_VERSION fi - rm -rf $DOCS_WORKSPACE/api/$PROJECT/$BRANCH_VERSION/* + rm -rf $DOCS_WORKSPACE/api/$PROJECT/$BRANCH_VERSION/* done mv $PROJECT_WORKSPACE/doxygen/html/* $DOCS_WORKSPACE/api/librmm/$BRANCH_VERSION mv $PROJECT_WORKSPACE/python/docs/_build/html/* $DOCS_WORKSPACE/api/rmm/$BRANCH_VERSION - diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index 01450d8bf..b8ee8d2c9 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -29,12 +29,20 @@ function sed_runner() { sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak } +# cpp update sed_runner 's/'" VERSION .*"'/'" VERSION ${NEXT_FULL_TAG}"'/g' CMakeLists.txt -sed_runner 's/'"rmm_version .*)"'/'"rmm_version ${NEXT_FULL_TAG})"'/g' python/CMakeLists.txt sed_runner 's/'"branch-.*\/RAPIDS.cmake"'/'"branch-${NEXT_SHORT_TAG}\/RAPIDS.cmake"'/g' CMakeLists.txt + +# Python update +sed_runner 's/'"rmm_version .*)"'/'"rmm_version ${NEXT_FULL_TAG})"'/g' python/CMakeLists.txt sed_runner 's/'"branch-.*\/RAPIDS.cmake"'/'"branch-${NEXT_SHORT_TAG}\/RAPIDS.cmake"'/g' python/CMakeLists.txt +# cmake-format rapids-cmake definitions +sed_runner 's/'"branch-.*\/cmake-format-rapids-cmake.json"'/'"branch-${NEXT_SHORT_TAG}\/cmake-format-rapids-cmake.json"'/g' ci/checks/style.sh + +# doxyfile update sed_runner 's/'"PROJECT_NUMBER = .*"'/'"PROJECT_NUMBER = ${NEXT_SHORT_TAG}"'/g' doxygen/Doxyfile +# sphinx docs update sed_runner 's/'"version =.*"'/'"version = \"${NEXT_SHORT_TAG}\""'/g' python/docs/conf.py sed_runner 's/'"release =.*"'/'"release = \"${NEXT_FULL_TAG}\""'/g' python/docs/conf.py diff --git a/cmake/config.json b/cmake/config.json index 6fb9d3fd7..59fc54be3 100644 --- a/cmake/config.json +++ b/cmake/config.json @@ -9,7 +9,7 @@ "VERSION": "?", "GIT_SHALLOW": "?", "OPTIONS": "*", - "FIND_PACKAGE_ARGUMENTS": "*" + "FIND_PACKAGE_ARGUMENTS": "*" } }, "ConfigureTest": { diff --git a/conda/environments/all_cuda-115_arch-x86_64.yaml b/conda/environments/all_cuda-115_arch-x86_64.yaml index 0f6da8e09..fd40328c3 100644 --- a/conda/environments/all_cuda-115_arch-x86_64.yaml +++ b/conda/environments/all_cuda-115_arch-x86_64.yaml @@ -4,20 +4,15 @@ channels: - rapidsai - conda-forge dependencies: -- black=22.3.0 -- clang-tools=11.1.0 -- clang=11.1.0 - cmake>=3.23.1,!=3.25.0 -- cmakelang=0.6.13 - cuda-python>=11.7.1,<12.0 - cudatoolkit=11.5 - cython>=0.29,<0.30 -- flake8=3.8.3 - gcovr>=5.0 -- isort=5.10.1 - ninja - numba>=0.49 - numpy>=1.19 +- pre-commit - pytest - pytest-cov - python>=3.8,<3.10 diff --git a/conda/environments/all_cuda-116_arch-x86_64.yaml b/conda/environments/all_cuda-116_arch-x86_64.yaml index 646565a90..3cec992a5 100644 --- a/conda/environments/all_cuda-116_arch-x86_64.yaml +++ b/conda/environments/all_cuda-116_arch-x86_64.yaml @@ -4,20 +4,15 @@ channels: - rapidsai - conda-forge dependencies: -- black=22.3.0 -- clang-tools=11.1.0 -- clang=11.1.0 - cmake>=3.23.1,!=3.25.0 -- cmakelang=0.6.13 - cuda-python>=11.7.1,<12.0 - cudatoolkit=11.6 - cython>=0.29,<0.30 -- flake8=3.8.3 - gcovr>=5.0 -- isort=5.10.1 - ninja - numba>=0.49 - numpy>=1.19 +- pre-commit - pytest - pytest-cov - python>=3.8,<3.10 diff --git a/dependencies.yaml b/dependencies.yaml index bd9b36122..1b16db27b 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -7,6 +7,7 @@ files: arch: [x86_64] includes: - build + - checks - cudatoolkit - develop - run @@ -24,8 +25,7 @@ files: checks: output: none includes: - - build - - develop + - checks - py_version channels: - rapidsai @@ -44,6 +44,11 @@ dependencies: - output_types: conda packages: - spdlog>=1.8.5,<1.9 + checks: + common: + - output_types: [conda, requirements] + packages: + - pre-commit cudatoolkit: specific: - output_types: conda @@ -68,15 +73,7 @@ dependencies: common: - output_types: [conda, requirements] packages: - - black=22.3.0 - - cmakelang=0.6.13 - - flake8=3.8.3 - gcovr>=5.0 - - isort=5.10.1 - - output_types: conda - packages: - - clang=11.1.0 - - clang-tools=11.1.0 py_version: specific: - output_types: conda diff --git a/print_env.sh b/print_env.sh index 28b3049cf..f67641ea2 100755 --- a/print_env.sh +++ b/print_env.sh @@ -1,38 +1,38 @@ #!/usr/bin/env bash # Reports relevant environment information useful for diagnosing and # debugging RMM issues. -# Usage: +# Usage: # "./print_env.sh" - prints to stdout # "./print_env.sh > env.txt" - prints to file "env.txt" echo "**git***" git log --decorate -n 1 -echo +echo echo "***OS Information***" cat /etc/*-release uname -a -echo +echo echo "***GPU Information***" nvidia-smi -echo +echo echo "***CPU***" lscpu echo echo "***CMake***" -which cmake && cmake --version -echo +which cmake && cmake --version +echo echo "***g++***" -which g++ && g++ --version -echo +which g++ && g++ --version +echo echo "***nvcc***" -which nvcc && nvcc --version -echo +which nvcc && nvcc --version +echo echo "***Python***" which python && python --version @@ -57,7 +57,7 @@ echo # Print conda packages if conda exists if type "conda" > /dev/null; then echo '***conda packages***' -which conda && conda list +which conda && conda list echo # Print pip packages if pip exists elif type "pip" > /dev/null; then diff --git a/python/.flake8 b/python/.flake8 deleted file mode 100644 index 1d251eec6..000000000 --- a/python/.flake8 +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2020, NVIDIA CORPORATION. - -[flake8] -exclude = __init__.py -ignore = - # line break before binary operator - W503 - # whitespace before : - E203 - diff --git a/python/.flake8.cython b/python/.flake8.cython deleted file mode 100644 index 2b614a924..000000000 --- a/python/.flake8.cython +++ /dev/null @@ -1,30 +0,0 @@ -# -# Copyright (c) 2018-2019, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -[flake8] -filename = *.pyx, *.pxd -exclude = *.egg, build, docs, .git -ignore = E999, E225, E226, E227, E402, W503, W504, E211 - -# Rules ignored: -# E999: invalid syntax (works for Python, not Cython) -# E211: whitespace before '(' (used in multi-line imports) -# E225: Missing whitespace around operators (breaks cython casting syntax like ) -# E226: Missing whitespace around arithmetic operators (breaks cython pointer syntax like int*) -# E227: Missing whitespace around bitwise or shift operator (Can also break casting syntax) -# E402: Module level import not at top of file (cimport is not recognized as import) -# W503: line break before binary operator (breaks lines that start with a pointer) -# W504: line break after binary operator (breaks lines that end with a pointer) diff --git a/python/rmm/_lib/cuda_stream.pyx b/python/rmm/_lib/cuda_stream.pyx index d93af2509..fb35ec11f 100644 --- a/python/rmm/_lib/cuda_stream.pyx +++ b/python/rmm/_lib/cuda_stream.pyx @@ -14,7 +14,6 @@ cimport cython from cuda.ccudart cimport cudaStream_t -from libc.stdint cimport uintptr_t from libcpp cimport bool diff --git a/python/rmm/_lib/device_buffer.pyx b/python/rmm/_lib/device_buffer.pyx index ce0009dbf..43ebf41ac 100644 --- a/python/rmm/_lib/device_buffer.pyx +++ b/python/rmm/_lib/device_buffer.pyx @@ -15,9 +15,8 @@ import numpy as np cimport cython from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_FromStringAndSize -from cython.operator cimport dereference from libc.stdint cimport uintptr_t -from libcpp.memory cimport make_unique, unique_ptr +from libcpp.memory cimport unique_ptr from libcpp.utility cimport move from rmm._cuda.stream cimport Stream @@ -31,7 +30,6 @@ from cuda.ccudart cimport ( cudaMemcpyAsync, cudaMemcpyKind, cudaStream_t, - cudaStreamSynchronize, ) from rmm._lib.memory_resource cimport get_current_device_resource diff --git a/python/rmm/_lib/memory_resource.pyx b/python/rmm/_lib/memory_resource.pyx index a20d481e0..867ea544e 100644 --- a/python/rmm/_lib/memory_resource.pyx +++ b/python/rmm/_lib/memory_resource.pyx @@ -19,20 +19,13 @@ from collections import defaultdict from cython.operator cimport dereference as deref from libc.stdint cimport int8_t, int64_t, uintptr_t from libcpp cimport bool -from libcpp.cast cimport dynamic_cast -from libcpp.memory cimport make_shared, make_unique, shared_ptr, unique_ptr +from libcpp.memory cimport make_unique, unique_ptr from libcpp.pair cimport pair from libcpp.string cimport string from cuda.cudart import cudaError_t -from rmm._cuda.gpu import ( - CUDARuntimeError, - driverGetVersion, - getDevice, - runtimeGetVersion, - setDevice, -) +from rmm._cuda.gpu import CUDARuntimeError, getDevice, setDevice from rmm._lib.cuda_stream_view cimport cuda_stream_view @@ -527,8 +520,6 @@ cdef class BinningMemoryResource(UpstreamResourceAdaptor): bin_resource : DeviceMemoryResource The resource to use for this bin (optional) """ - cdef DeviceMemoryResource _bin_resource - if bin_resource is None: (( self.c_obj.get()))[0].add_bin(allocation_size) diff --git a/python/rmm/_lib/tests/test_device_buffer.pyx b/python/rmm/_lib/tests/test_device_buffer.pyx index c4f5e5ae3..733383827 100644 --- a/python/rmm/_lib/tests/test_device_buffer.pyx +++ b/python/rmm/_lib/tests/test_device_buffer.pyx @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import cython import numpy as np from libcpp.memory cimport make_unique -from libcpp.utility cimport move from rmm._lib.cuda_stream_view cimport cuda_stream_default from rmm._lib.device_buffer cimport DeviceBuffer, device_buffer diff --git a/python/setup.cfg b/python/setup.cfg index 9e0227b94..7a1f5c819 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -13,6 +13,29 @@ versionfile_build = rmm/_version.py tag_prefix = v parentdir_prefix = rmm- +[flake8] +filename = *.py, *.pyx, *.pxd, *.pxi +exclude = __init__.py, *.egg, build, docs, .git +force-check = True +ignore = + # line break before binary operator + W503, + # whitespace before : + E203 +per-file-ignores = + # Rules ignored only in Cython: + # E211: whitespace before '(' (used in multi-line imports) + # E225: Missing whitespace around operators (breaks cython casting syntax like ) + # E226: Missing whitespace around arithmetic operators (breaks cython pointer syntax like int*) + # E227: Missing whitespace around bitwise or shift operator (Can also break casting syntax) + # E275: Missing whitespace after keyword (Doesn't work with Cython except?) + # E402: invalid syntax (works for Python, not Cython) + # E999: invalid syntax (works for Python, not Cython) + # W504: line break after binary operator (breaks lines that end with a pointer) + *.pyx: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxd: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxi: E211, E225, E226, E227, E275, E402, E999, W504 + [isort] line_length=79 multi_line_output=3 diff --git a/python/setup.py b/python/setup.py index 8ea0f3ab7..ee8fb9e5f 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,11 +2,10 @@ import os +import versioneer from setuptools import find_packages from skbuild import setup -import versioneer - if "RAPIDS_PY_WHEEL_VERSIONEER_OVERRIDE" in os.environ: orig_get_versions = versioneer.get_versions diff --git a/scripts/run-clang-format.py b/scripts/run-clang-format.py deleted file mode 100755 index 6c4370742..000000000 --- a/scripts/run-clang-format.py +++ /dev/null @@ -1,175 +0,0 @@ -# Copyright (c) 2019-2020, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from __future__ import print_function - -import argparse -import os -import re -import subprocess -import sys -import tempfile - -EXPECTED_VERSION = "11.1.0" -VERSION_REGEX = re.compile(r"clang-format version ([0-9.]+)") -# NOTE: populate this list with more top-level dirs as we add more of them -# to the rmm repo -DEFAULT_DIRS = ["src", "include", "tests", "benchmarks"] - - -def parse_args(): - argparser = argparse.ArgumentParser("Runs clang-format on a project") - argparser.add_argument( - "-dstdir", - type=str, - default=None, - help="Directory to store the temporary outputs of" - " clang-format. If nothing is passed for this, then" - " a temporary dir will be created using `mkdtemp`", - ) - argparser.add_argument( - "-exe", - type=str, - default="clang-format", - help="Path to clang-format exe", - ) - argparser.add_argument( - "-inplace", - default=False, - action="store_true", - help="Replace the source files itself.", - ) - argparser.add_argument( - "-regex", - type=str, - default=r"[.](cu|cuh|h|hpp|cpp)$", - help="Regex string to filter in sources", - ) - argparser.add_argument( - "-ignore", - type=str, - default=r"cannylab/bh[.]cu$", - help="Regex used to ignore files from matched list", - ) - argparser.add_argument( - "-v", - dest="verbose", - action="store_true", - help="Print verbose messages", - ) - argparser.add_argument( - "dirs", type=str, nargs="*", help="List of dirs where to find sources" - ) - args = argparser.parse_args() - args.regex_compiled = re.compile(args.regex) - args.ignore_compiled = re.compile(args.ignore) - if args.dstdir is None: - args.dstdir = tempfile.mkdtemp() - ret = subprocess.check_output("%s --version" % args.exe, shell=True) - ret = ret.decode("utf-8") - version = VERSION_REGEX.match(ret) - if version is None: - raise Exception("Failed to figure out clang-format version!") - version = version.group(1) - if version != EXPECTED_VERSION: - raise Exception( - "clang-format exe must be v%s found '%s'" - % (EXPECTED_VERSION, version) - ) - if len(args.dirs) == 0: - args.dirs = DEFAULT_DIRS - return args - - -def list_all_src_files(file_regex, ignore_regex, srcdirs, dstdir, inplace): - allFiles = [] - for srcdir in srcdirs: - for root, dirs, files in os.walk(srcdir): - for f in files: - if re.search(file_regex, f): - src = os.path.join(root, f) - if re.search(ignore_regex, src): - continue - if inplace: - _dir = root - else: - _dir = os.path.join(dstdir, root) - dst = os.path.join(_dir, f) - allFiles.append((src, dst)) - return allFiles - - -def run_clang_format(src, dst, exe, verbose): - dstdir = os.path.dirname(dst) - if not os.path.exists(dstdir): - os.makedirs(dstdir) - # run the clang format command itself - if src == dst: - cmd = "%s -i %s" % (exe, src) - else: - cmd = "%s %s > %s" % (exe, src, dst) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError: - print("Failed to run clang-format! Maybe your env is not proper?") - raise - # run the diff to check if there are any formatting issues - cmd = "diff -q %s %s >/dev/null" % (src, dst) - try: - subprocess.check_call(cmd, shell=True) - if verbose: - print("%s passed" % os.path.basename(src)) - except subprocess.CalledProcessError: - print( - "%s failed! 'diff %s %s' will show formatting violations!" - % (os.path.basename(src), src, dst) - ) - return False - return True - - -def main(): - args = parse_args() - # Attempt to making sure that we run this script from root of repo always - if not os.path.exists(".git"): - print("Error!! This needs to always be run from the root of repo") - sys.exit(-1) - all_files = list_all_src_files( - args.regex_compiled, - args.ignore_compiled, - args.dirs, - args.dstdir, - args.inplace, - ) - # actual format checker - status = True - for src, dst in all_files: - if not run_clang_format(src, dst, args.exe, args.verbose): - status = False - if not status: - print("clang-format failed! You have 2 options:") - print(" 1. Look at formatting differences above and fix them manually") - print(" 2. Or run the below command to bulk-fix all these at once") - print("Bulk-fix command: ") - print( - " python scripts/run-clang-format.py %s -inplace" - % " ".join(sys.argv[1:]) - ) - sys.exit(-1) - return - - -if __name__ == "__main__": - main() diff --git a/scripts/run-cmake-format.sh b/scripts/run-cmake-format.sh index 6175a9dc8..a7d9984b3 100755 --- a/scripts/run-cmake-format.sh +++ b/scripts/run-cmake-format.sh @@ -15,7 +15,7 @@ # and exits gracefully if the file is not found. If a user wishes to specify a # config file at a nonstandard location, they may do so by setting the # environment variable RAPIDS_CMAKE_FORMAT_FILE. -# +# # This script can be invoked directly anywhere within the project repository. # Alternatively, it may be invoked as a pre-commit hook via # `pre-commit run (cmake-format)|(cmake-lint)`.