diff --git a/.bumpversion.cfg b/.bumpversion.cfg index c0cde74..75d63ca 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -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\d+)\.(?P\d+)\.(?P\d+)(-(?Prc)\.(?P\d+))? @@ -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}" diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 611d709..f0c08df 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -4,6 +4,7 @@ on: push: branches: - dev + - main pull_request: jobs: @@ -34,5 +35,5 @@ jobs: - name: Run tests run: pytest - - name: Complete messsge + - name: Complete message run: echo "unit tests completed" diff --git a/README.md b/README.md index 77b999f..a2599e7 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/pyproject.toml b/pyproject.toml index e731bd1..33dc0f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/utt/plugins/project_summary.py b/src/utt/plugins/project_summary.py index bc24041..9b4bae2 100644 --- a/src/utt/plugins/project_summary.py +++ b/src/utt/plugins/project_summary.py @@ -9,6 +9,8 @@ from utt.api import _v1 +DEFAULT_CURRENT_ACTIVITY_NAME = "-- Current Activity --" + if TYPE_CHECKING: from collections.abc import Sequence @@ -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.""" @@ -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.""" @@ -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) @@ -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: @@ -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", @@ -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", diff --git a/src/utt_project_summary/__init__.py b/src/utt_project_summary/__init__.py index c0b911f..ff3bfb2 100644 --- a/src/utt_project_summary/__init__.py +++ b/src/utt_project_summary/__init__.py @@ -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" diff --git a/tests/test_project_summary.py b/tests/test_project_summary.py index e8b059f..33e3971 100644 --- a/tests/test_project_summary.py +++ b/tests/test_project_summary.py @@ -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)