Skip to content

Commit

Permalink
fix refurb and ruff preview errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 22, 2024
1 parent 507e25e commit b8ad1ca
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion plugins/pray_times_files/pray_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,5 @@ def onCurrentDateChange(self, gdate):
# dialog.connect("response", gtk.main_quit)
dialog.resize(600, 600)
result = dialog.run()
log.info(f"{result}")
log.info(f"{result}") # noqa: FURB183
# gtk.main()
64 changes: 31 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ lint.select = [
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
# "G", # flake8-logging-format, non-sense!
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"INP", # flake8-no-pep420
"PIE", # flake8-pie
# "T20", # flake8-print
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
Expand All @@ -47,15 +47,15 @@ lint.select = [
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"INT", # flake8-gettext
"ARG", # flake8-unused-arguments
"ARG", # flake8-unused-arguments
# "PTH", # flake8-use-pathlib
# "TD", # flake8-todos
# "FIX", # flake8-fixme: just shows me FIXMEs and TODOs
# "ERA", # eradicate
# "PD", # pandas-vet: full of false positives
"PGH", # pygrep-hooks
"PL", # Pylint
"TRY", # tryceratops, some are BS
"PL", # Pylint
"TRY", # tryceratops, some are BS
# "FLY", # flynt
"NPY", # NumPy-specific rules
"AIR", # Airflow
Expand All @@ -69,19 +69,19 @@ lint.select = [
# To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.

lint.ignore = [
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
"PLC0206", # Extracting value from dictionary without calling `.items()`

"PYI034", # py3.11: `__iadd__` methods in classes like `...` usually return `self` at runtime
"PYI034", # py3.11: `__iadd__` methods in classes like `...` usually return `self` at runtime

"PLR1702", # Too many nested blocks
"PLR0904", # Too many public methods (? > 20)
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0914", # Too many local variables
"PLR0915", # Too many statements
"PLR0917", # Too many positional arguments
"PLR2004", # Magic value used in comparison, consider replacing `...` with a constant variable
"PLR0904", # Too many public methods (? > 20)
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0914", # Too many local variables
"PLR0915", # Too many statements
"PLR0917", # Too many positional arguments
"PLR2004", # Magic value used in comparison, consider replacing `...` with a constant variable
"PLW0603", # Using the global statement to update `...` is discouraged
"PLC0415", # `import` should be at the top-level of a file

Expand Down Expand Up @@ -111,17 +111,17 @@ lint.ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF100", # Unused `noqa` directive (non-enabled: ...)

"TRY003", # BS: Avoid specifying long messages outside the exception class
"TRY400", # BS: Use `logging.exception` instead of `logging.error`
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM108", # Use ternary operator {contents} instead of if-else-block
"SIM117", # Use a single with statement with multiple contexts...
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`, why?
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaises`, why?
"TRY003", # BS: Avoid specifying long messages outside the exception class
"TRY400", # BS: Use `logging.exception` instead of `logging.error`
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM108", # Use ternary operator {contents} instead of if-else-block
"SIM117", # Use a single with statement with multiple contexts...
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`, why?
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaises`, why?
"RET502", # Do not implicitly `return None` in function able to return non-`None` value
"E402", # Module level import not at top of file
"S101", # Use of `assert` detected
"W191", # Indentation contains tabs
"E402", # Module level import not at top of file
"S101", # Use of `assert` detected
"W191", # Indentation contains tabs
]

# UP033: (Since Python 3.9) Use `@functools.cache`
Expand Down Expand Up @@ -189,9 +189,9 @@ lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
]
"*_test.py" = [
"T201", # `print` found
"T203", # `pprint` found
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
"T201", # `print` found
"T203", # `pprint` found
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
"PLR6301", # Method `...` could be a function, class method, or static method
]
"scal3/__init__.py" = [
Expand Down Expand Up @@ -237,6 +237,8 @@ exclude = []

[tool.refurb]
ignore = [
117, # Replace `open(filename, "rb")` with `filename.open("rb")`
184, # Assignment statement should be chained
101, # Replace `with open(x, ...) as f: y = f.read()` with `y = Path(x).read_bytes()`
103, # Replace `with open(x, ...) as f: f.write(y)` with `Path(x).write_bytes(y)`
104, # Replace `os.getcwd()` with `Path.cwd()`
Expand All @@ -253,11 +255,7 @@ ignore = [
#quiet = true

[tool.vulture]
exclude = [
"scal3/account/",
"*_test.py",
"scal3/ui_gtk/arch-enable-locale.py",
]
exclude = ["scal3/account/", "*_test.py", "scal3/ui_gtk/arch-enable-locale.py"]
ignore_names = [
"OPEN_START",
"validDate",
Expand All @@ -266,6 +264,6 @@ ignore_names = [
"rgbToInt",
"rgbToHsl",
"htmlColorToRgb",
"_*",
"_*",
"test*",
]
8 changes: 3 additions & 5 deletions scal3/account/google.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) Saeed Rasooli <saeed.gnu@gmail.com>
#
Expand All @@ -16,6 +15,7 @@

# FIXME
from __future__ import annotations

developerKey = (
"AI39si4QJ0bmdZJd7nVz0j3zuo1JYS3WUJX8y0f2"
"mvGteDtiKY8TUSzTsY4oAcGlYAM0LmOxHmWWyFLU"
Expand All @@ -40,7 +40,7 @@
# from httplib2 import
from scal3.path import sourceDir

sys.path.append(join(sourceDir, "google-api-python-client")) # FIXME
sys.path.append(join(sourceDir, "google-api-python-client")) # noqa: FURB113 # FIXME
sys.path.append(join(sourceDir, "oauth2client")) # FIXME

from scal3 import core, event_lib
Expand All @@ -50,10 +50,8 @@

# from scal3.ics import
from scal3.locale_man import tr as _
from scal3.os_utils import openUrl
from scal3.os_utils import getUserDisplayName, openUrl
from scal3.utils import toBytes, toStr
from scal3.os_utils import getUserDisplayName


userDisplayName = getUserDisplayName()

Expand Down
2 changes: 1 addition & 1 deletion scal3/cal_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def primaryModule(self):
def update(self):
self.active = []
self.inactive = [] # range(len(modules))
remainingNames = self.names[:]
remainingNames = self.names.copy()
for name in self.activeNames:
try:
i = self.names.index(name)
Expand Down
2 changes: 1 addition & 1 deletion scal3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def getVersion() -> str:
# sys.stderr.write(error)

gitVersion = re.sub(
"-([0-9]+)-g([0-9a-f]{6,8})",
r"-([0-9]+)-g([0-9a-f]{6,8})",
r"post\1+\2",
gitVersionRaw,
)
Expand Down
14 changes: 10 additions & 4 deletions scal3/event_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from typing import Any

import json
import operator
import os
import os.path
from collections import OrderedDict
Expand Down Expand Up @@ -128,6 +129,7 @@
hms_zero = HMS()
hms_24 = HMS(24)

keyFuncIndex0 = operator.itemgetter(0)

# --------------------------

Expand Down Expand Up @@ -1428,7 +1430,7 @@ def setSeconds(self, s: int) -> None:
assert isinstance(s, int)
for unit in reversed(self.units):
if s % unit == 0:
self.value, self.unit = int(s // unit), unit
self.value, self.unit = s // unit, unit
return
self.unit, self.value = s, 1

Expand Down Expand Up @@ -1504,7 +1506,7 @@ def getServerString(self) -> str:
return str(self.days)

def __str__(self) -> str:
return f"{self.days}"
return str(self.days)

def __init__(self, parent: Event) -> None:
EventRule.__init__(self, parent)
Expand Down Expand Up @@ -1545,7 +1547,7 @@ def getServerString(self) -> str:
return str(self.weeks)

def __str__(self) -> str:
return f"{self.weeks}"
return str(self.weeks)

def __init__(self, parent: RuleContainer) -> None:
EventRule.__init__(self, parent)
Expand Down Expand Up @@ -2936,16 +2938,20 @@ def getEnd(self):
def getEndJd(self) -> int:
end, ok = self["end"]
if ok:
# assert isinstance(end.getJd(), int)
return end.getJd()
duration, ok = self["duration"]
if ok:
start, ok = self["start"]
if not ok:
raise RuntimeError("no start rule")
# assert isinstance(start.getJd(), int)
return start.getJd() + duration.getSeconds() // dayLen
raise ValueError("no end date neither duration specified for task")

def getEndEpoch(self):
# if not isinstance(self.getEndJd(), int):
# raise TypeError(f"{self}.getEndJd() returned non-int: {self.getEndJd()}")
return self.getEpochFromJd(self.getEndJd())

# def setEndJd(self, jd):
Expand Down Expand Up @@ -6407,7 +6413,7 @@ def getDayOccurrenceData(curJd, groups, tfmt="HM$"):
),
),
)
data.sort(key=lambda x: x[0])
data.sort(key=keyFuncIndex0)
return [item[1] for item in data]


Expand Down
9 changes: 5 additions & 4 deletions scal3/import_config_2to3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) Saeed Rasooli <saeed.gnu@gmail.com>
#
Expand All @@ -19,15 +18,17 @@
# no logging in this file

from __future__ import annotations

import json
import logging
import os
import re
import shutil
from collections import OrderedDict
from collections.abc import Generator
from os.path import isdir, isfile, join, splitext
from time import time as now
from typing import Any, Generator
from typing import Any

from scal3.json_utils import dataToPrettyJson
from scal3.os_utils import makeDir
Expand Down Expand Up @@ -139,8 +140,8 @@ def loadUiCustomizeConf() -> None:
print(f"failed to read file {confPath!r}: {e}")
return
# -----
text = re.sub(r"^ui\.", "", text, flags=re.M)
text = re.sub(r"^ud\.", "ud__", text, flags=re.M)
text = re.sub(r"^ui\.", "", text, flags=re.MULTILINE)
text = re.sub(r"^ud\.", "ud__", text, flags=re.MULTILINE)
# ------
data = OrderedDict()
exec(text, {}, data)
Expand Down
2 changes: 1 addition & 1 deletion scal3/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def openUrl(url: str) -> bool:
try:
Popen([command, url]) # noqa: S603
except Exception as e:
log.error(f"{e}")
log.error(f"{e}") # noqa: FURB183
else:
return True
return False
10 changes: 6 additions & 4 deletions scal3/time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def getUtcOffsetByJd(jd: int, tz: TZ = None) -> int:
y, m, d = jd_to_g(jd)
offset = getUtcOffsetByGDate(y, m, d, tz)

assert isinstance(offset, int)
return offset


Expand All @@ -160,7 +161,8 @@ def getJdFromEpoch(epoch, tz: TZ = None) -> int:
return ifloor(getFloatJdFromEpoch(epoch, tz))


def getEpochFromJd(jd, tz: TZ = None) -> int:
def getEpochFromJd(jd: int, tz: TZ = None) -> int:
assert isinstance(jd, int)
localEpoch = (jd - J1970) * 24 * 3600
year, month, day = jd_to_g(jd) # jd or jd-1? FIXME
return localEpoch - getUtcOffsetByGDate(year, month, day, tz)
Expand Down Expand Up @@ -239,7 +241,7 @@ def getJdAndSecondsFromEpoch(epoch: int) -> tuple[int, int]:
def timeEncode(
tm: tuple[int, int, int] | tuple[int, int],
) -> str:
return f"{HMS(*tm)}"
return str(HMS(*tm))


def simpleTimeEncode(
Expand All @@ -252,9 +254,9 @@ def simpleTimeEncode(
if len(tm) == 2:
if tm[1] == 0:
return str(int(tm[0]))
return f"{HMS(*tm)}"
return str(HMS(*tm))
if len(tm) == 3:
return f"{HMS(*tm)}"
return str(HMS(*tm))
return None


Expand Down
4 changes: 2 additions & 2 deletions scal3/timeline/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def addDayOfMonthTick(jd, month, day, dayUnit):
break
unitSize = stepSec * pixelPerSec
for jd in range(jd0, jd1 + 1):
utcOffset = int(getUtcOffsetByJd(jd))
utcOffset = getUtcOffsetByJd(jd)
firstEpoch = (
iceil(
(timeStart + utcOffset) / stepSec,
Expand All @@ -320,7 +320,7 @@ def addDayOfMonthTick(jd, month, day, dayUnit):
)
for tmEpoch in range(
firstEpoch,
min(int(getEpochFromJd(jd + 1)), iceil(timeEnd)),
min(getEpochFromJd(jd + 1), iceil(timeEnd)),
stepSec,
):
if tmEpoch in tickEpochSet:
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
with open(join(sourceDir, "svg", "special", "color-check.svg"), encoding="utf-8") as fp: # noqa: FURB101
colorCheckSvgTextChecked = fp.read()
colorCheckSvgTextUnchecked = re.sub(
'<path[^<>]*?id="check"[^<>]*?/>',
r'<path[^<>]*?id="check"[^<>]*?/>',
"",
colorCheckSvgTextChecked,
flags=re.MULTILINE | re.DOTALL,
Expand Down
6 changes: 1 addition & 5 deletions scal3/ui_gtk/pref_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,7 @@ def __init__(
raise ValueError("onChangeFunc is given without live=True")

def get(self) -> str:
iconPath = self.iconSelect.get_filename()
direc = join(pixDir, "")
if iconPath.startswith(direc):
iconPath = iconPath[len(direc) :]
return iconPath
return self.iconSelect.get_filename().removeprefix(join(pixDir, ""))

def set(self, iconPath: str) -> None:
if not isabs(iconPath):
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/winContronller.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class WinConButtonRightPanel(WinConButton):

def __init__(self, controller):
direc = "left" if rtl else "right"
self.imageName = f"{direc}"
self.imageName = direc
self.imageNameFocus = f"{direc}-focus"
self.imageNameInactive = f"{direc}-inactive"
self.imageNamePress = f"{direc}-press"
Expand Down
Loading

0 comments on commit b8ad1ca

Please sign in to comment.