Skip to content
Merged
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 .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0-rc.1
current_version = 0.1.0-rc.2
commit = True
tag_name = v{new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>rc)\.(?P<build>\d+))?
Expand All @@ -21,6 +21,6 @@ first_value = 1
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:src/utt_balance/__init__.py]
[bumpversion:file:src/utt_project_summary/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
3 changes: 2 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- dev
- main
pull_request:

jobs:
Expand Down Expand Up @@ -34,5 +35,5 @@ jobs:
- name: Run tests
run: pytest

- name: Complete messsge
- name: Complete message
run: echo "unit tests completed"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# utt-project-summary

[![CI - Test](https://github.com/loganthomas/utt-project-summary/actions/workflows/unit-tests.yml/badge.svg?branch=main)](https://github.com/loganthomas/utt-project-summary/actions/workflows/unit-tests.yml)
[![PyPI Latest Release](https://img.shields.io/pypi/v/utt-project-summary.svg)](https://pypi.org/project/utt-project-summary/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/utt-project-summary.svg?label=PyPI%20downloads)](https://pypi.org/project/utt-project-summary/)
[![License - GPL-3.0](https://img.shields.io/pypi/l/utt-project-summary.svg)](https://github.com/loganthomas/utt-project-summary/blob/main/LICENSE)
[![Python Versions](https://img.shields.io/pypi/pyversions/utt-project-summary.svg)](https://pypi.org/project/utt-project-summary/)

A [`utt`](https://github.com/larose/utt) plugin that shows projects sorted by time spent.

## Why utt-project-summary?
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "utt-project-summary"
version = "0.1.0-rc.1"
version = "0.1.0-rc.2"
description = "A utt plugin to show projects sorted by time spent"
readme = "README.md"
license = "GPL-3.0-only"
Expand Down
40 changes: 29 additions & 11 deletions src/utt/plugins/project_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from utt.api import _v1

DEFAULT_CURRENT_ACTIVITY_NAME = "-- Current Activity --"

if TYPE_CHECKING:
from collections.abc import Sequence

Expand Down Expand Up @@ -85,10 +87,10 @@ def _aggregate_projects(self, activities: Sequence[_v1.Activity]) -> list[Projec

def _extract_current(self, activities: Sequence[_v1.Activity]) -> CurrentActivity | None:
"""Extract current activity if present."""
for activity in activities:
if activity.is_current_activity:
return CurrentActivity(activity.name.name, activity.duration)
return None
return next(
(CurrentActivity(a.name.name, a.duration) for a in activities if a.is_current_activity),
None,
)

def _compute_total(self) -> timedelta:
"""Sum all project durations plus current activity."""
Expand All @@ -101,9 +103,17 @@ def _compute_total(self) -> timedelta:
class ProjectSummaryView:
"""Render project summary output."""

def __init__(self, model: ProjectSummaryModel, show_perc: bool = False) -> None:
def __init__(
self,
model: ProjectSummaryModel,
show_perc: bool = False,
show_current: bool = True,
current_activity_name: str = DEFAULT_CURRENT_ACTIVITY_NAME,
) -> None:
self._model = model
self._show_perc = show_perc
self._show_current = show_current
self._current_activity_name = current_activity_name

def render(self, output: _v1.Output) -> None:
"""Render the project summary to output stream."""
Expand All @@ -128,13 +138,13 @@ def render(self, output: _v1.Output) -> None:
dur_str = f"{dur_str:<{max_dur_len}} ({perc:5.1f}%)"
print(f"{project.name:<{max_name_len}}: {dur_str}", file=output)

if self._model.current_activity:
if self._show_current and self._model.current_activity:
ca = self._model.current_activity
dur_str = ca.formatted
if self._show_perc and total_secs > 0:
perc = (ca.duration.total_seconds() / total_secs) * 100
dur_str = f"{dur_str} ({perc:5.1f}%)"
print(f"{ca.name:<{max_name_len}}: {dur_str}", file=output)
dur_str = f"{dur_str:<{max_dur_len}} ({perc:5.1f}%)"
print(f"{self._current_activity_name:<{max_name_len}}: {dur_str}", file=output)

print(file=output)
total_str = format_duration(self._model.total_duration)
Expand All @@ -160,7 +170,13 @@ def __init__(
def __call__(self) -> None:
"""Execute command."""
model = ProjectSummaryModel(self._activities)
ProjectSummaryView(model, self._args.show_perc).render(self._output)
view = ProjectSummaryView(
model,
show_perc=self._args.show_perc,
show_current=not self._args.no_current_activity,
current_activity_name=self._args.current_activity,
)
view.render(self._output)


def add_args(parser: argparse.ArgumentParser) -> None:
Expand All @@ -176,9 +192,9 @@ def add_args(parser: argparse.ArgumentParser) -> None:
)
parser.add_argument(
"--current-activity",
default="-- Current Activity --",
default=DEFAULT_CURRENT_ACTIVITY_NAME,
type=str,
help="Set the current activity",
help="Set the current activity name",
)
parser.add_argument(
"--no-current-activity",
Expand Down Expand Up @@ -224,6 +240,8 @@ def add_args(parser: argparse.ArgumentParser) -> None:
)


# Note: type: ignore needed because _v1.Command expects a specific handler protocol
# that differs from our implementation's signature (uses filtered_activities vs activities)
project_summary_command = _v1.Command(
name="project-summary",
description="Show projects sorted by time spent",
Expand Down
2 changes: 1 addition & 1 deletion src/utt_project_summary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""utt-project-summary: A utt plugin to show projects sorted by time spent."""

__version__ = "0.1.0-rc.1"
__version__ = "0.1.0-rc.2"
6 changes: 5 additions & 1 deletion tests/test_project_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ def test_handler_renders_output(self):
create_activity("backend: task1", datetime(2024, 1, 1, 9, 0), 120),
create_activity("frontend: task1", datetime(2024, 1, 1, 11, 0), 60),
]
args = argparse.Namespace(show_perc=False)
args = argparse.Namespace(
show_perc=False,
no_current_activity=False,
current_activity="-- Current Activity --",
)
output = io.StringIO()

handler = ProjectSummaryHandler(args, activities, output)
Expand Down