Skip to content

Commit

Permalink
Use ruff, remove isort and black. (#1759)
Browse files Browse the repository at this point in the history
Closes #1758.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Matthew Murray (https://github.com/Matt711)
  - James Lamb (https://github.com/jameslamb)

URL: #1759
  • Loading branch information
bdice authored Dec 11, 2024
1 parent 73a66c9 commit 3cad8fe
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 90 deletions.
35 changes: 12 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
# 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
rev: v5.0.0
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:
Expand Down Expand Up @@ -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:
Expand Down
88 changes: 86 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
64 changes: 11 additions & 53 deletions python/rmm/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
1 change: 1 addition & 0 deletions python/rmm/rmm/_cuda/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def getDevice():
def setDevice(device: int):
"""
Set the current CUDA device
Parameters
----------
device : int
Expand Down
12 changes: 6 additions & 6 deletions python/rmm/rmm/mr.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"CudaAsyncMemoryResource",
"CudaMemoryResource",
"DeviceMemoryResource",
"FailureCallbackResourceAdaptor",
"FixedSizeMemoryResource",
"LimitingResourceAdaptor",
"LoggingResourceAdaptor",
Expand All @@ -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",
]
12 changes: 6 additions & 6 deletions python/rmm/rmm/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -71,7 +71,7 @@ def enable_statistics() -> None:
)


def get_statistics() -> Optional[Statistics]:
def get_statistics() -> Statistics | None:
"""Get the current allocation statistics.
Returns
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -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)

Expand Down

0 comments on commit 3cad8fe

Please sign in to comment.