Skip to content

Commit

Permalink
ruff: fix pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Mar 14, 2024
1 parent 25ea71c commit 9d536f0
Show file tree
Hide file tree
Showing 114 changed files with 732 additions and 742 deletions.
16 changes: 12 additions & 4 deletions distro/base/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ def main():
# print(f"runDirStr: {runDirStr}")

executablePath = join(targetPrefix, "bin", pkgName)
with open(executablePath, mode="w") as _file:
with open(executablePath, mode="w", encoding="utf-8") as _file:
_file.write(
"#!/usr/bin/env sh\n"
f'{pyCmd} {runDirStr}/scal3/ui_gtk/starcal-main.py "$@"\n',
)
os.chmod(executablePath, 0o755)
print(f"Executable: {executablePath}")

with open(join(targetCodeDir, "VERSION"), mode="w") as _file:
with open(join(targetCodeDir, "VERSION"), mode="w", encoding="utf-8") as _file:
_file.write(f"{version}\n")

if installType == "system":
Expand All @@ -270,7 +270,15 @@ def main():
else:
os.remove(join(targetCodeDir, "distro/base/uninstall"))

with open(join(shareDir, "applications", f"{pkgName}.desktop"), mode="w") as _file:
with open(
join(
shareDir,
"applications",
f"{pkgName}.desktop",
),
mode="w",
encoding="utf-8",
) as _file:
_file.write(
"[Desktop Entry]\n"
"Encoding=UTF-8\n"
Expand All @@ -294,7 +302,7 @@ def main():
):
return 1

if "$installType" in ("for-pkg", "system"):
if "$installType" in {"for-pkg", "system"}:
cleanup(join(targetCodeDir, ".git"))
cleanup(join(targetCodeDir, ".github"))
cleanup(join(targetCodeDir, ".gitignore"))
Expand Down
2 changes: 1 addition & 1 deletion natz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def readEtcLocaltime():
# https://github.com/regebro/tzlocal/blob/master/tzlocal/unix.py
if not islink("/etc/localtime"):
if isfile("/var/db/zoneinfo"):
with open("/var/db/zoneinfo") as _file:
with open("/var/db/zoneinfo", encoding="utf-8") as _file:
tzname = _file.read().strip()
return dateutil.tz.gettz(tzname)
# 'zdump /etc/localtime' does not show timezone's name
Expand Down
41 changes: 21 additions & 20 deletions plugins/pray_times_files/pray_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,25 @@ def translatePlaceName(name: str) -> str:
if len(p) < 2:
# log.debug(p)
continue
if p[0] == "":
if p[1] == "":
city, lat, lng = p[2:5]
log.debug(f"{city=}")
if len(p) > 4:
cityData.append(
(
country + "/" + city,
translatePlaceName(country)
+ "/"
+ translatePlaceName(city),
float(lat),
float(lng),
),
)
else:
log.debug(f"{country=}, {p=}")
else:
country = p[1]
if p[0]:
continue
if p[1]:
country = p[1]
continue
city, lat, lng = p[2:5]
log.debug(f"{city=}")
if len(p) < 5:
log.debug(f"{country=}, {p=}")
continue
cityData.append(
(
country + "/" + city,
translatePlaceName(country) + "/" + translatePlaceName(city),
float(lat),
float(lng),
),
)

return cityData


Expand Down Expand Up @@ -321,7 +321,8 @@ def get_times_jd(self, jd):
)
return [(name, times[name]) for name in self.shownTimeNames]

def getFormattedTime(self, tm): # tm is float hour
@staticmethod
def getFormattedTime(tm): # tm is float hour
try:
h, m, _s = floatHourToTime(float(tm))
except ValueError:
Expand Down
6 changes: 4 additions & 2 deletions plugins/pray_times_files/pray_times_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,17 @@ def sunPosition(self, jd):
return {"declination": decl, "equation": eqt}
"""

def sunDeclination(self, jd):
@staticmethod
def sunDeclination(jd):
D = jd - 2451545.0
g = fixAngle(357.529 + 0.98560028 * D)
q = fixAngle(280.459 + 0.98564736 * D)
L = fixAngle(q + 1.915 * sin(g) + 0.020 * sin(2 * g))
e = 23.439 - 0.00000036 * D
return arcsin(sin(e) * sin(L))

def sunEquation(self, jd):
@staticmethod
def sunEquation(jd):
D = jd - 2451545.0
g = fixAngle(357.529 + 0.98560028 * D)
q = fixAngle(280.459 + 0.98564736 * D)
Expand Down
22 changes: 12 additions & 10 deletions plugins/pray_times_files/pray_times_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,20 @@ def update_list(self, s=""):
t.clear()
d = self.cityData
n = len(d)
if s == "":
if not s:
for i in range(n):
t.append((i, d[i][0]))
else: # here check also translations
mr = self.maxResults
r = 0
for i in range(n):
if s in (d[i][0] + "\n" + d[i][1]).lower():
t.append((i, d[i][1]))
r += 1
if r >= mr:
break
return

# here check also translations
mr = self.maxResults
r = 0
for i in range(n):
if s in (d[i][0] + "\n" + d[i][1]).lower():
t.append((i, d[i][1]))
r += 1
if r >= mr:
break
self.treev.scroll_to_cell((0, 0))
self.okB.set_sensitive(self.checkbEdit.get_active())

Expand Down
56 changes: 34 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ lint.select = [
# "ERA", # eradicate
# "PD", # pandas-vet: full of false positives
"PGH", # pygrep-hooks
# "PL", # Pylint
"PL", # Pylint
"TRY", # tryceratops, some are BS
# "FLY", # flynt
"NPY", # NumPy-specific rules
Expand All @@ -69,7 +69,18 @@ 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 = [
"PYI034", # py3.11: `__iadd__` methods in classes like `SqEntryList` 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
"PLW0603", # Using the global statement to update `...` is discouraged
"PLC0415", # `import` should be at the top-level of a file

"B019", # Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
"B019", # Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
Expand Down Expand Up @@ -120,26 +131,26 @@ lint.ignore = [
# since which Python is comma after **kwargs allowd?

# Allow autofix for all enabled rules (when `--fix`) is provided.
lint.fixable = [
"TRY", # tryceratops
"ANN",
"C408", # Unnecessary `dict` call (rewrite as a literal)
"COM",
"D",
"E",
"F",
"W",
"F401",
"I",
"Q",
"PIE790",
"RET",
"RUF",
# "SIM",
"SIM108", # Use ternary operator {contents} instead of if-else-block
"TCH",
"UP",
]
# lint.fixable = [
# "TRY", # tryceratops
# "ANN",
# "C408", # Unnecessary `dict` call (rewrite as a literal)
# "COM",
# "D",
# "E",
# "F",
# "W",
# "F401",
# "I",
# "Q",
# "PIE790",
# "RET",
# "RUF",
# # "SIM",
# "SIM108", # Use ternary operator {contents} instead of if-else-block
# "TCH",
# "UP",
# ]
lint.unfixable = []

# Exclude a variety of commonly ignored directories.
Expand Down Expand Up @@ -182,6 +193,7 @@ lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"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
]

[tool.ruff.format]
Expand Down
7 changes: 4 additions & 3 deletions scal3/cal_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
modules = [gregorian]


with open(join(modDir, "modules.list")) as fp:
with open(join(modDir, "modules.list"), encoding="utf-8") as fp:
for name in fp.read().split("\n"):
name = name.strip()
name = name.strip() # noqa: PLW2901
if not name:
continue
if name.startswith("#"):
Expand Down Expand Up @@ -162,7 +162,8 @@ def get(self, key, default=None):
def getDesc(self, key):
return self.get(key).desc

def nameByIndex(self, index):
@staticmethod
def nameByIndex(index):
if index >= len(modules):
return ""
return modules[index].name
Expand Down
2 changes: 1 addition & 1 deletion scal3/cal_types/gregorian_proleptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def getMonthLen(y, m):
if isLeap(y):
return 29
return 28
if m in (4, 6, 9, 11):
if m in {4, 6, 9, 11}:
return 30
return 31

Expand Down
1 change: 1 addition & 0 deletions scal3/cal_types/gregorian_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def notest_isLeap_negativeYear(self):

def test_isLeap(self):
import calendar

for year, isLeapStr in self.isLeapDict.items():
isLeap = isLeapStr == "L"
assert isLeap == calendar.isleap(year)
Expand Down
18 changes: 8 additions & 10 deletions scal3/cal_types/hijri.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@


def getMonthName(m, y=None): # noqa: ARG001
return monthName.__getitem__(m - 1)
return monthName[m - 1]


def getMonthNameAb(tr, m, y=None): # noqa: ARG001
Expand Down Expand Up @@ -134,9 +134,7 @@ def save():
saveJsonConf(
__name__,
confPath,
(
"hijriUseDB",
),
("hijriUseDB",),
)


Expand Down Expand Up @@ -176,12 +174,12 @@ def setData(self, data):
self.setMonthLenByYear(monthLenByYear)

def load(self):
with open(self.sysDbPath) as fp:
with open(self.sysDbPath, encoding="utf-8") as fp:
data = jsonToData(fp.read())
self.origVersion = data["version"]
##
if isfile(self.userDbPath):
with open(self.userDbPath) as fp:
with open(self.userDbPath, encoding="utf-8") as fp:
userData = jsonToData(fp.read())
if userData["origVersion"] >= self.origVersion:
data = userData
Expand All @@ -200,8 +198,7 @@ def getMonthLenByYear(self):

def save(self):
mLenData = [
[year] + mLenList
for year, mLenList in self.getMonthLenByYear().items()
[year] + mLenList for year, mLenList in self.getMonthLenByYear().items()
]
text = dataToPrettyJson(
OrderedDict(
Expand All @@ -214,7 +211,7 @@ def save(self):
],
),
)
with open(self.userDbPath, "w") as f:
with open(self.userDbPath, "w", encoding="utf-8") as f:
f.write(text)

def getMonthLenList(self):
Expand Down Expand Up @@ -258,7 +255,8 @@ def getDateFromJd(self, jd):
year, mm = divmod(ym, 12)
return (year, mm + 1, d)

def getJdFromDate(self, year, month, day):
@staticmethod
def getJdFromDate(year, month, day):
ym = year * 12 + month - 1
y0, m0, _d0 = monthDb.startDate
if ym - 1 not in monthDb.monthLenByYm:
Expand Down
2 changes: 1 addition & 1 deletion scal3/color_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def rgbToHsl(r, g, b):
# ln means lightness
ln = (mx + mn) / 2.0
###
if 0 in (ln, dm):
if 0 in {ln, dm}:
s = 0
elif 0 < ln < 0.5:
s = dm / (mx + mn)
Expand Down
Loading

0 comments on commit 9d536f0

Please sign in to comment.