From 876e8fd1f581e466482f33980769de0d779f039f Mon Sep 17 00:00:00 2001 From: Adam Gayoso Date: Sun, 1 Sep 2024 17:12:20 +0100 Subject: [PATCH] Add more ruff rules (#177) * Add more ruff rules * remove bandit * Add FA * fixes * Remove D400 --- docs/extensions/typed_returns.py | 10 +++++---- pyproject.toml | 32 ++++++++++++++--------------- src/scib_metrics/benchmark/_core.py | 8 ++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/extensions/typed_returns.py b/docs/extensions/typed_returns.py index 1135204..8eceeb6 100644 --- a/docs/extensions/typed_returns.py +++ b/docs/extensions/typed_returns.py @@ -1,12 +1,14 @@ # code from https://github.com/theislab/scanpy/blob/master/docs/extensions/typed_returns.py # with some minor adjustment from __future__ import annotations - +from sphinx.ext.napoleon import NumpyDocstring +from typing import TYPE_CHECKING import re -from collections.abc import Generator, Iterable -from sphinx.application import Sphinx -from sphinx.ext.napoleon import NumpyDocstring +if TYPE_CHECKING: + from collections.abc import Generator, Iterable + + from sphinx.application import Sphinx def _process_return(lines: Iterable[str]) -> Generator[str, None, None]: diff --git a/pyproject.toml b/pyproject.toml index d550a21..3c65b09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,10 +35,7 @@ dependencies = [ ] [project.optional-dependencies] -dev = [ - "pre-commit", - "twine>=4.0.2", -] +dev = ["pre-commit", "twine>=4.0.2"] doc = [ "sphinx>=4", "sphinx-book-theme>=1.0", @@ -93,17 +90,20 @@ xfail_strict = true src = ["src"] line-length = 120 lint.select = [ - "F", # Errors detected by Pyflakes - "E", # Error detected by Pycodestyle - "W", # Warning detected by Pycodestyle - "I", # isort - "D", # pydocstyle - "B", # flake8-bugbear - "TID", # flake8-tidy-imports - "C4", # flake8-comprehensions - "BLE", # flake8-blind-except - "UP", # pyupgrade - "RUF100", # Report unused noqa directives + "F", # Errors detected by Pyflakes + "E", # Error detected by Pycodestyle + "W", # Warning detected by Pycodestyle + "I", # isort + "D", # pydocstyle + "B", # flake8-bugbear + "TID", # flake8-tidy-imports + "C4", # flake8-comprehensions + "BLE", # flake8-blind-except + "UP", # pyupgrade + "RUF100", # Report unused noqa directives + "ICN", # flake8-import-conventions + "TCH", # flake8-type-checking + "FA", # flake8-future-annotations ] lint.ignore = [ # line too long -> we accept long comment lines; formatter gets rid of long code lines @@ -122,8 +122,6 @@ lint.ignore = [ "B008", # __magic__ methods are are often self-explanatory, allow missing docstrings "D105", - # first line should end with a period [Bug: doesn't work with single-line docstrings] - "D400", # First line should be in imperative mood; try rephrasing "D401", ## Disable one in each pair of mutually incompatible rules diff --git a/src/scib_metrics/benchmark/_core.py b/src/scib_metrics/benchmark/_core.py index c159da9..dcfc259 100644 --- a/src/scib_metrics/benchmark/_core.py +++ b/src/scib_metrics/benchmark/_core.py @@ -6,7 +6,7 @@ from functools import partial from typing import Any -import matplotlib +import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd @@ -297,7 +297,7 @@ def plot_results_table(self, min_max_scale: bool = True, show: bool = True, save The directory to save the plot to. If `None`, the plot is not saved. """ num_embeds = len(self._embedding_obsm_keys) - cmap_fn = lambda col_data: normed_cmap(col_data, cmap=matplotlib.cm.PRGn, num_stds=2.5) + cmap_fn = lambda col_data: normed_cmap(col_data, cmap=mpl.cm.PRGn, num_stds=2.5) df = self.get_results(min_max_scale=min_max_scale) # Do not want to plot what kind of metric it is plot_df = df.drop(_METRIC_TYPE, axis=0) @@ -335,7 +335,7 @@ def plot_results_table(self, min_max_scale: bool = True, show: bool = True, save title=col.replace(" ", "\n", 1), plot_fn=bar, plot_kw={ - "cmap": matplotlib.cm.YlGnBu, + "cmap": mpl.cm.YlGnBu, "plot_bg_bar": False, "annotate": True, "height": 0.9, @@ -347,7 +347,7 @@ def plot_results_table(self, min_max_scale: bool = True, show: bool = True, save for i, col in enumerate(score_cols) ] # Allow to manipulate text post-hoc (in illustrator) - with matplotlib.rc_context({"svg.fonttype": "none"}): + with mpl.rc_context({"svg.fonttype": "none"}): fig, ax = plt.subplots(figsize=(len(df.columns) * 1.25, 3 + 0.3 * num_embeds)) tab = Table( plot_df,