diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f8385092..9349f45cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ # Copyright (c) 2022-2024, NVIDIA CORPORATION. ci: - autofix_commit_msg: "[pre-commit.ci] auto code formatting" - autofix_prs: false - autoupdate_branch: "" - autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate" - autoupdate_schedule: quarterly - skip: ["verify-alpha-spec"] - submodules: false + autofix_commit_msg: "[pre-commit.ci] auto code formatting" + autofix_prs: false + autoupdate_branch: "" + autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate" + autoupdate_schedule: quarterly + skip: ["verify-alpha-spec"] + submodules: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -14,18 +14,12 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: ["--settings-path=python/rmm/pyproject.toml"] - files: python/.* - types_or: [python, cython, pyi] - - repo: https://github.com/ambv/black - rev: 24.10.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.2 hooks: - - id: black - args: ["--config=python/rmm/pyproject.toml"] + - id: ruff + args: ["--fix"] + - id: ruff-format - repo: https://github.com/MarcoGorelli/cython-lint rev: v0.16.6 hooks: @@ -80,11 +74,6 @@ repos: language: system pass_filenames: false verbose: true - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.2 - hooks: - - id: ruff - files: python/.*$ - repo: https://github.com/rapidsai/pre-commit-hooks rev: v0.4.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 929d5e563..b99bf800c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,14 +11,98 @@ builtin = "clear" quiet-level = 3 [tool.ruff] -select = ["E", "F", "W"] +line-length = 79 +target-version = "py310" + +[tool.ruff.lint] +select = [ + # pycodestyle Error + "E", + # Pyflakes + "F", + # pycodestyle Warning + "W", + # isort + "I", + # no-blank-line-before-function + "D201", + # one-blank-line-after-class + "D204", + # indent-with-spaces + "D206", + # under-indentation + "D207", + # over-indentation + "D208", + # new-line-after-last-paragraph + "D209", + # surrounding-whitespace + "D210", + # blank-line-before-class + "D211", + # section-not-over-indented + "D214", + # section-underline-not-over-indented + "D215", + # triple-single-quotes + "D300", + # escape-sequence-in-docstring + "D301", + # first-line-capitalized + "D403", + # capitalize-section-name + "D405", + # new-line-after-section-name + "D406", + # dashed-underline-after-section + "D407", + # section-underline-after-name + "D408", + # section-underline-matches-section-length + "D409", + # no-blank-line-after-section + "D410", + # no-blank-line-before-section + "D411", + # blank-lines-between-header-and-content + "D412", + # empty-docstring-section + "D414", + # overload-with-docstring + "D418", + # flake8-type-checking + "TCH", + # flake8-future-annotations + "FA", + # non-pep585-annotation + "UP006", + # non-pep604-annotation + "UP007", + # Import from `collections.abc` instead: `Callable` + "UP035", + # usage of legacy `np.random` function calls + "NPY002", + # Ruff-specific rules + "RUF", +] ignore = [ # whitespace before : "E203", + # line-too-long (due to Copyright header) + "E501", + # type-comparison, disabled because we compare types to numpy dtypes + "E721", + # String contains ambiguous character + "RUF001", + # Parenthesize `a and b` expressions when chaining `and` and `or` + # together, to make the precedence clear + "RUF021", + # Mutable class attributes should be annotated with + # `typing.ClassVar` + "RUF012", ] fixable = ["ALL"] exclude = [ # TODO: Remove this in a follow-up where we fix __all__. "__init__.py", ] -line-length = 79 diff --git a/python/rmm/pyproject.toml b/python/rmm/pyproject.toml index a235130e1..e2dbb9711 100644 --- a/python/rmm/pyproject.toml +++ b/python/rmm/pyproject.toml @@ -54,59 +54,6 @@ test = [ [project.urls] Homepage = "https://github.com/rapidsai/rmm" -[tool.black] -line-length = 79 -target-version = ["py310"] -include = '\.py?$' -exclude = ''' -/( - thirdparty | - \.eggs | - \.git | - \.hg | - \.mypy_cache | - \.tox | - \.venv | - _build | - buck-out | - build | - dist -)/ -''' - -[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_first_party = [ - "rmm", -] -default_section = "THIRDPARTY" -sections = [ - "FUTURE", - "STDLIB", - "THIRDPARTY", - "FIRSTPARTY", - "LOCALFOLDER", -] -skip = [ - "thirdparty", - ".eggs", - ".git", - ".hg", - ".mypy_cache", - ".tox", - ".venv", - "_build", - "buck-out", - "build", - "dist", - "__init__.py", -] - [tool.scikit-build] build-dir = "build/{wheel_tag}" cmake.build-type = "Release" @@ -148,3 +95,14 @@ filterwarnings = [ "error", "ignore:.*cuda..* module is deprecated.*:DeprecationWarning" ] + +[tool.ruff] +extend = "../../pyproject.toml" + +[tool.ruff.lint.isort] +combine-as-imports = true +known-first-party = ["rmm"] +section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"] + +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["E402", "F401"] diff --git a/python/rmm/rmm/_cuda/gpu.py b/python/rmm/rmm/_cuda/gpu.py index 8ed7abc93..75f9fa0f9 100644 --- a/python/rmm/rmm/_cuda/gpu.py +++ b/python/rmm/rmm/_cuda/gpu.py @@ -62,6 +62,7 @@ def getDevice(): def setDevice(device: int): """ Set the current CUDA device + Parameters ---------- device : int diff --git a/python/rmm/rmm/mr.py b/python/rmm/rmm/mr.py index 82729271f..673ffde82 100644 --- a/python/rmm/rmm/mr.py +++ b/python/rmm/rmm/mr.py @@ -52,6 +52,7 @@ "CudaAsyncMemoryResource", "CudaMemoryResource", "DeviceMemoryResource", + "FailureCallbackResourceAdaptor", "FixedSizeMemoryResource", "LimitingResourceAdaptor", "LoggingResourceAdaptor", @@ -62,19 +63,18 @@ "StatisticsResourceAdaptor", "SystemMemoryResource", "TrackingResourceAdaptor", - "FailureCallbackResourceAdaptor", "UpstreamResourceAdaptor", "_flush_logs", "_initialize", "available_device_memory", - "set_per_device_resource", - "enable_logging", "disable_logging", - "get_per_device_resource", - "set_current_device_resource", + "enable_logging", "get_current_device_resource", - "get_per_device_resource_type", "get_current_device_resource_type", "get_log_filenames", + "get_per_device_resource", + "get_per_device_resource_type", "is_initialized", + "set_current_device_resource", + "set_per_device_resource", ] diff --git a/python/rmm/rmm/statistics.py b/python/rmm/rmm/statistics.py index 2dabedce6..f7908c3f1 100644 --- a/python/rmm/rmm/statistics.py +++ b/python/rmm/rmm/statistics.py @@ -18,7 +18,7 @@ from contextlib import contextmanager from dataclasses import dataclass from functools import wraps -from typing import Dict, Literal, Optional +from typing import Literal import rmm.mr @@ -71,7 +71,7 @@ def enable_statistics() -> None: ) -def get_statistics() -> Optional[Statistics]: +def get_statistics() -> Statistics | None: """Get the current allocation statistics. Returns @@ -85,7 +85,7 @@ def get_statistics() -> Optional[Statistics]: return None -def push_statistics() -> Optional[Statistics]: +def push_statistics() -> Statistics | None: """Push new counters on the current allocation statistics stack. This returns the current tracked statistics and pushes a new set @@ -105,7 +105,7 @@ def push_statistics() -> Optional[Statistics]: return None -def pop_statistics() -> Optional[Statistics]: +def pop_statistics() -> Statistics | None: """Pop the counters of the current allocation statistics stack. This returns the counters of current tracked statistics and pops @@ -193,7 +193,7 @@ def add(self, memory_total: int, memory_peak: int): def __init__(self) -> None: self._lock = threading.Lock() - self._records: Dict[str, ProfilerRecords.MemoryRecord] = defaultdict( + self._records: dict[str, ProfilerRecords.MemoryRecord] = defaultdict( ProfilerRecords.MemoryRecord ) @@ -215,7 +215,7 @@ def add(self, name: str, data: Statistics) -> None: ) @property - def records(self) -> Dict[str, MemoryRecord]: + def records(self) -> dict[str, MemoryRecord]: """Dictionary mapping record names to their memory statistics.""" return dict(self._records)