Skip to content

Commit

Permalink
chore(release): version 2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkasa committed Oct 16, 2024
2 parents 7a4b1e1 + 04e17e6 commit 2242b9c
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 489 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
3. Editing tags.
4. Deleting tags.

# Development
# Contributing

See [DEVELOPMENT](docs/DEVELOPMENT.md).
See [CONTRIBUTING](docs/CONTRIBUTING.md).

# License

Expand Down
50 changes: 50 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Development

### Basic Environment

- Development is run through Poetry

1. `git clone https://github.com/ddkasa/ulauncher-toggl-extension`
2. `cd toggl-api-wrapper`
3. `$ poetry shell`
4. `$ poetry install`

- Lint with `ruff ulauncher_toggl_extension`
- Check typing with `mypy ulauncher_toggl_extension`
- Make sure to install pre-commit hook with `pre-commit install`

- In order to debug/test the extension inside Ulauncher:

1. Move extension into this folder:

```
~/.local/share/ulauncher/extensions/
```

2. Run:

```bash
VERBOSE=1 ULAUNCHER_WS_API=ws://127.0.0.1:5054/ulauncher-toggl-extension PYTHONPATH=/usr/lib/python3.12/site-packages /usr/bin/python3 /home/dk/.local/share/ulauncher/extensions/ulauncher-toggl-extension/main.py
```

### Testing

- All tests are run through `pytest`
- Basic unit tests through `pytest -m unit`
- Integration tests through `pytest -m integration`
- For multiple python versions run: `tox`

### Deployment

- Merge with **production** branch
- Make sure to add new development files to the _.gitattributes_ file

### Git

- Commit messages are based on [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)

### Notes

- More information on extension development [here](https://docs.ulauncher.io/en/stable/extensions/intro.html)
- Additional system dependencies may need to be installed.
- If on Fedora [this](https://gitlab.gnome.org/alicem/jhbuild-steps/-/wikis/JHBuild-on-Fedora) might be required
30 changes: 0 additions & 30 deletions docs/DEVELOPMENT.md

This file was deleted.

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", "0.3.1")
ensure_import("toggl_api", "toggl-api-wrapper", "1.0.1")

from ulauncher_toggl_extension.extension import TogglExtension # noqa: E402

Expand Down
546 changes: 189 additions & 357 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tool.poetry]
name = "ulauncher-toggl-extension"
version = "2.4.0"
version = "2.4.1"
description = "Toggl time tracker extension for Ulauncher."
authors = ["David Kasakaitis <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
toggl-api-wrapper = "^0.3.0"
pycairo = "^1.26.1"
pygobject = "^3.48.2"
toggl-api-wrapper = "^1.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.4"
Expand Down
10 changes: 9 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta
import os
import time
from dataclasses import dataclass
from datetime import timedelta
from pathlib import Path

import pytest
Expand All @@ -11,6 +12,13 @@
from ulauncher_toggl_extension.date_time import get_local_tz


@pytest.fixture(autouse=True)
def _rate_limit(request):
yield
if "integration" in request.keywords:
time.sleep(1)


@pytest.fixture(autouse=True)
def _patch_noti(monkeypatch):
def mocked_notif():
Expand Down
28 changes: 27 additions & 1 deletion tests/test_commands/test_tracker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import time
from datetime import datetime
from pathlib import Path

import pytest
from toggl_api import TogglTracker
from toggl_api import JSONCache, TogglTracker, TrackerEndpoint

from ulauncher_toggl_extension.commands import (
AddCommand,
ContinueCommand,
CurrentTrackerCommand,
DeleteCommand,
EditCommand,
ListCommand,
Expand All @@ -28,6 +31,29 @@ def test_continue_command(dummy_ext, create_tracker):
assert cmd.current_tracker().name == create_tracker.name


@pytest.mark.integration
@pytest.mark.slow
def test_current_command(
dummy_ext,
create_tracker,
auth,
workspace,
tmp_path,
):
cmd = CurrentTrackerCommand(dummy_ext)
assert cmd.get_current_tracker(refresh=True).id == create_tracker.id
endpoint = TrackerEndpoint(workspace, auth, JSONCache(Path(tmp_path)))
assert endpoint.stop(create_tracker).id == create_tracker.id

time.sleep(5)

assert cmd.get_current_tracker().id == create_tracker.id

time.sleep(5)

assert cmd.get_current_tracker() is None


@pytest.mark.integration
def test_list_command(dummy_ext):
cmd = ListCommand(dummy_ext)
Expand Down
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.4.0"
__version__ = "2.4.1"
62 changes: 47 additions & 15 deletions ulauncher_toggl_extension/commands/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from functools import partial
from typing import Optional

Expand All @@ -16,6 +17,8 @@

from .meta import QueryParameters, SubCommand

log = logging.getLogger(__name__)


class ClientCommand(SubCommand):
"""Subcommand for all client based tasks."""
Expand All @@ -27,7 +30,13 @@ class ClientCommand(SubCommand):

def get_models(self, **kwargs) -> list[TogglClient]:
endpoint = ClientEndpoint(self.workspace_id, self.auth, self.cache)
clients = endpoint.get_clients(refresh=kwargs.get("refresh", False))
try:
clients = endpoint.collect(refresh=kwargs.get("refresh", False))
except HTTPStatusError as err:
log.exception("%s")
self.notification(str(err))
return []

clients.sort(key=lambda x: x.timestamp, reverse=True)
return clients

Expand All @@ -41,11 +50,12 @@ def get_client(
return None
endpoint = ClientEndpoint(self.workspace_id, self.auth, self.cache)
try:
client = endpoint.get_client(client_id, refresh=refresh)
client = endpoint.get(client_id, refresh=refresh)
except HTTPStatusError as err:
if err.response.status_code == endpoint.NOT_FOUND:
return None
raise
log.exception("%s")
self.notification(str(err))
return None

return client


Expand Down Expand Up @@ -147,15 +157,20 @@ def handle(self, query: list[str], **kwargs) -> bool:
if not isinstance(name, str):
return False

body = ClientBody(
self.workspace_id,
name,
kwargs.get("status"),
kwargs.get("notes"),
)
body = ClientBody(name, kwargs.get("status"), kwargs.get("notes"))
endpoint = ClientEndpoint(self.workspace_id, self.auth, self.cache)
endpoint.create_client(body)

try:
client = endpoint.add(body)
except HTTPStatusError as err:
log.exception("%s")
self.notification(str(err))
return False

if not client:
return False

self.notification(msg=f"Created client {body.name}!")
return True


Expand Down Expand Up @@ -208,8 +223,15 @@ def handle(self, query: list[str], **kwargs) -> bool:
return False

endpoint = ClientEndpoint(self.workspace_id, self.auth, self.cache)
endpoint.delete_client(model)

try:
endpoint.delete(model)
except HTTPStatusError as err:
log.exception("%s")
self.notification(str(err))
return False

self.notification(msg=f"Deleted client {model}!")
return True


Expand Down Expand Up @@ -268,12 +290,22 @@ def handle(self, query: list[str], **kwargs) -> bool:
return False

body = ClientBody(
self.workspace_id,
name if isinstance(name, str) else None,
kwargs.get("status"),
kwargs.get("notes"),
)
endpoint = ClientEndpoint(self.workspace_id, self.auth, self.cache)
endpoint.update_client(model, body)

try:
client = endpoint.edit(model, body)
except HTTPStatusError as err:
log.exception("%s")
self.notification(str(err))
return False

if not client:
return False

self.notification(msg=f"Edited client {body.name}!")

return True
4 changes: 2 additions & 2 deletions ulauncher_toggl_extension/commands/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def notification(
show_notification(msg, self.ICON.absolute(), on_close=on_close)

@property
def cache(self) -> partial[JSONCache]:
return partial(JSONCache, self.cache_path, self.EXPIRATION)()
def cache(self) -> JSONCache:
return JSONCache(self.cache_path, self.EXPIRATION)

@classmethod
def check_autocmp(cls, query: list[str]) -> bool:
Expand Down
Loading

0 comments on commit 2242b9c

Please sign in to comment.