Skip to content

Commit

Permalink
Add timezone aliases to reference and target timezone
Browse files Browse the repository at this point in the history
add py313 and remove py38
  • Loading branch information
kjmeagher authored Oct 28, 2024
2 parents f400962 + 9091850 commit 025c4aa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 6 additions & 8 deletions multizone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@

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
from babel.core import default_locale
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:
Expand All @@ -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]:
Expand Down Expand Up @@ -202,12 +199,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
Expand Down
29 changes: 20 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -42,29 +43,39 @@ test = ["pytest", "pytest-cov"]
[project.scripts]
multizone = "multizone:main"

[tool.black]
line-length = 108
target-version = ['py38']

[tool.coverage.run]
include = ["multizone.py"]

[tool.pylint.format]
max-line-length = "108"

[tool.pylint.message_control]
disable = "R0912"
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 = "py38"

[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
"""
11 changes: 5 additions & 6 deletions test_mz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()."""
Expand Down Expand Up @@ -180,6 +176,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()."""
Expand All @@ -197,4 +196,4 @@ def test_table_to_string() -> None:


if __name__ == "__main__":
pytest.main(["-v", __file__])
sys.exit(pytest.main(["-v", __file__, *sys.argv[1:]]))
12 changes: 0 additions & 12 deletions tox.ini

This file was deleted.

0 comments on commit 025c4aa

Please sign in to comment.