diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..d2253c76f4 --- /dev/null +++ b/.flake8 @@ -0,0 +1,24 @@ +# Copyright (c) 2022-2023, NVIDIA CORPORATION. + +[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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85d4537130..7606914589 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: rev: 5.0.4 hooks: - id: flake8 - args: ["--config=setup.cfg"] + args: ["--config=.flake8"] files: python/.*$ types: [file] types_or: [python, cython] @@ -31,7 +31,7 @@ repos: hooks: - id: mypy additional_dependencies: [types-cachetools] - args: ["--config-file=setup.cfg", + args: ["--config-file=pyproject.toml", "python/pylibraft/pylibraft", "python/raft-dask/raft_dask"] pass_filenames: false @@ -39,7 +39,9 @@ repos: rev: 6.1.1 hooks: - id: pydocstyle - args: ["--config=setup.cfg"] + # https://github.com/PyCQA/pydocstyle/issues/603 + additional_dependencies: [toml] + args: ["--config=pyproject.toml"] - repo: https://github.com/pre-commit/mirrors-clang-format rev: v11.1.0 hooks: @@ -92,9 +94,11 @@ repos: language: python additional_dependencies: [gitpython] - repo: https://github.com/codespell-project/codespell - rev: v2.1.0 + rev: v2.2.2 hooks: - id: codespell + additional_dependencies: [tomli] + args: ["--toml", "pyproject.toml"] exclude: (?x)^(^CHANGELOG.md$) - repo: https://github.com/rapidsai/dependency-file-generator rev: v1.4.0 diff --git a/cpp/include/raft/matrix/detail/linewise_op.cuh b/cpp/include/raft/matrix/detail/linewise_op.cuh index ef8f0e88c1..514d0dc51b 100644 --- a/cpp/include/raft/matrix/detail/linewise_op.cuh +++ b/cpp/include/raft/matrix/detail/linewise_op.cuh @@ -201,7 +201,7 @@ struct Linewise { } /** - * @brief Same as loadVec, but padds data with Ones + * @brief Same as loadVec, but pads data with Ones * * @tparam VecT Type of the vector to load * @param shm diff --git a/cpp/include/raft/neighbors/ivf_pq_serialize.cuh b/cpp/include/raft/neighbors/ivf_pq_serialize.cuh index 9a719c69d4..98b59fd5e1 100644 --- a/cpp/include/raft/neighbors/ivf_pq_serialize.cuh +++ b/cpp/include/raft/neighbors/ivf_pq_serialize.cuh @@ -38,7 +38,7 @@ namespace raft::neighbors::ivf_pq { * // create an output stream * std::ostream os(std::cout.rdbuf()); * // create an index with `auto index = ivf_pq::build(...);` - * raft::serailize(handle, os, index); + * raft::serialize(handle, os, index); * @endcode * * @tparam IdxT type of the index @@ -68,7 +68,7 @@ void serialize(raft::device_resources const& handle, std::ostream& os, const ind * // create a string with a filepath * std::string filename("/path/to/index"); * // create an index with `auto index = ivf_pq::build(...);` - * raft::serailize(handle, filename, index); + * raft::serialize(handle, filename, index); * @endcode * * @tparam IdxT type of the index diff --git a/cpp/include/raft/random/detail/multi_variable_gaussian.cuh b/cpp/include/raft/random/detail/multi_variable_gaussian.cuh index 8b77608e62..16f50446ae 100644 --- a/cpp/include/raft/random/detail/multi_variable_gaussian.cuh +++ b/cpp/include/raft/random/detail/multi_variable_gaussian.cuh @@ -32,7 +32,7 @@ #include #include -// mvg.cuh takes in matrices that are colomn major (as in fortran) +// mvg.cuh takes in matrices that are column major (as in fortran) #define IDX2C(i, j, ld) (j * ld + i) namespace raft::random { diff --git a/cpp/scripts/gitutils.py b/cpp/scripts/gitutils.py index f6d6b97413..a7337ed4df 100644 --- a/cpp/scripts/gitutils.py +++ b/cpp/scripts/gitutils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ def repo_version_major_minor(): def determine_merge_commit(current_branch="HEAD"): """ When running outside of CI, this will estimate the target merge commit hash - of `current_branch` by finding a common ancester with the remote branch + of `current_branch` by finding a common ancestor with the remote branch 'branch-{major}.{minor}' where {major} and {minor} are determined from the repo version. diff --git a/cpp/test/util/bitonic_sort.cu b/cpp/test/util/bitonic_sort.cu index 2eb7e6da8b..2cf5420334 100644 --- a/cpp/test/util/bitonic_sort.cu +++ b/cpp/test/util/bitonic_sort.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ __global__ void bitonic_kernel(T* arr, bool ascending, int warp_width, int n_inp const int subwarp_id = tid / warp_width; const int subwarp_lane = tid % warp_width; T local_arr[Capacity]; // NOLINT - // Split the data into chunks of size `warp_width * Capacity`, each thread poiting + // Split the data into chunks of size `warp_width * Capacity`, each thread pointing // to the beginning of its stride within the chunk. T* per_thread_arr = arr + subwarp_id * warp_width * Capacity + subwarp_lane; diff --git a/pyproject.toml b/pyproject.toml index dfd22f3378..f8b09bed89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,3 +17,31 @@ force-exclude = ''' dist )/ ''' + +[tool.pydocstyle] +# Due to https://github.com/PyCQA/pydocstyle/issues/363, we must exclude rather +# than include using match-dir. Note that as discussed in +# https://stackoverflow.com/questions/65478393/how-to-filter-directories-using-the-match-dir-flag-for-pydocstyle, +# unlike the match option above this match-dir will have no effect when +# pydocstyle is invoked from pre-commit. Therefore this exclusion list must +# also be maintained in the pre-commit config file. +match-dir = "^(?!(ci|cpp|conda|docs)).*$" +select = "D201, D204, D206, D207, D208, D209, D210, D211, D214, D215, D300, D301, D302, D403, D405, D406, D407, D408, D409, D410, D411, D412, D414, D418" + # Would like to enable the following rules in the future: + # D200, D202, D205, D400 + +[tool.mypy] +ignore_missing_imports = true +# If we don't specify this, then mypy will check excluded files if +# they are imported by a checked file. +follow_imports = "skip" + +[tool.codespell] +# note: pre-commit passes explicit lists of files here, which this skip file list doesn't override - +# this is only to allow you to run codespell interactively +skip = "./.git,./.github,./cpp/build,.*egg-info.*,./.mypy_cache,.*_skbuild" +# ignore short words, and typename parameters like OffsetT +ignore-regex = "\\b(.{1,4}|[A-Z]\\w*T)\\b" +ignore-words-list = "inout,numer" +builtin = "clear" +quiet-level = 3 diff --git a/python/pylibraft/.flake8 b/python/pylibraft/.flake8 deleted file mode 100644 index ef2e5a8495..0000000000 --- a/python/pylibraft/.flake8 +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. - -[flake8] -exclude = __init__.py -ignore = - # line break before binary operator - W503 - # whitespace before : - E203 \ No newline at end of file diff --git a/python/pylibraft/.flake8.cython b/python/pylibraft/.flake8.cython deleted file mode 100644 index 3cd436d3f3..0000000000 --- a/python/pylibraft/.flake8.cython +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (c) 2022, 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, W503, W504 - -# Rules ignored: -# E999: invalid syntax (works for Python, not Cython) -# 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) -# 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/pylibraft/pyproject.toml b/python/pylibraft/pyproject.toml index 0dd6e54b84..c8cf252d0a 100644 --- a/python/pylibraft/pyproject.toml +++ b/python/pylibraft/pyproject.toml @@ -25,3 +25,46 @@ requires = [ "rmm==23.4.*", ] build-backend = "setuptools.build_meta" + +[tool.isort] +line_length = 79 +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +combine_as_imports = true +order_by_type = true +known_dask = [ + "dask", + "distributed", + "dask_cuda", +] +known_rapids = [ + "rmm", +] +known_first_party = [ + "pylibraft", +] +default_section = "THIRDPARTY" +sections = [ + "FUTURE", + "STDLIB", + "THIRDPARTY", + "DASK", + "RAPIDS", + "FIRSTPARTY", + "LOCALFOLDER", +] +skip = [ + "thirdparty", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".tox", + ".venv", + "_build", + "buck-out", + "build", + "dist", + "__init__.py", +] diff --git a/python/pylibraft/setup.cfg b/python/pylibraft/setup.cfg deleted file mode 100644 index 7d1a0c9065..0000000000 --- a/python/pylibraft/setup.cfg +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. - -[isort] -line_length=79 -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -combine_as_imports=True -order_by_type=True -known_dask= - dask - distributed - dask_cuda -known_rapids= - nvtext - cudf - cuml - cugraph - dask_cudf - rmm -known_first_party= - raft - pylibraft -default_section=THIRDPARTY -sections=FUTURE,STDLIB,THIRDPARTY,DASK,RAPIDS,FIRSTPARTY,LOCALFOLDER -skip= - thirdparty - .eggs - .git - .hg - .mypy_cache - .tox - .venv - _build - buck-out - build - dist - __init__.py diff --git a/python/raft-dask/pyproject.toml b/python/raft-dask/pyproject.toml index 0261c0b09d..947a0677ed 100644 --- a/python/raft-dask/pyproject.toml +++ b/python/raft-dask/pyproject.toml @@ -22,3 +22,47 @@ requires = [ "cmake>=3.23.1,!=3.25.0", "ninja", ] + +[tool.isort] +line_length = 79 +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +combine_as_imports = true +order_by_type = true +known_dask = [ + "dask", + "distributed", + "dask_cuda", +] +known_rapids = [ + "pylibraft", + "rmm", +] +known_first_party = [ + "raft_dask", +] +default_section = "THIRDPARTY" +sections = [ + "FUTURE", + "STDLIB", + "THIRDPARTY", + "DASK", + "RAPIDS", + "FIRSTPARTY", + "LOCALFOLDER", +] +skip = [ + "thirdparty", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".tox", + ".venv", + "_build", + "buck-out", + "build", + "dist", + "__init__.py", +] diff --git a/python/raft-dask/raft_dask/common/comms.py b/python/raft-dask/raft_dask/common/comms.py index 0a7fb02da7..56e40b98da 100644 --- a/python/raft-dask/raft_dask/common/comms.py +++ b/python/raft-dask/raft_dask/common/comms.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ import warnings from collections import OrderedDict -from pylibraft.common.handle import Handle - from dask.distributed import default_client, get_worker +from pylibraft.common.handle import Handle + from .comms_utils import ( inject_comms_on_handle, inject_comms_on_handle_coll_only, diff --git a/python/raft-dask/setup.cfg b/python/raft-dask/setup.cfg index b4179896a4..41e4ad8574 100644 --- a/python/raft-dask/setup.cfg +++ b/python/raft-dask/setup.cfg @@ -1,41 +1,5 @@ # Copyright (c) 2020-2023, NVIDIA CORPORATION. -[isort] -line_length=79 -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -combine_as_imports=True -order_by_type=True -known_dask= - dask - distributed - dask_cuda -known_rapids= - nvtext - cudf - cuml - cugraph - dask_cudf - rmm -known_first_party= - raft_dask -default_section=THIRDPARTY -sections=FUTURE,STDLIB,THIRDPARTY,DASK,RAPIDS,FIRSTPARTY,LOCALFOLDER -skip= - thirdparty - .eggs - .git - .hg - .mypy_cache - .tox - .venv - _build - buck-out - build - dist - __init__.py - [options] packages = find: python_requires = >=3.8,<3.11 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e64641d05b..0000000000 --- a/setup.cfg +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. - -[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 - -[pydocstyle] -# Due to https://github.com/PyCQA/pydocstyle/issues/363, we must exclude rather -# than include using match-dir. Note that as discussed in -# https://stackoverflow.com/questions/65478393/how-to-filter-directories-using-the-match-dir-flag-for-pydocstyle, -# unlike the match option above this match-dir will have no effect when -# pydocstyle is invoked from pre-commit. Therefore this exclusion list must -# also be maintained in the pre-commit config file. -match-dir = ^(?!(ci|cpp|conda|docs|java|notebooks)).*$ -# Allow missing docstrings for docutils -ignore-decorators = .*(docutils|doc_apply|copy_docstring).* -select = - D201, D204, D206, D207, D208, D209, D210, D211, D214, D215, D300, D301, D302, D403, D405, D406, D407, D408, D409, D410, D411, D412, D414, D418 - # Would like to enable the following rules in the future: - # D200, D202, D205, D400 - -[mypy] -ignore_missing_imports = True -# If we don't specify this, then mypy will check excluded files if -# they are imported by a checked file. -follow_imports = skip - -[codespell] -# note: pre-commit passes explicit lists of files here, which this skip file list doesn't override - -# this is only to allow you to run codespell interactively -skip = ./.git,./.github,./cpp/build,.*egg-info.*,./.mypy_cache,.*_skbuild -# ignore short words, and typename parameters like OffsetT -ignore-regex = \b(.{1,4}|[A-Z]\w*T)\b -ignore-words-list = inout,unparseable,numer -builtin = clear -quiet-level = 3