Skip to content

Commit

Permalink
cleanup: remove, rename or ignore unused codes and vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Mar 2, 2024
1 parent 47c9e8e commit 5b2d6b7
Show file tree
Hide file tree
Showing 93 changed files with 567 additions and 629 deletions.
1 change: 0 additions & 1 deletion conf/defaults/en_US.UTF-8/hijri.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"hijriAlg": 0,
"hijriUseDB": false
}
1 change: 0 additions & 1 deletion conf/defaults/fa_IR.UTF-8/hijri.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"hijriAlg": 0,
"hijriUseDB": true
}
20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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
Expand Down Expand Up @@ -248,3 +248,21 @@ ignore = [
# refurb has no exclude param!
#load = ["some_module"]
#quiet = true

[tool.vulture]
exclude = [
"scal3/account/",
"*_test.py",
"scal3/ui_gtk/arch-enable-locale.py",
]
ignore_names = [
"OPEN_START",
"validDate",
"prefVersion",
"getMonthWeekNth",
"rgbToInt",
"rgbToHsl",
"htmlColorToRgb",
"_*",
"test*",
]
7 changes: 6 additions & 1 deletion scal3/account/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
from scal3.locale_man import tr as _
from scal3.os_utils import openUrl
from scal3.utils import toBytes, toStr
from scal3.os_utils import getUserDisplayName


userDisplayName = getUserDisplayName()


auth_local_webserver = True
auth_host_name = "localhost"
Expand Down Expand Up @@ -562,7 +567,7 @@ def addToDiff(key, here, status, *args):
"calendarId": remoteGroupId,
"sequence": group.index(event.id),
"organizer": {
"displayName": core.userDisplayName, # FIXME
"displayName": userDisplayName, # FIXME
"email": self.email,
},
})
Expand Down
2 changes: 1 addition & 1 deletion scal3/bin_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def deleteLessThan(self, key):
"""


def getMinTest(N):
def testGetMin(N):
from random import randint

h = MaxHeap()
Expand Down
3 changes: 0 additions & 3 deletions scal3/cal_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ def iterIndexModuleInactive(self):
for i in self.inactive:
yield i, modules[i]

def allIndexes(self):
return self.active + self.inactive

def __contains__(self, key) -> bool:
if isinstance(key, str):
return key in self.byName
Expand Down
4 changes: 0 additions & 4 deletions scal3/cal_types/ethiopian.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y):
return 12


epoch = 1724235
minMonthLen = 30
maxMonthLen = 36
Expand Down
6 changes: 1 addition & 5 deletions scal3/cal_types/gregorian.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ def getMonthNameAb(tr, m, y: "int | None" = None) -> str: # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y: int) -> int:
return 12


epoch = 1721426
minMonthLen = 29
maxMonthLen = 31
Expand Down Expand Up @@ -147,7 +143,7 @@ def getMonthLen(y: int, m: int) -> int:
return to_jd(y, m + 1, 1) - to_jd(y, m, 1)


J0001 = 1721426 # to_jd(1, 1, 1)
# J0001 = 1721426 # to_jd(1, 1, 1)
J1970 = 2440588 # to_jd(1970, 1, 1)

J0001_epoch = -62135621220
4 changes: 0 additions & 4 deletions scal3/cal_types/gregorian_proleptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y):
return 12


from math import floor


Expand Down
14 changes: 2 additions & 12 deletions scal3/cal_types/hijri.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,14 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y):
return 12


epoch = 1948440
minMonthLen = 29
maxMonthLen = 30
avgYearLen = 354.3666 # FIXME


hijriAlg = 0
hijriUseDB = True


# ("hijriAlg", list, "Hijri Calculation Algorithm",
# ("Internal", "ITL (idate command)", "ITL (idate command) Umm Alqura")),
options = (
(
"hijriUseDB",
Expand Down Expand Up @@ -144,7 +136,6 @@ def save():
__name__,
confPath,
(
"hijriAlg",
"hijriUseDB",
),
)
Expand Down Expand Up @@ -302,15 +293,14 @@ def to_jd_c(year, month, day):


def to_jd(year, month, day):
if hijriUseDB: # and hijriAlg == 0
if hijriUseDB:
jd = monthDb.getJdFromDate(year, month, day)
if jd is not None:
return jd
return to_jd_c(year, month, day)


def jd_to(jd):
# hijriAlg == 0
if hijriUseDB:
# jd = ifloor(jd)
date = monthDb.getDateFromJd(jd)
Expand All @@ -328,7 +318,7 @@ def jd_to(jd):


def getMonthLen(y, m):
# if hijriUseDB:## and hijriAlg==0
# if hijriUseDB:
# try:
# return monthDb.monthLenByYm[y*12+m]
# except KeyError:
Expand Down
6 changes: 1 addition & 5 deletions scal3/cal_types/indian_national.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y):
return 12


# Monday Somavãra
# Tuesday Mañgalvã
# Wednesday Budhavãra
Expand Down Expand Up @@ -157,7 +153,7 @@ def jd_to(jd):
# the Indian year and subtracting off the required number of months and
# days to get the final date

gregorianYear, gregorianMonth, gregorianDay = gregorian.jd_to(jd)
gregorianYear, _gregorianMonth, _gregorianDay = gregorian.jd_to(jd)
jdGregorianFirstDayOfYear = gregorian.to_jd(gregorianYear, 1, 1)
gregorianDayOfYear = jd - jdGregorianFirstDayOfYear + 1

Expand Down
4 changes: 0 additions & 4 deletions scal3/cal_types/jalali.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return tr(fullEn)


def getMonthsInYear(_y):
return 12


epoch = 1948321
minMonthLen = 29
maxMonthLen = 31
Expand Down
3 changes: 0 additions & 3 deletions scal3/cal_types/julian.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001
return monthNameAb[m - 1]


def getMonthsInYear(_y):
return 12


epoch = 1721058
minMonthLen = 28
Expand Down
8 changes: 0 additions & 8 deletions scal3/color_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
ColorType: "typing.TypeAlias" = "tuple[int,int,int] | tuple[int,int,int,int]"


def invertColor(r, g, b):
return (
255 - r,
255 - g,
255 - b,
)


def rgbToInt(r, g, b):
"""For example (170, 85, 52) or "#aa5534" becomes 0xaa5534."""
return b + g * 256 + r * 256**2
Expand Down
68 changes: 15 additions & 53 deletions scal3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
saveModuleJsonConf,
)
from scal3.locale_man import tr as _
from scal3.os_utils import (
getUserDisplayName,
)
from scal3.path import (
APP_NAME,
confDir,
Expand All @@ -51,9 +48,8 @@
sourceDir,
sysConfDir,
)
from scal3.plugin_man import BasePlugin, loadPlugin
from scal3.time_utils import getEpochFromJd, getJhmsFromEpoch
from scal3.utils import versionLessThan
from scal3.plugin_man import loadPlugin
from scal3.time_utils import getJhmsFromEpoch

try:
__file__
Expand All @@ -71,12 +67,11 @@
APP_DESC = "StarCalendar"
COMMAND = APP_NAME
homePage = "http://ilius.github.io/starcal/"
userDisplayName = getUserDisplayName()


# __plugin_api_get__ = [
# "VERSION", "APP_NAME", "APP_DESC", "COMMAND",
# "homePage", "osName", "userDisplayName"
# "homePage", "osName",
# "jd_to_primary", "primary_to_jd",
# ]
# __plugin_api_set__ = []
Expand Down Expand Up @@ -155,7 +150,7 @@ def saveConf() -> None:

log = logger.get()

fs = None # type: "s_object.FileSystem"
fs: s_object.FileSystem | None = None

# ____________________________________________________________________ #
# __________________ class and function defenitions __________________ #
Expand Down Expand Up @@ -229,10 +224,10 @@ def getCurrentJd() -> int:
return to_jd(y, m, d, GREGORIAN)


def getWeekDateHmsFromEpoch(epoch: int) -> tuple[int, int, int, int, int]:
jd, hms = getJhmsFromEpoch(epoch)
absWeekNumber, weekDay = getWeekDateFromJd(jd)
return (absWeekNumber, weekDay, hms.h, hms.m, hms.s)
# def getWeekDateHmsFromEpoch(epoch: int) -> tuple[int, int, int, int, int]:
# jd, hms = getJhmsFromEpoch(epoch)
# absWeekNumber, weekDay = getWeekDateFromJd(jd)
# return (absWeekNumber, weekDay, hms.h, hms.m, hms.s)


def getMonthWeekNth(jd: int, calType: int) -> tuple[int, int, int]:
Expand All @@ -241,7 +236,7 @@ def getMonthWeekNth(jd: int, calType: int) -> tuple[int, int, int]:
year, month, day = jd_to(jd, calType)
absWeekNumber, weekDay = getWeekDateFromJd(jd)
##
dayDiv, dayMode = divmod(day - 1, 7)
dayDiv = (day - 1) // 7
return month, dayDiv, weekDay


Expand Down Expand Up @@ -312,12 +307,12 @@ def getWeekNumberByJd(jd: int) -> int:
# return getWeekNumberByJd(primary_to_jd(year+1, 1, 1) - 7)


def getJdFromWeek(year: int, weekNumber: int) -> int: # FIXME
# weekDay == 0
wd0 = getWeekDay(year, 1, 1) - 1
wn0 = getWeekNumber(year, 1, 1, False)
jd0 = primary_to_jd(year, 1, 1)
return jd0 - wd0 + (weekNumber - wn0) * 7
# def getJdFromWeek(year: int, weekNumber: int) -> int: # FIXME
# # weekDay == 0
# wd0 = getWeekDay(year, 1, 1) - 1
# wn0 = getWeekNumber(year, 1, 1, False)
# jd0 = primary_to_jd(year, 1, 1)
# return jd0 - wd0 + (weekNumber - wn0) * 7


def getWeekDateFromJd(jd: int) -> tuple[int, int]:
Expand Down Expand Up @@ -411,15 +406,6 @@ def initPlugins(fs: "s_object.FileSystem") -> None:
updatePlugins()


def getHolidayPlugins() -> list[BasePlugin]:
hPlugs = []
for i in plugIndex:
plug = allPlugList[i]
if hasattr(plug, "holidays"):
hPlugs.append(plug)
return hPlugs


def updatePlugins() -> None:
for i in plugIndex:
plug = allPlugList[i]
Expand Down Expand Up @@ -479,19 +465,6 @@ def restart() -> typing.NoReturn:
# _____________________________________________________ #


def mylocaltime(
sec: "int | None" = None,
calType: "int | None" = None,
) -> list[int]:
from scal3.cal_types import convert

if calType is None: # GREGORIAN
return list(localtime(sec))
t = list(localtime(sec))
t[:3] = convert(t[0], t[1], t[2], GREGORIAN, calType)
return t


def compressLongInt(num: int) -> str:
"""Num must be less than 2**64."""
from base64 import b64encode
Expand All @@ -514,13 +487,6 @@ def getCompactTime(maxDays: int = 1000, minSec: float = 0.1) -> str:
)


def floatJdEncode(jd: int, calType: int) -> str:
jd, hms = getJhmsFromEpoch(getEpochFromJd(jd))
if calType not in calTypes:
raise RuntimeError(f"cal type '{calType}' not found")
return dateEncode(jd_to(jd, calType)) + f" {hms:HMS}"


def epochDateTimeEncode(epoch: int) -> str:
jd, hms = getJhmsFromEpoch(epoch)
return dateEncode(jd_to_primary(jd)) + f" {hms:HMS}"
Expand Down Expand Up @@ -560,10 +526,6 @@ def init() -> None:
initPlugins(fs)


def prefIsOlderThan(v: str) -> bool:
return versionLessThan(prefVersion, v)


# ___________________________________________________________________________ #
# __________________ End of class and function defenitions __________________ #

Expand Down
4 changes: 2 additions & 2 deletions scal3/date_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def dateEncode(date: tuple[int, int, int]) -> str:
return f"{date[0]:04d}/{date[1]:02d}/{date[2]:02d}"


def dateEncodeDash(date: tuple[int, int, int]) -> str:
return f"{date[0]:04d}-{date[1]:02d}-{date[2]:02d}"
# def dateEncodeDash(date: tuple[int, int, int]) -> str:
# return f"{date[0]:04d}-{date[1]:02d}-{date[2]:02d}"


def checkDate(date: tuple[int, int, int]) -> None:
Expand Down
Loading

0 comments on commit 5b2d6b7

Please sign in to comment.