Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: check-added-large-files
- id: debug-statements
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
rev: v2.4.0
hooks:
- id: mypy
additional_dependencies:
Expand All @@ -19,7 +19,7 @@ repos:
- types-setuptools
- types-python-dateutil
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.15.7'
rev: 'v0.17.0'
hooks:
- id: ruff
args: ["--fix"]
Expand Down
18 changes: 12 additions & 6 deletions khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ def get_events_between(
# yes the logic could be simplified, but I believe it's easier
# to understand what's going on here this way
if notstarted:
if event.allday and event.start < original_start.date():
continue
elif not event.allday and event.start_local < original_start:
if (
event.allday
and event.start < original_start.date()
or not event.allday
and event.start_local < original_start
):
continue
if seen is not None and event.uid in seen:
continue
Expand Down Expand Up @@ -659,9 +662,12 @@ def edit(collection, search_string, locale, format=None, allow_past=False, conf=
events = sorted(collection.search(search_string))
for event in events:
if not allow_past:
if event.allday and event.end < now.date():
continue
elif not event.allday and event.end_local < now:
if (
event.allday
and event.end < now.date()
or not event.allday
and event.end_local < now
):
continue
event_text = textwrap.wrap(
human_formatter(format)(event.attributes(relative_to=now)), term_width
Expand Down
2 changes: 1 addition & 1 deletion khal/khalendar/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def at_once(self) -> Iterator["SQLiteDb"]:
def _create_dbdir(self) -> None:
"""create the dbdir if it doesn't exist"""
if self.db_path == ":memory:":
return None
return
dbdir = self.db_path.rsplit("/", 1)[0]
if not path.isdir(dbdir):
try:
Expand Down
6 changes: 2 additions & 4 deletions khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ def ensure_date(self, day: dt.date) -> None:

def days_to_next_already_loaded(self, day: dt.date) -> int:
"""return number of days until `day` is already loaded into the CalendarWidget"""
if len(self) == 0:
return 0
elif self[0].date <= day <= self[-1].date:
if len(self) == 0 or self[0].date <= day <= self[-1].date:
return 0
elif day <= self[0].date:
return (self[0].date - day).days
Expand Down Expand Up @@ -891,7 +889,7 @@ def duplicate(self) -> None:
# which are also copied. If the events' summary is edited it will show
# up on disk but not be displayed in khal
if self.focus_event is None:
return None
return
event = self.focus_event.event.duplicate()
try:
self.pane.collection.insert(event)
Expand Down
4 changes: 1 addition & 3 deletions khal/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def is_top_level(self):

def on_key_press(self, key):
"""Handle application-wide key strokes."""
if key in self.quit_keys:
self.backtrack()
elif key == "esc" and not self.is_top_level():
if key in self.quit_keys or key == "esc" and not self.is_top_level():
self.backtrack()
return key

Expand Down
16 changes: 8 additions & 8 deletions khal/ui/calendarwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def set_focus_date(self, a_date: dt.date) -> None:
for num, day in enumerate(self.contents[1:8], 1):
if day[0].date == a_date:
self.focus_position = num
return None
return
raise ValueError(f"{a_date} not found in this week")

def get_date_column(self, a_date: dt.date) -> int:
Expand Down Expand Up @@ -415,9 +415,7 @@ def set_focus(self, position: int) -> None:

def days_to_next_already_loaded(self, day: dt.date) -> int:
"""return the number of weeks from the focus to the next week that is already loaded"""
if len(self) == 0:
return 0
elif self.earliest_date <= day <= self.latest_date:
if len(self) == 0 or self.earliest_date <= day <= self.latest_date:
return 0
elif day <= self.earliest_date:
return (self.earliest_date - day).days
Expand Down Expand Up @@ -529,10 +527,12 @@ def _construct_week(self, week: list[dt.date]) -> DateCColumns:
:param week: list of datetime.date objects
:returns: the week as an CColumns object
"""
if self.monthdisplay == "firstday" and 1 in (day.day for day in week):
month_name = calendar.month_abbr[week[-1].month].ljust(4)
attr = "monthname"
elif self.monthdisplay == "firstfullweek" and week[0].day <= 7:
if (
self.monthdisplay == "firstday"
and 1 in (day.day for day in week)
or self.monthdisplay == "firstfullweek"
and week[0].day <= 7
):
month_name = calendar.month_abbr[week[-1].month].ljust(4)
attr = "monthname"
elif self.weeknumbers == "left":
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from icalendar.parser import Contentlines # icalendar >= 7.0.0
except ImportError:
from icalendar.cal import Contentlines # icalendar < 7.0.0 # noqa: F401
from icalendar.cal import Contentlines # icalendar < 7.0.0


CollVdirType = tuple[CalendarCollection, dict[str, Vdir]]
Expand Down
8 changes: 3 additions & 5 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ def test_relative_timedelta_str():
assert utils.relative_timedelta_str(dt.date(2016, 7, 29)) == "~7 weeks ago"


weekheader = """ Mo Tu We Th Fr Sa Su """
today_line = """Today"""
calendarline = (
"Nov 31  1  2  3  4  5  6"
)
weekheader = """\x1b[1m Mo Tu We Th Fr Sa Su \x1b[0m"""
today_line = """\x1b[1mToday\x1b[0m\x1b[0m"""
calendarline = "\x1b[1mNov \x1b[0m\x1b[1;33m31\x1b[0m \x1b[32m 1\x1b[0m \x1b[1;33m 2\x1b[0m \x1b[1;33m 3\x1b[0m \x1b[1;33m 4\x1b[0m \x1b[32m 5\x1b[0m \x1b[32m 6\x1b[0m"


def test_last_reset():
Expand Down
Loading