Skip to content

Commit

Permalink
ruff: process remaining existing checks and suppress the annoying ones
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Aug 28, 2024
1 parent 1c5efc4 commit d584534
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions my/coding/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def repos() -> List[Path]:

# returns modification time for an index to use as hash function
def _repo_depends_on(_repo: Path) -> int:
for pp in {
for pp in [
".git/FETCH_HEAD",
".git/HEAD",
"FETCH_HEAD", # bare
"HEAD", # bare
}:
]:
ff = _repo / pp
if ff.exists():
return int(ff.stat().st_mtime)
Expand Down
2 changes: 1 addition & 1 deletion my/core/_deprecated/kompress.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Ext:
def is_compressed(p: Path) -> bool:
# todo kinda lame way for now.. use mime ideally?
# should cooperate with kompress.kopen?
return any(p.name.endswith(ext) for ext in {Ext.xz, Ext.zip, Ext.lz4, Ext.zstd, Ext.zst, Ext.targz})
return any(p.name.endswith(ext) for ext in [Ext.xz, Ext.zip, Ext.lz4, Ext.zstd, Ext.zst, Ext.targz])


def _zstd_open(path: Path, *args, **kwargs) -> IO:
Expand Down
2 changes: 1 addition & 1 deletion my/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from . import compat
from . import warnings as warnings
from . import warnings

# some helper functions
# TODO start deprecating this? soon we'd be able to use Path | str syntax which is shorter and more explicit
Expand Down
2 changes: 1 addition & 1 deletion my/core/hpi_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self, it: Iterator[V]) -> None:
self.it = it
self._list: Optional[List] = None

def __iter__(self) -> Iterator[V]:
def __iter__(self) -> Iterator[V]: # noqa: PYI034
return self.it.__iter__()

def __next__(self) -> V:
Expand Down
2 changes: 1 addition & 1 deletion my/photos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _make_photo_aux(*args, **kwargs) -> List[Result]:

def _make_photo(photo: Path, mtype: str, *, parent_geo: Optional[LatLon]) -> Iterator[Result]:
exif: Exif
if any(x in mtype for x in {'image/png', 'image/x-ms-bmp', 'video'}):
if any(x in mtype for x in ['image/png', 'image/x-ms-bmp', 'video']):
# TODO don't remember why..
logger.debug(f"skipping exif extraction for {photo} due to mime {mtype}")
exif = {}
Expand Down
34 changes: 32 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ lint.extend-select = [
"PERF", # various potential performance speedups
"PD", # pandas rules
"PIE", # 'misc' lints
"PLR", # 'refactor' rules
"PLC", # pylint convention rules
"PLR", # pylint refactor rules
"PLW", # pylint warnings
"PT", # pytest stuff
"PYI", # various type hinting rules
"RET", # early returns
"RUF", # various ruff-specific rules
"TID", # various imports suggestions
"TCH", # various type checking rules
"TRY", # various exception handling rules
"UP", # detect deprecated python stdlib stuff
# "FA", # TODO enable later after we make sure cachew works?
Expand All @@ -31,10 +35,15 @@ lint.extend-select = [
# "EM", # TODO hmm could be helpful to prevent duplicate err msg in traceback.. but kinda annoying
# "FIX", # complains about fixmes/todos -- annoying
# "TD", # complains about todo formatting -- too annoying
# "ALL",
# "ANN", # missing type annotations? seems way to string though

# "ALL", # uncomment this to check for new rules!
]

lint.ignore = [
"D", # annoying nags about docstrings
"N", # pep naming

### too opinionated style checks
"E501", # too long lines
"E702", # Multiple statements on one line (semicolon)
Expand Down Expand Up @@ -115,4 +124,25 @@ lint.ignore = [
"TRY201", # raise without specifying exception name -- sometimes hurts readability
"TRY400", # TODO double check this, might be useful
"TRY401", # redundant exception in logging.exception call? TODO double check, might result in excessive logging

"TCH002", # suggests moving imports into type checking blocks -- too annoying
"TCH003", # suggests moving imports into type checking blocks -- too annoying

"I001", # unsorted import block TODO consider these?
"PGH", # TODO force error code in mypy instead

# TODO enable TID?
"TID252", # Prefer absolute imports over relative imports from parent modules

## too annoying
"T20", # just complains about prints and pprints
"Q", # flake quotes, too annoying
"C90", # some complexity checking
"G004", # logging statement uses f string
"ERA001", # commented out code
"SLF001", # private member accessed
"BLE001", # do not catch 'blind' Exception
"INP001", # complains about implicit namespace packages
"SIM", # some if statements crap
##
]

0 comments on commit d584534

Please sign in to comment.