Skip to content

Commit

Permalink
Update ruff config (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Dec 13, 2023
1 parent 04c4fcd commit a8f3841
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.2
rev: 0.27.3
hooks:
- id: check-github-workflows

Expand Down Expand Up @@ -66,7 +66,7 @@ repos:
additional_dependencies: ["traitlets>=5.13"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
rev: v0.1.7
hooks:
- id: ruff
types_or: [python, jupyter]
Expand Down
2 changes: 1 addition & 1 deletion comm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _get_comm_manager() -> CommManager:
This method is intended to be replaced if needed (if you want to manage multiple CommManagers).
"""
global _comm_manager
global _comm_manager # noqa: PLW0603

if _comm_manager is None:
_comm_manager = CommManager()
Expand Down
26 changes: 14 additions & 12 deletions comm/base_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,22 @@ def __init__(

def publish_msg(
self,
msg_type: str,
data: MaybeDict = None,
metadata: MaybeDict = None,
buffers: BuffersType = None,
**keys: t.Any,
msg_type: str, # noqa: ARG002
data: MaybeDict = None, # noqa: ARG002
metadata: MaybeDict = None, # noqa: ARG002
buffers: BuffersType = None, # noqa: ARG002
**keys: t.Any, # noqa: ARG002
) -> None:
raise NotImplementedError("publish_msg Comm method is not implemented")
msg = "publish_msg Comm method is not implemented"
raise NotImplementedError(msg)

def __del__(self) -> None:
"""trigger close on gc"""
self.close(deleting=True)

# publishing messages

def open( # noqa: A003
def open(
self, data: MaybeDict = None, metadata: MaybeDict = None, buffers: BuffersType = None
) -> None:
"""Open the frontend-side version of this comm"""
Expand All @@ -93,7 +94,8 @@ def open( # noqa: A003
data = self._open_data
comm_manager = comm.get_comm_manager()
if comm_manager is None:
raise RuntimeError("Comms cannot be opened without a comm_manager.")
msg = "Comms cannot be opened without a comm_manager." # type:ignore[unreachable]
raise RuntimeError(msg)

comm_manager.register_comm(self)
try:
Expand Down Expand Up @@ -211,7 +213,7 @@ def register_target(self, target_name: str, f: CommTargetCallback | str) -> None

self.targets[target_name] = t.cast(CommTargetCallback, f)

def unregister_target(self, target_name: str, f: CommTargetCallback) -> CommTargetCallback:
def unregister_target(self, target_name: str, f: CommTargetCallback) -> CommTargetCallback: # noqa: ARG002
"""Unregister a callable registered with register_target"""
return self.targets.pop(target_name)

Expand Down Expand Up @@ -245,7 +247,7 @@ def get_comm(self, comm_id: str) -> BaseComm | None:

# Message handlers

def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None:
def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002
"""Handler for comm_open messages"""
from comm import create_comm

Expand Down Expand Up @@ -278,7 +280,7 @@ def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None:
exc_info=True,
)

def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None:
def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002
"""Handler for comm_msg messages"""
content = msg["content"]
comm_id = content["comm_id"]
Expand All @@ -291,7 +293,7 @@ def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None:
except Exception:
logger.error("Exception in comm_msg for %s", comm_id, exc_info=True)

def comm_close(self, stream: ZMQStream, ident: str, msg: MessageType) -> None:
def comm_close(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002
"""Handler for comm_close messages"""
content = msg["content"]
comm_id = content["comm_id"]
Expand Down
38 changes: 32 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,33 @@ warn_unreachable = true
line-length = 100

[tool.ruff.lint]
select = [
"A", "B", "C", "E", "F", "I", "N", "Q", "RUF", "S", "T",
"UP", "W", "YTT",
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PTH", # flake8-use-pathlib
"PT", # flake8-pytest-style
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"PYI", # flake8-pyi
"S", # flake8-bandit
]
ignore = [
"PLR", # Design related pylint codes
"S101", # Use of `assert` detected
"G201" # Logging `.exception(...)` should be used instead
]
unfixable = [
# Don't touch print statements
Expand All @@ -100,8 +122,12 @@ unfixable = [
]

[tool.ruff.lint.per-file-ignores]
# S101 Use of `assert` detected
"tests/*" = ["S101"]
"tests/*" = []

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false
parametrize-names-type = "csv"

[tool.repo-review]
ignore = ["PY007", "PP308", "PY004", "GH102", "MY101", "RTD100"]
ignore = ["PP308", "PY004", "GH102", "MY101", "RTD100"]

0 comments on commit a8f3841

Please sign in to comment.