Skip to content

Commit

Permalink
chore(release): version 2.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkasa committed Dec 2, 2024
2 parents a379e67 + faa2248 commit 45d64f6
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 109 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ulauncher_toggl_extension.utils import ensure_import

ensure_import("toggl_api", "toggl-api-wrapper", "1.4.0")
ensure_import("toggl_api", "toggl-api-wrapper", "1.5.1")

from ulauncher_toggl_extension.extension import TogglExtension # noqa: E402

Expand Down
186 changes: 108 additions & 78 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ulauncher-toggl-extension"
version = "2.8.3"
version = "2.8.4"
description = "Toggl time tracker extension for Ulauncher."
authors = ["David Kasakaitis <davidkasakaitis@proton.me>"]
readme = "README.md"
Expand Down
19 changes: 18 additions & 1 deletion tests/test_commands/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ulauncher_toggl_extension.commands.meta import Command, SubCommand
from ulauncher_toggl_extension.commands.project import ProjectCommand
from ulauncher_toggl_extension.commands.tag import TagCommand
from ulauncher_toggl_extension.commands.tracker import TrackerCommand
from ulauncher_toggl_extension.commands.tracker import EditCommand, TrackerCommand


@pytest.mark.unit
Expand Down Expand Up @@ -110,3 +110,20 @@ def _min_alias_length(command: type[Command], done: set[type[Command]]) -> bool:
def test_alias_length():
commands = set()
assert _min_alias_length(Command, commands)


@pytest.mark.unit
@pytest.mark.parametrize(
("query"),
[
("tgl", "edit"),
("tgl", "project"),
("tgl", "continue"),
],
)
def test_amend_query(dummy_ext, query):
cmd = EditCommand(dummy_ext)

query = list(query)
cmd.amend_query(query)
assert query == ["tgl", cmd.PREFIX]
2 changes: 1 addition & 1 deletion ulauncher_toggl_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.8.3"
__version__ = "2.8.4"
5 changes: 3 additions & 2 deletions ulauncher_toggl_extension/commands/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ def _paginator(
def amend_query(self, query: list[str]) -> None:
if not query:
query.append(self.PREFIX)
elif query[0] != self.PREFIX:
query[0] = self.PREFIX

elif len(query) >= 2 and query[1] != self.PREFIX: # noqa: PLR2004
query[1] = self.PREFIX

def notification(
self,
Expand Down
6 changes: 1 addition & 5 deletions ulauncher_toggl_extension/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ def _fetch_break_down(self, span: DateTimeFrame, **query) -> list[dict]:
include_time_entry_ids=False,
)
trackers: list[dict] = []
endpoint = DetailedReportEndpoint(
self.workspace_id,
self.auth,
include_time_entry_ids=False,
)
endpoint = DetailedReportEndpoint(self.workspace_id, self.auth)
search = self._break_down_helper(endpoint, body, trackers)

while (
Expand Down
6 changes: 5 additions & 1 deletion ulauncher_toggl_extension/date_time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import enum
from calendar import monthrange
from dataclasses import dataclass, field
from datetime import date, datetime, timedelta, timezone
from functools import cache
Expand Down Expand Up @@ -132,6 +133,7 @@ def localize_timezone(ts: datetime) -> datetime:


def get_caps(date_obj: date, frame: TimeFrame) -> tuple[datetime, datetime]:
"""Helper function that gets a target time frame for querying an filtering."""
if isinstance(date_obj, datetime):
date_obj = date_obj.date()

Expand Down Expand Up @@ -164,8 +166,10 @@ def get_caps(date_obj: date, frame: TimeFrame) -> tuple[datetime, datetime]:
datetime.min.time(),
tzinfo=timezone.utc,
)

_, day = monthrange(date_obj.year, date_obj.month)
stop = datetime.combine(
date(date_obj.year, (date_obj.month % 12) + 1, 1) - timedelta(days=1),
date(date_obj.year, date_obj.month, day),
datetime.max.time(),
tzinfo=timezone.utc,
)
Expand Down
46 changes: 27 additions & 19 deletions ulauncher_toggl_extension/extension.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# ruff: noqa: E402
from __future__ import annotations

import contextlib
import logging
from collections import OrderedDict
from pathlib import Path
from typing import TYPE_CHECKING, Callable, Final, Iterable, Optional
from typing import TYPE_CHECKING, Callable, Final, Iterable, Optional, cast

from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.client.Extension import Extension
Expand Down Expand Up @@ -199,33 +198,42 @@ def match_query(
) -> bool:
return get_score(query, target) >= threshold

def match_results(
self,
query: Query,
**kwargs,
) -> list[QueryResults]:
def match_results(self, query: Query, max_results: int = 5) -> list[QueryResults]:
"""Fuzzy matches query terms against a dictionary of functions using
the `match_query` method.
Will ignore any other parameters supplied with *_ parameters.
Args:
match_dict(dict): Dictionary of functions to match against.
Will only display the first result of each viwer method.
query (str): Query term to match against.
query: Query term to match against.
max_results: Max results to match for. Soft edge as the method will
let through previews with more than result through.
Returns:
list: List of possible matches that are produced by matched
functions.
List of possible matches that are produced by matched functions.
"""
results: list[QueryResults] = []
for trg, fn in self.COMMANDS.items():
if self.match_query(query.raw_args[0], trg):
cmd = fn(self)
with contextlib.suppress(IndexError):
results.append(cmd.preview(query, **kwargs)[0])
if query.command is None:
return self.default_results(query)

raw_results = list(self.COMMANDS.values())
raw_results.sort(
key=lambda x: self.match_query(
cast(str, query.command),
x.PREFIX,
),
)

return results or self.default_results(query, **kwargs)
results = []
i = 0
for result in raw_results:
preview = result(self).preview(query)
if preview:
results.extend(preview)
i += len(preview)
if i >= max_results:
break

return results

def create_action(
self,
Expand Down

0 comments on commit 45d64f6

Please sign in to comment.