From 464230aaef49cb1b2a50710797d20838ffb26a78 Mon Sep 17 00:00:00 2001 From: Tomas Peterka Date: Thu, 2 May 2024 11:23:12 +0200 Subject: [PATCH] chore: fix docs and annotations and permissions --- README.md | 8 ++++---- gira/core.py | 8 +++++++- gira/deps.py | 11 ++++++----- gira/formatter.py | 13 +++++++------ gira/gira.py | 4 ++-- gira/jira.py | 2 +- run_tests.sh | 0 7 files changed, 27 insertions(+), 19 deletions(-) mode change 100644 => 100755 run_tests.sh diff --git a/README.md b/README.md index be8d4e8..6d8c2f8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Gira reacts to changes in your dependency files and bring you JIRA tickets menti - west.yaml/yml - pubspec.yaml/yml -Gira is especially usefull with [pre-commit](https://pre-commit.com) but is great for changelog enhancements when called as `gira --format markdown -r ` +Gira is especially useful with [pre-commit](https://pre-commit.com) but is great for changelog enhancements when called as `gira --format markdown -r ` __Pssst__: works the best if your dependencies follow [semantic release](https://semantic-release.gitbook.io/semantic-release/) thus have tags in `vX.Y.*` format. @@ -24,8 +24,8 @@ commit messages. The markdown version is intended for changelogs. ```bash $ gira [--format=commit] -internal-dependency1 => : JIRA-123, JIRA-567 -other-followed-lib => : JIRA-876, JIRA-543 +internal-dependency1 => : JIRA-123, JIRA-567 +other-followed-lib => : JIRA-876, JIRA-543 ``` Config file is by default _.gira.yaml_ but can be pretty much any YAML or pyproject.toml. See section bellow. @@ -94,7 +94,7 @@ as follows: ```bash $ gira -internal-dependency1 => : +internal-dependency1 => : JIRA-123: details about the issue (url) JIRA-567: details about the issue (url) ``` diff --git a/gira/core.py b/gira/core.py index 65670c8..9a4073d 100644 --- a/gira/core.py +++ b/gira/core.py @@ -35,7 +35,13 @@ class Upgrade: new_version: Optional[str] messages: Optional[list[str]] - def __init__(self, name, old_version=None, new_version=None, messages=None): + def __init__( + self, + name: str, + old_version: Optional[str] = None, + new_version: Optional[str] = None, + messages=None, + ): self.name = name self.old_version = old_version self.new_version = new_version diff --git a/gira/deps.py b/gira/deps.py index a18e512..41ce8c8 100644 --- a/gira/deps.py +++ b/gira/deps.py @@ -1,4 +1,5 @@ -"""Dependencies module reads different """ +"""Dependencies module reads different""" + import re import sys @@ -13,12 +14,12 @@ from . import logger version_re = re.compile(r"""([0-9]+\.[0-9]+[^"',]*)""") -parseable_filenames = ("pyproject.toml", "pubspec.yaml", "pubspec.yml", "west.yaml", "west.yml") +parsable_filenames = ("pyproject.toml", "pubspec.yaml", "pubspec.yml", "west.yaml", "west.yml") -def parseable(filepath: Path) -> bool: +def parsable(filepath: Path) -> bool: """Extract changes in observed dependencies from dependency/lock files diffs""" - return filepath.name in parseable_filenames + return filepath.name in parsable_filenames def parse(path: Path, content: str, observed: dict[str, str]) -> dict[str, str]: @@ -36,7 +37,7 @@ def parse_pytoml(content: str, observed: dict[str, str]) -> dict[str, str]: parsed = toml.loads(content) if _section(parsed, "project.dependencies"): - """Parse standart pytoml dependencies definition + """Parse standard pytoml dependencies definition Example: [project] diff --git a/gira/formatter.py b/gira/formatter.py index c5789cc..fab3aa2 100644 --- a/gira/formatter.py +++ b/gira/formatter.py @@ -1,4 +1,5 @@ -from typing import Iterable, TextIO +from abc import ABC +from typing import Iterable, Optional, TextIO from .core import Upgrade from .jira import Ticket @@ -14,20 +15,20 @@ def get_formatter(name: str, stream: TextIO): raise ValueError(f"Unknown format {name}") -class Formatter: +class Formatter(ABC): needs_details: bool def __init__(self, stream: TextIO): self._stream = stream - def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]): - raise NotImplementedError() + def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]) -> None: + """Write textual representation of the upgrade and tickets to the internal stream.""" class CommitFormatter(Formatter): needs_details = False - def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]): + def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]) -> None: chars = 0 sep = " " self._stream.write("\n") @@ -35,7 +36,7 @@ def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]): if chars > 70: chars = self._stream.write("\n ") - def _s(s): # shorten + def _s(s: Optional[str]) -> Optional[str]: # shorten return s[:7] if s and len(s) > 10 else s chars += self._stream.write(f"({_s(upgrade.old_version)} -> {_s(upgrade.new_version)})") diff --git a/gira/gira.py b/gira/gira.py index 1b3fd9a..3ac440b 100644 --- a/gira/gira.py +++ b/gira/gira.py @@ -17,7 +17,7 @@ def gira(config: config.Config, stream: TextIO, format: str, ref: Optional[str]) # extract changes from diffs of locks or other dependency specifying files upgrades: list[core.Upgrade] = [] - for file in filter(deps.parseable, files): + for file in filter(deps.parsable, files): logger.debug(f"Processing {file} for dependencies") pre = deps.parse(file, repository.get_old_content(file), config.observe) post = deps.parse(file, repository.get_current_content(file), config.observe) @@ -68,7 +68,7 @@ def gira(config: config.Config, stream: TextIO, format: str, ref: Optional[str]) f" {upgrade.old_version}: {upgrade.messages}" ) tickets = {ticket for m in upgrade.messages for ticket in jira.extract_ticket_names(m)} - + logger.debug(f"Extracted tickets: {tickets}") if len(tickets) == 0: logger.info( f"No JIRA tickets found in commits for {upgrade.name} between" diff --git a/gira/jira.py b/gira/jira.py index 7919758..ec8365c 100644 --- a/gira/jira.py +++ b/gira/jira.py @@ -22,7 +22,7 @@ class Ticket: url: str summary: str - def __init__(self, name, url="", summary=""): + def __init__(self, name: str, url: str = "", summary: str = ""): self.name = name self.url = url self.summary = summary diff --git a/run_tests.sh b/run_tests.sh old mode 100644 new mode 100755