From 005e5828282e1efb40888162d24f4766531bb3ba Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 8 Nov 2023 17:39:29 +0200 Subject: [PATCH 1/3] Apply colour to HTML output --- src/norwegianblue/__init__.py | 24 ++++++++++++++++------- tests/data/expected_output.py | 36 +++++++++++++++++------------------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/norwegianblue/__init__.py b/src/norwegianblue/__init__.py index 5865f01..9b2ff16 100644 --- a/src/norwegianblue/__init__.py +++ b/src/norwegianblue/__init__.py @@ -82,8 +82,8 @@ def norwegianblue( return "\n".join(data) data = _ltsify(data) - if color != "no" and format not in ("html", "yaml"): - data = _colourify(data) + if color != "no" and format != "yaml": + data = _colourify(data, is_html=format == "html") output = _tabulate(data, format, color, product if show_title else None) logging.info("") @@ -117,7 +117,7 @@ def _ltsify(data: list[dict]) -> list[dict]: return data -def _colourify(data: list[dict]) -> list[dict]: +def _colourify(data: list[dict], *, is_html: bool = False) -> list[dict]: """Add colour to dates: red: in the past yellow: will pass in six months @@ -137,7 +137,10 @@ def _colourify(data: list[dict]) -> list[dict]: colour = "green" if cycle["support"] else "red" else: # "eol" and "discontinued" colour = "red" if cycle[property_] else "green" - cycle[property_] = colored(cycle[property_], colour) + + cycle[property_] = _apply_colour( + cycle[property_], colour, is_html=is_html + ) continue # Handle date @@ -147,14 +150,21 @@ def _colourify(data: list[dict]) -> list[dict]: tzinfo=dt.timezone.utc ) if date_datetime < now: - cycle[property_] = colored(date_str, "red") + cycle[property_] = _apply_colour(date_str, "red", is_html=is_html) elif date_datetime < six_months_from_now: - cycle[property_] = colored(date_str, "yellow") + cycle[property_] = _apply_colour(date_str, "yellow", is_html=is_html) else: - cycle[property_] = colored(date_str, "green") + cycle[property_] = _apply_colour(date_str, "green", is_html=is_html) return data +def _apply_colour(text: str, colour: str, *, is_html: bool = False) -> str: + if is_html: + return f'{text}' + + return colored(text, colour) + + def _tabulate( data: list[dict], format_: str = "markdown", color: str = "yes", title: str = None ) -> str: diff --git a/tests/data/expected_output.py b/tests/data/expected_output.py index 523225a..51913fe 100644 --- a/tests/data/expected_output.py +++ b/tests/data/expected_output.py @@ -19,8 +19,8 @@ Jammy Jellyfish 2022-04-21 22.04 - 2027-04-02 - 2032-04-01 + 2027-04-02 + 2032-04-01 https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/ @@ -28,8 +28,8 @@ Impish Indri 2021-10-14 21.10 - 2022-07-31 - 2022-07-31 + 2022-07-31 + 2022-07-31 https://wiki.ubuntu.com/ImpishIndri/ReleaseNotes/ @@ -37,8 +37,8 @@ Hirsute Hippo 2021-04-22 21.04 - 2022-01-20 - 2022-01-20 + 2022-01-20 + 2022-01-20 https://wiki.ubuntu.com/HirsuteHippo/ReleaseNotes/ @@ -46,8 +46,8 @@ Groovy Gorilla 2020-10-22 20.10 - 2021-07-22 - 2021-07-22 + 2021-07-22 + 2021-07-22 @@ -55,8 +55,8 @@ Focal Fossa 2020-04-23 20.04.4 - 2025-04-02 - 2030-04-01 + 2025-04-02 + 2030-04-01 @@ -64,8 +64,8 @@ Karmic Koala 2019-10-17 19.10 - 2020-07-06 - 2020-07-06 + 2020-07-06 + 2020-07-06 @@ -73,8 +73,8 @@ Bionic Beaver 2018-04-26 18.04.6 - 2023-04-02 - 2028-04-01 + 2023-04-02 + 2028-04-01 https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes @@ -82,8 +82,8 @@ Xenial Xerus 2016-04-21 16.04.7 - 2021-04-02 - 2026-04-01 + 2021-04-02 + 2026-04-01 @@ -91,8 +91,8 @@ Trusty Tahr 2014-04-17 14.04.6 - 2019-04-02 - 2024-04-01 + 2019-04-02 + 2024-04-01 From 115ced507853c48ea6fe2fb992a58cfeba743a8d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 8 Nov 2023 18:00:22 +0200 Subject: [PATCH 2/3] Update config --- .coveragerc | 5 +--- .pre-commit-config.yaml | 45 +++++++++++++---------------------- pyproject.toml | 27 +++++++++++++++++++-- tests/data/expected_output.py | 4 ++-- tox.ini | 8 ++++++- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/.coveragerc b/.coveragerc index 41f9a3e..396bbf5 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,10 +2,7 @@ [report] # Regexes for lines to exclude from consideration -exclude_lines = - # Have to re-enable the standard pragma: - pragma: no cover - +exclude_also = # Don't complain if non-runnable code isn't run: if __name__ == .__main__.: def main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 433802f..d801b2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,53 +1,37 @@ repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.14.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.4 hooks: - - id: pyupgrade - args: [--py38-plus] + - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.9.1 + rev: 23.11.0 hooks: - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - args: [--add-import=from __future__ import annotations] - - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - additional_dependencies: - [flake8-2020, flake8-errmsg, flake8-implicit-str-concat] - - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 - hooks: - - id: python-check-blanket-noqa - - id: python-no-log-warn - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-merge-conflict - id: check-json - id: check-toml - id: check-yaml - - id: requirements-txt-fixer + - id: debug-statements - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: trailing-whitespace + exclude: tests/data/expected_output.py - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.2.0 + rev: 1.4.1 hooks: - id: pyproject-fmt additional_dependencies: [tox] - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.14 + rev: v0.15 hooks: - id: validate-pyproject @@ -62,5 +46,10 @@ repos: - id: prettier args: [--prose-wrap=always, --print-width=88] + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + ci: autoupdate_schedule: quarterly diff --git a/pyproject.toml b/pyproject.toml index a0d71f8..e1eafae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,8 +65,31 @@ version.source = "vcs" [tool.hatch.version.raw-options] local_scheme = "no-local-version" -[tool.isort] -profile = "black" +[tool.ruff] +line-length = 88 +select = [ + "E", # pycodestyle errors + "EM", # flake8-errmsg + "F", # pyflakes errors + "I", # isort + "ISC", # flake8-implicit-str-concat + "PGH", # pygrep-hooks + "RUF100", # unused noqa (yesqa) + "UP", # pyupgrade + "W", # pycodestyle warnings + "YTT", # flake8-2020 + # "LOG", # TODO: enable flake8-logging when it's not in preview anymore +] +extend-ignore = [ + "E203", # Whitespace before ':' + "E221", # Multiple spaces before operator + "E226", # Missing whitespace around arithmetic operator + "E241", # Multiple spaces after ',' +] + +[tool.ruff.isort] +known-first-party = ["norwegianblue"] +required-imports = ["from __future__ import annotations"] [tool.pytest.ini_options] addopts = "--color=yes" diff --git a/tests/data/expected_output.py b/tests/data/expected_output.py index 51913fe..5d59486 100644 --- a/tests/data/expected_output.py +++ b/tests/data/expected_output.py @@ -188,7 +188,7 @@ "18.04 LTS","Bionic Beaver","2018-04-26","18.04.6","2023-04-02","2028-04-01","https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes" "16.04 LTS","Xenial Xerus","2016-04-21","16.04.7","2021-04-02","2026-04-01", "14.04 LTS","Trusty Tahr","2014-04-17","14.04.6","2019-04-02","2024-04-01", -""" # noqa: E501 W291 +""" EXPECTED_TSV = """ "cycle"\t"codename"\t"release"\t"latest"\t"support"\t"eol"\t"link" @@ -201,7 +201,7 @@ "18.04 LTS"\t"Bionic Beaver"\t"2018-04-26"\t"18.04.6"\t"2023-04-02"\t"2028-04-01"\t"https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes" "16.04 LTS"\t"Xenial Xerus"\t"2016-04-21"\t"16.04.7"\t"2021-04-02"\t"2026-04-01"\t "14.04 LTS"\t"Trusty Tahr"\t"2014-04-17"\t"14.04.6"\t"2019-04-02"\t"2024-04-01"\t -""" # noqa: E501 W291 +""" EXPECTED_MD_LOG4J = """ | cycle | release | latest | eol | diff --git a/tox.ini b/tox.ini index 2ec3900..f3d0116 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,13 @@ env_list = extras = tests commands = - {envpython} -m pytest --cov norwegianblue --cov tests --cov-report html --cov-report term --cov-report xml {posargs} + {envpython} -m pytest \ + --cov norwegianblue \ + --cov tests \ + --cov-report html \ + --cov-report term \ + --cov-report xml \ + {posargs} norwegianblue --version norwegianblue --help eol --version From 9524208c8575d0be12c974096620ae26e072e465 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 8 Nov 2023 18:23:11 +0200 Subject: [PATCH 3/3] Update help text --- README.md | 71 +++++++++++++++++++++------------------- src/norwegianblue/cli.py | 2 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index b7f2e69..05934c1 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ options: deprecated: use direct options instead: --html, --json, --md, --pretty, --rst, --csv, --tsv or --yaml. -c {yes,no,auto}, --color {yes,no,auto} - colour the terminal output (default: auto) + colour the output (default: auto) --clear-cache clear cache before running -v, --verbose print extra messages to stderr -V, --version show program's version number and exit @@ -98,11 +98,11 @@ run("eol", line_limit=5) ```console $ eol +akeneo-pim alibaba-dragonwell almalinux alpine -amazon-corretto -amazon-eks +amazon-cdk ... ``` @@ -116,21 +116,22 @@ run("norwegianblue python") ```console $ norwegianblue python -┌───────┬────────────┬─────────┬────────────────┬────────────┐ -│ cycle │ release │ latest │ latest release │ eol │ -├───────┼────────────┼─────────┼────────────────┼────────────┤ -│ 3.11 │ 2022-10-24 │ 3.11.4 │ 2023-06-06 │ 2027-10-24 │ -│ 3.10 │ 2021-10-04 │ 3.10.12 │ 2023-06-06 │ 2026-10-04 │ -│ 3.9 │ 2020-10-05 │ 3.9.17 │ 2023-06-06 │ 2025-10-05 │ -│ 3.8 │ 2019-10-14 │ 3.8.17 │ 2023-06-06 │ 2024-10-14 │ -│ 3.7 │ 2018-06-26 │ 3.7.17 │ 2023-06-05 │ 2023-06-27 │ -│ 3.6 │ 2016-12-22 │ 3.6.15 │ 2021-09-03 │ 2021-12-23 │ -│ 3.5 │ 2015-09-12 │ 3.5.10 │ 2020-09-05 │ 2020-09-13 │ -│ 3.4 │ 2014-03-15 │ 3.4.10 │ 2019-03-18 │ 2019-03-18 │ -│ 3.3 │ 2012-09-29 │ 3.3.7 │ 2017-09-19 │ 2017-09-29 │ -│ 2.7 │ 2010-07-03 │ 2.7.18 │ 2020-04-19 │ 2020-01-01 │ -│ 2.6 │ 2008-10-01 │ 2.6.9 │ 2013-10-29 │ 2013-10-29 │ -└───────┴────────────┴─────────┴────────────────┴────────────┘ +┌───────┬────────────┬─────────┬────────────────┬────────────┬────────────┐ +│ cycle │ release │ latest │ latest release │ support │ eol │ +├───────┼────────────┼─────────┼────────────────┼────────────┼────────────┤ +│ 3.12 │ 2023-10-02 │ 3.12.0 │ 2023-10-02 │ 2025-04-02 │ 2028-10-02 │ +│ 3.11 │ 2022-10-24 │ 3.11.6 │ 2023-10-02 │ 2024-04-01 │ 2027-10-24 │ +│ 3.10 │ 2021-10-04 │ 3.10.13 │ 2023-08-24 │ 2023-04-05 │ 2026-10-04 │ +│ 3.9 │ 2020-10-05 │ 3.9.18 │ 2023-08-24 │ 2022-05-17 │ 2025-10-05 │ +│ 3.8 │ 2019-10-14 │ 3.8.18 │ 2023-08-24 │ 2021-05-03 │ 2024-10-14 │ +│ 3.7 │ 2018-06-26 │ 3.7.17 │ 2023-06-05 │ 2020-06-27 │ 2023-06-27 │ +│ 3.6 │ 2016-12-22 │ 3.6.15 │ 2021-09-03 │ 2018-12-24 │ 2021-12-23 │ +│ 3.5 │ 2015-09-12 │ 3.5.10 │ 2020-09-05 │ False │ 2020-09-13 │ +│ 3.4 │ 2014-03-15 │ 3.4.10 │ 2019-03-18 │ False │ 2019-03-18 │ +│ 3.3 │ 2012-09-29 │ 3.3.7 │ 2017-09-19 │ False │ 2017-09-29 │ +│ 2.7 │ 2010-07-03 │ 2.7.18 │ 2020-04-19 │ False │ 2020-01-01 │ +│ 2.6 │ 2008-10-01 │ 2.6.9 │ 2013-10-29 │ False │ 2013-10-29 │ +└───────┴────────────┴─────────┴────────────────┴────────────┴────────────┘ ``` @@ -141,19 +142,20 @@ You can format in Markdown, ready for pasting in GitHub issues and PRs: run("eol python --md", with_console=False) ]]] --> -| cycle | release | latest | latest release | eol | -| :---- | :--------: | :------ | :------------: | :--------: | -| 3.11 | 2022-10-24 | 3.11.4 | 2023-06-06 | 2027-10-24 | -| 3.10 | 2021-10-04 | 3.10.12 | 2023-06-06 | 2026-10-04 | -| 3.9 | 2020-10-05 | 3.9.17 | 2023-06-06 | 2025-10-05 | -| 3.8 | 2019-10-14 | 3.8.17 | 2023-06-06 | 2024-10-14 | -| 3.7 | 2018-06-26 | 3.7.17 | 2023-06-05 | 2023-06-27 | -| 3.6 | 2016-12-22 | 3.6.15 | 2021-09-03 | 2021-12-23 | -| 3.5 | 2015-09-12 | 3.5.10 | 2020-09-05 | 2020-09-13 | -| 3.4 | 2014-03-15 | 3.4.10 | 2019-03-18 | 2019-03-18 | -| 3.3 | 2012-09-29 | 3.3.7 | 2017-09-19 | 2017-09-29 | -| 2.7 | 2010-07-03 | 2.7.18 | 2020-04-19 | 2020-01-01 | -| 2.6 | 2008-10-01 | 2.6.9 | 2013-10-29 | 2013-10-29 | +| cycle | release | latest | latest release | support | eol | +| :---- | :--------: | :------ | :------------: | :--------: | :--------: | +| 3.12 | 2023-10-02 | 3.12.0 | 2023-10-02 | 2025-04-02 | 2028-10-02 | +| 3.11 | 2022-10-24 | 3.11.6 | 2023-10-02 | 2024-04-01 | 2027-10-24 | +| 3.10 | 2021-10-04 | 3.10.13 | 2023-08-24 | 2023-04-05 | 2026-10-04 | +| 3.9 | 2020-10-05 | 3.9.18 | 2023-08-24 | 2022-05-17 | 2025-10-05 | +| 3.8 | 2019-10-14 | 3.8.18 | 2023-08-24 | 2021-05-03 | 2024-10-14 | +| 3.7 | 2018-06-26 | 3.7.17 | 2023-06-05 | 2020-06-27 | 2023-06-27 | +| 3.6 | 2016-12-22 | 3.6.15 | 2021-09-03 | 2018-12-24 | 2021-12-23 | +| 3.5 | 2015-09-12 | 3.5.10 | 2020-09-05 | False | 2020-09-13 | +| 3.4 | 2014-03-15 | 3.4.10 | 2019-03-18 | False | 2019-03-18 | +| 3.3 | 2012-09-29 | 3.3.7 | 2017-09-19 | False | 2017-09-29 | +| 2.7 | 2010-07-03 | 2.7.18 | 2020-04-19 | False | 2020-01-01 | +| 2.6 | 2008-10-01 | 2.6.9 | 2013-10-29 | False | 2013-10-29 | @@ -170,11 +172,12 @@ $ eol nodejs --rst ======== ============ ========== ================ ============ ============ ====================================================================================== cycle release latest latest release support eol link ======== ============ ========== ================ ============ ============ ====================================================================================== - 20 LTS 2023-04-18 20.5.0 2023-07-20 2024-10-22 2026-04-30 + 21 2023-10-17 21.1.0 2023-10-24 2024-04-01 2024-06-01 + 20 LTS 2023-04-18 20.9.0 2023-10-24 2024-10-22 2026-04-30 19 2022-10-18 19.9.0 2023-04-10 2023-04-01 2023-06-01 - 18 LTS 2022-04-19 18.17.0 2023-07-18 2023-10-18 2025-04-30 + 18 LTS 2022-04-19 18.18.2 2023-10-13 2023-10-18 2025-04-30 17 2021-10-19 17.9.1 2022-06-01 2022-04-01 2022-06-01 - 16 LTS 2021-04-20 16.20.1 2023-06-20 2022-10-18 2023-09-11 + 16 LTS 2021-04-20 16.20.2 2023-08-09 2022-10-18 2023-09-11 15 2020-10-20 15.14.0 2021-04-06 2021-04-01 2021-06-01 14 LTS 2020-04-21 14.21.3 2023-02-16 2021-10-19 2023-04-30 13 2019-10-22 13.14.0 2020-04-29 2020-04-01 2020-06-01 diff --git a/src/norwegianblue/cli.py b/src/norwegianblue/cli.py index 123186f..9b30573 100644 --- a/src/norwegianblue/cli.py +++ b/src/norwegianblue/cli.py @@ -59,7 +59,7 @@ def main() -> None: "--color", default="auto", choices=("yes", "no", "auto"), - help="colour the terminal output (default: auto)", + help="colour the output (default: auto)", ) parser.add_argument( "--clear-cache", action="store_true", help="clear cache before running"