From 5843727d476c7e06a7cd6c3779b7a1df18045ba2 Mon Sep 17 00:00:00 2001 From: Tomas Peterka Date: Mon, 26 Feb 2024 14:38:23 +0100 Subject: [PATCH] fix: support both YAML extensions: .yml and .yaml --- README.md | 15 ++++++++++----- gira/config.py | 14 +------------- gira/deps.py | 6 +++--- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5e3a73c..be8d4e8 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ Gira reacts to changes in your dependency files and bring you JIRA tickets mentioned in commits between current and updated version of the dependencies. Supported dependency files are - pyproject.toml -- west.yaml -- pubspec.yaml +- 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 ` __Pssst__: works the best if your dependencies follow [semantic release](https://semantic-release.gitbook.io/semantic-release/) thus have tags in `vX.Y.*` format. -## Usage +## Usage - standalone ```bash gira [-r revision] [-c config] [--format="commit|detail|markdown"] @@ -30,13 +30,18 @@ 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. -## Pre-commit +## Usage - Pre-commit + +```bash +$ pip install pre-commit +$ pre-commit install -t prepare-commit-msg -t pre-commit -t commit-msg +``` Add to your .pre-commit-config.yaml ```yaml - repo: https://github.com/dronetag/gira - rev: v1.0.0 + rev: v1.0.1 hooks: - id: gira # if you use other config than .gira.yaml then diff --git a/gira/config.py b/gira/config.py index 7d0ad12..8e89833 100644 --- a/gira/config.py +++ b/gira/config.py @@ -44,9 +44,7 @@ def _parse_file(path: Path) -> Config: config = _conf(path) elif path.name == "pyproject.toml": config = _pytoml(path) - elif path.name.startswith("west"): - config = _west(path) - elif path.name.endswith(".yaml"): + elif path.suffix in (".yaml", ".yml"): config = _generic_yaml(path) if not config.observe: raise RuntimeError(f"No observed dependencies configured in {path}") @@ -75,16 +73,6 @@ def _generic_yaml(path: Path) -> Config: return Config(jira=_section(parsed, "gira.jira"), observe=_section(parsed, "gira.observe")) -def _west(path: Path) -> Config: - parsed = yaml.load(path.read_text(), Loader=yaml.SafeLoader) - jira = _section(parsed, "manifest.gira.jira") - observe = _section(parsed, "manifest.gira.observe") - return Config( - jira=jira, - observe=observe, - ) - - def _section(d: Optional[dict], path: str) -> dict: """Return dot-separated path from dictionary""" for key in path.split("."): diff --git a/gira/deps.py b/gira/deps.py index 1a1956a..a18e512 100644 --- a/gira/deps.py +++ b/gira/deps.py @@ -13,7 +13,7 @@ from . import logger version_re = re.compile(r"""([0-9]+\.[0-9]+[^"',]*)""") -parseable_filenames = ("pyproject.toml", "pubspec.yaml", "west.yaml") +parseable_filenames = ("pyproject.toml", "pubspec.yaml", "pubspec.yml", "west.yaml", "west.yml") def parseable(filepath: Path) -> bool: @@ -24,9 +24,9 @@ def parseable(filepath: Path) -> bool: def parse(path: Path, content: str, observed: dict[str, str]) -> dict[str, str]: if path.name == "pyproject.toml": return parse_pytoml(content, observed) - if path.name == "pubspec.yaml": + if path.name in ("pubspec.yaml", "pubspec.yml"): return parse_pubspec_yaml(content, observed) - if path.name == "west.yaml": + if path.name in ("west.yaml", "west.yml"): return parse_west_yaml(content, observed) raise NotImplementedError(f"No dependency parser for {path.name}")