From 6a2960f04497c1381b6742861a98af2eb3c7911d Mon Sep 17 00:00:00 2001 From: Kevin Meagher <11620178+kjmeagher@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:29:46 -0500 Subject: [PATCH 1/3] use aliases on reference and target timezones --- .pre-commit-config.yaml | 9 +++------ multizone.py | 5 +++-- pyproject.toml | 2 +- test_mz.py | 5 ++++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71e92c3..1ee4e85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,22 +17,19 @@ repos: rev: v4.0.3 hooks: - id: reuse -- repo: https://github.com/psf/black - rev: 24.8.0 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.9 + rev: v0.7.1 hooks: - id: ruff args: [--fix] + - id: ruff-format - repo: https://github.com/pycqa/pylint rev: v3.3.1 hooks: - id: pylint additional_dependencies: [babel, tabulate, tzlocal, xdg-base-dirs, termcolor, pytest] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v1.13.0 hooks: - id: mypy additional_dependencies: [types-tabulate, types-tzlocal, types-termcolor] diff --git a/multizone.py b/multizone.py index 7f4fe38..9973e43 100755 --- a/multizone.py +++ b/multizone.py @@ -202,12 +202,13 @@ def zone_table( zones.append((name, time)) if not found_local: - zones.append((str(localzone), localdt)) + localname = str(localzone) + zones.append((aliases.get(localname, localname), localdt)) if not found_ref and localoffset != refoffset: tzname = refdt.tzname() assert tzname is not None - zones.append((tzname, refdt)) + zones.append((aliases.get(tzname, tzname), refdt)) zones.sort(key=time_offset) return zones diff --git a/pyproject.toml b/pyproject.toml index 5e686e7..a83a3f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ include = ["multizone.py"] max-line-length = "108" [tool.pylint.message_control] -disable = "R0912" +disable = "R0912,R0914" [tool.ruff] fixable = ["D", "I", "COM"] diff --git a/test_mz.py b/test_mz.py index b444fad..bb8f6c2 100755 --- a/test_mz.py +++ b/test_mz.py @@ -180,6 +180,9 @@ def test_zone_table() -> None: tab4 = multizone.zone_table(["ROK", "EST", "UTC"], {"ROK": "Korea", "EST": "Eastern"}, time0, rok) assert tab4 == [("Korea", time_rok), ("UTC", time0), ("Eastern", time_est)] + tab5 = multizone.zone_table(["EST"], {"ROK": "Korea", "UTC": "London"}, time0, rok) + assert tab5 == [("Korea", time_rok), ("London", time0), ("EST", time_est)] + def test_table_to_string() -> None: """Test table_to_string().""" @@ -197,4 +200,4 @@ def test_table_to_string() -> None: if __name__ == "__main__": - pytest.main(["-v", __file__]) + sys.exit(pytest.main(["-v", __file__, *sys.argv[1:]])) From 98e04d8ce43bb2470701613351296480f1b644a6 Mon Sep 17 00:00:00 2001 From: Kevin Meagher <11620178+kjmeagher@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:39:35 -0500 Subject: [PATCH 2/3] remove python3.8 add python3.13 --- .github/workflows/tests.yml | 6 +++--- pyproject.toml | 23 ++++++++++++++++------- tox.ini | 12 ------------ 3 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 tox.ini diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5327018..da11640 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,11 +14,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] os: [ubuntu-24.04] include: - - python-version: 3.12 - os: macos-14 + - python-version: 3.13 + os: macos-latest steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index a83a3f0..fe6cfbf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,15 +14,16 @@ classifiers = [ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX :: Linux", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.11", "Topic :: Utilities" ] dependencies = [ "babel", - "backports.zoneinfo; python_version < '3.9'", "tabulate", "termcolor", "tomli; python_version < '3.11'", @@ -42,10 +43,6 @@ test = ["pytest", "pytest-cov"] [project.scripts] multizone = "multizone:main" -[tool.black] -line-length = 108 -target-version = ['py38'] - [tool.coverage.run] include = ["multizone.py"] @@ -64,7 +61,19 @@ ignore = [ ] line-length = 108 select = ["ALL"] -target-version = "py38" +target-version = "py39" [tool.ruff.per-file-ignores] "test_mz.py" = ["PLR2004"] + +[tool.tox] +legacy_tox_ini = """ +[tox] +envlist = py3{9,10,11,12,13} +isolated_build = True + +[testenv] +usedevelop=True +deps = .[test] +commands = pytest +""" diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 03e8e77..0000000 --- a/tox.ini +++ /dev/null @@ -1,12 +0,0 @@ -; SPDX-FileCopyrightText: 2023 Kevin Meagher -; -; SPDX-License-Identifier: GPL-3.0-or-later - -[tox] -envlist = py3{7,8,9,10,11} -isolated_build = True - -[testenv] -usedevelop=True -deps = .[test] -commands = pytest From 90918502edece46b380b58c9f5d4bf0659ad9691 Mon Sep 17 00:00:00 2001 From: Kevin Meagher <11620178+kjmeagher@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:44:33 -0500 Subject: [PATCH 3/3] set target python3.9 --- multizone.py | 9 +++------ pyproject.toml | 6 ++++-- test_mz.py | 6 +----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/multizone.py b/multizone.py index 9973e43..1002c8a 100755 --- a/multizone.py +++ b/multizone.py @@ -12,9 +12,10 @@ import argparse import sys +import zoneinfo from datetime import datetime, timedelta, tzinfo from pathlib import Path -from typing import Any, Dict +from typing import Any import tabulate import tzlocal @@ -22,10 +23,6 @@ from babel.dates import format_datetime from termcolor import colored -if sys.version_info < (3, 9): - from backports import zoneinfo -else: - import zoneinfo if sys.version_info < (3, 10): from xdg import xdg_config_home else: @@ -35,7 +32,7 @@ else: import tomllib -ConfigType = Dict[str, Any] +ConfigType = dict[str, Any] def get_arg(time_str: str, sep: str) -> list[int]: diff --git a/pyproject.toml b/pyproject.toml index fe6cfbf..dc2c828 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,15 +53,17 @@ max-line-length = "108" disable = "R0912,R0914" [tool.ruff] +line-length = 108 +target-version = "py39" + +[tool.ruff.lint] fixable = ["D", "I", "COM"] ignore = [ "S101", # assert "D213", # multi-line-summary-second-line incompatible with multi-line-summary-first-line "D203" # one-blank-line-before-class" incompatible with no-blank-line-before-class ] -line-length = 108 select = ["ALL"] -target-version = "py39" [tool.ruff.per-file-ignores] "test_mz.py" = ["PLR2004"] diff --git a/test_mz.py b/test_mz.py index bb8f6c2..f92d724 100755 --- a/test_mz.py +++ b/test_mz.py @@ -12,17 +12,13 @@ from datetime import datetime from pathlib import Path from unittest.mock import MagicMock, mock_open, patch +from zoneinfo import ZoneInfo import pytest from babel.core import default_locale import multizone -if sys.version_info < (3, 9): - from backports.zoneinfo import ZoneInfo -else: - from zoneinfo import ZoneInfo - def test_parse_time_args() -> None: """Tests parse_time_args()."""