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.3.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.16.2'
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

try:
# Available from configobj 5.1.0
import configobj.validate as validate
from configobj import validate
except ModuleNotFoundError:
import validate

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
8 changes: 0 additions & 8 deletions khal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
class Error(Exception):
"""base class for all of khal's Exceptions"""

pass


class FatalError(Error):
"""execution cannot continue"""

pass


class DateTimeParseError(FatalError):
pass
Expand All @@ -43,14 +39,10 @@ class ConfigurationError(FatalError):
class UnsupportedFeatureError(Error):
"""something Failed but we know why"""

pass


class UnsupportedRecurrence(Error):
"""raised if the RRULE is not understood by dateutil.rrule"""

pass


class InvalidDate(Error):
pass
2 changes: 1 addition & 1 deletion khal/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def split_ics(ics: str, random_uid: bool = False, default_timezone=None) -> list
try:
ics = ics_from_list(events, tzs, random_uid, default_timezone)
except Exception as exception:
logger.warn(f"Error when trying to import the event {uid}")
logger.warning(f"Error when trying to import the event {uid}")
saved_exception = exception
else:
out.append(ics)
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
2 changes: 1 addition & 1 deletion khal/khalendar/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def fromVEvents(
vevents["PROTO"] = event

if ref is None:
ref = "PROTO" if ref in vevents.keys() else list(vevents.keys())[0]
ref = "PROTO" if ref in vevents else list(vevents.keys())[0]
try:
if type(vevents[ref]["DTSTART"].dt) is not type(vevents[ref]["DTEND"].dt):
raise ValueError("DTSTART and DTEND should be of the same type (datetime or date)")
Expand Down
4 changes: 2 additions & 2 deletions khal/parse_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def datetimefstr(
for _ in range(parts):
item = dtime_list.pop(0)
if " " in item:
logger.warn("detected a space in datetime specification, this can lead to errors.")
logger.warn("Make sure not to quote your datetime specification.")
logger.warning("detected a space in datetime specification, this can lead to errors.")
logger.warning("Make sure not to quote your datetime specification.")

if infer_year:
dtstart = dt.datetime(*(default_day.timetuple()[:1] + dtstart_struct[1:5]))
Expand Down
2 changes: 0 additions & 2 deletions khal/settings/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
class InvalidSettingsError(Error):
"""Invalid Settings detected"""

pass


class CannotParseConfigFileError(InvalidSettingsError):
pass
Expand Down
2 changes: 1 addition & 1 deletion khal/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_timedelta(string: str) -> dt.timedelta:
raise VdtValueError(f"Invalid timedelta: {string}")


def weeknumber_option(option: str) -> Literal["left", "right"] | Literal[False]:
def weeknumber_option(option: str) -> Literal["left", "right", False]:
"""checks if *option* is a valid value

:param option: the option the user set in the config file
Expand Down
16 changes: 7 additions & 9 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 Expand Up @@ -1303,17 +1301,17 @@ def _urwid_palette_entry(
colors = {}
# Colorcube
colorlevels = (0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF)
for r in range(0, 6):
for g in range(0, 6):
for b in range(0, 6):
for r in range(6):
for g in range(6):
for b in range(6):
colors[r * 36 + g * 6 + b + 16] = (
colorlevels[r],
colorlevels[g],
colorlevels[b],
)
# Grayscale
graylevels = [0x08 + 10 * i for i in range(0, 24)]
for c in range(0, 24):
graylevels = [0x08 + 10 * i for i in range(24)]
for c in range(24):
colors[232 + c] = (graylevels[c],) * 3
# Parse the HTML-style color into the variables r, g, b.
if len(color) == 4:
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
4 changes: 2 additions & 2 deletions khal/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _select_last_selectable(self):

def _first_selectable(self):
"""return sequence number of self.contents last selectable item"""
for j in range(0, len(self._contents)):
for j in range(len(self._contents)):
if self._contents[j][0].selectable():
return j
return False
Expand Down Expand Up @@ -373,7 +373,7 @@ def _select_last_selectable(self):

def _first_selectable(self):
"""return sequence number of self._contents last selectable item"""
for j in range(0, len(self.body)):
for j in range(len(self.body)):
if self.body[j].selectable():
return j
return False
Expand Down
24 changes: 12 additions & 12 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_notstarted(runner):
result = runner.invoke(main_khal, command.split())
assert not result.exception

result = runner.invoke(main_khal, "list now".split())
result = runner.invoke(main_khal, ["list", "now"])
assert (
result.output
== """Today, 01.06.2015
Expand All @@ -232,7 +232,7 @@ def test_notstarted(runner):
"""
)
assert not result.exception
result = runner.invoke(main_khal, "list now --notstarted".split())
result = runner.invoke(main_khal, ["list", "now", "--notstarted"])
assert (
result.output
== """Today, 01.06.2015
Expand All @@ -246,7 +246,7 @@ def test_notstarted(runner):
)
assert not result.exception

result = runner.invoke(main_khal, "list now --once".split())
result = runner.invoke(main_khal, ["list", "now", "--once"])
assert (
result.output
== """Today, 01.06.2015
Expand All @@ -260,7 +260,7 @@ def test_notstarted(runner):
)
assert not result.exception

result = runner.invoke(main_khal, "list now --once --notstarted".split())
result = runner.invoke(main_khal, ["list", "now", "--once", "--notstarted"])
assert (
result.output
== """Today, 01.06.2015
Expand Down Expand Up @@ -346,9 +346,9 @@ def test_default_command_empty(runner):

def test_invalid_calendar(runner):
runner = runner(days=2)
result = runner.invoke(main_khal, ["new"] + "-a one 18:00 myevent".split())
result = runner.invoke(main_khal, ["new"] + ["-a", "one", "18:00", "myevent"])
assert not result.exception
result = runner.invoke(main_khal, ["new"] + "-a inexistent 18:00 myevent".split())
result = runner.invoke(main_khal, ["new"] + ["-a", "inexistent", "18:00", "myevent"])
assert result.exception
assert result.exit_code == 2
assert "Unknown calendar " in result.output
Expand Down Expand Up @@ -586,7 +586,7 @@ def test_search_json(runner):

def test_no_default_new(runner):
runner = runner(default_calendar=False)
result = runner.invoke(main_khal, "new 18:00 beer".split())
result = runner.invoke(main_khal, ["new", "18:00", "beer"])
assert (
"Error: Invalid value: No default calendar is configured, please provide one explicitly."
) in result.output
Expand All @@ -604,7 +604,7 @@ def test_print_bad_ics(runner):

def test_import(runner, monkeypatch):
runner = runner()
result = runner.invoke(main_khal, "import -a one -a two import file.ics".split())
result = runner.invoke(main_khal, ["import", "-a", "one", "-a", "two", "import", "file.ics"])
assert result.exception
assert result.exit_code == 2
assert 'Can\'t use "--include-calendar" / "-a" more than once' in result.output
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def test_edit(runner):
def test_new(runner):
runner = runner(print_new="path")

result = runner.invoke(main_khal, "new 13.03.2016 3d Visit".split())
result = runner.invoke(main_khal, ["new", "13.03.2016", "3d", "Visit"])
assert not result.exception
assert result.output.endswith(".ics\n")
assert result.output.startswith(str(runner.tmpdir))
Expand Down Expand Up @@ -1059,7 +1059,7 @@ def test_new_json(runner):
def test_new_interactive(runner):
runner = runner(print_new="path")

result = runner.invoke(main_khal, "new -i".split(), "Another event\n13:00 17:00\n\nNone\nn\n")
result = runner.invoke(main_khal, ["new", "-i"], "Another event\n13:00 17:00\n\nNone\nn\n")
assert not result.exception
assert result.exit_code == 0

Expand All @@ -1079,7 +1079,7 @@ def test_new_interactive_extensive(runner):

result = runner.invoke(
main_khal,
"new -i 15:00 15:30".split(),
["new", "-i", "15:00", "15:30"],
"?\ninvalid\ntwo\n"
"Unicce Name\n"
"\n"
Expand All @@ -1105,7 +1105,7 @@ def test_issue_1056(runner):

result = runner.invoke(
main_khal,
"new -i".split(),
["new", "-i"],
"two\n"
"new event\n"
"now\n"
Expand Down
Loading
Loading