Skip to content

Commit 58bbd7b

Browse files
committed
fix(time,lftest): keep modules importable on Python 3.6 (RHEL 8 / Rocky 8)
time.py guarded the zoneinfo import (stdlib only since 3.9) and falls back to UTC; lftest.py replaced a parenthesized context manager (3.10+ syntax) with an ExitStack. Both modules sit in every plugin's import chain, so the prior code crashed uncompiled plugins on the system Python of RHEL 8 / Rocky 8.
1 parent 721bb81 commit 58bbd7b

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Fixed
1212

1313
* db_sqlite.py: cached databases now self-heal after a schema change between releases. A constraint or data error (such as a `NOT NULL` column that a newer or older release no longer writes) deletes and rebuilds the cache on the next run, instead of failing on every run until the stale file is removed by hand.
14+
* lftest.py: no longer breaks at import with a `SyntaxError` on Python interpreters older than 3.10 (such as the system Python 3.6 on RHEL 8 / Rocky 8, and our supported Python 3.9 floor). A parenthesized context manager was rewritten as nested `with` statements, so every plugin that imports this module stays runnable on those interpreters.
15+
* time.py: no longer fails to import on Python interpreters older than 3.9 (such as the system Python 3.6 on RHEL 8 / Rocky 8) where the `zoneinfo` module does not exist. Consumers that do not need named time zones keep working and fall back to UTC.
1416

1517

1618
## [v5.0.0] - 2026-06-12

lftest.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from . import base, disk, shell
2020

2121
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
22-
__version__ = '2026061201'
22+
__version__ = '2026061901'
2323

2424

2525
def run(test_instance, plugin, testcase):
@@ -600,20 +600,24 @@ def run_mysql_compatible_from_containerfile(
600600
tag = f'lfmp-mysql-{dockerfile_name}'.lower().replace('_', '-')
601601

602602
# No parenthesized context managers: they are Python 3.10+ syntax and break
603-
# parsing on RHEL 8's default Python 3.6.
604-
with (
605-
DockerImage(
606-
path=build_dir,
607-
dockerfile_path=dockerfile_name,
608-
tag=tag,
609-
clean_up=False,
610-
) as image,
611-
_run_mysql_compatible_resolved(
612-
str(image.tag),
613-
command,
614-
seed,
615-
) as result,
616-
):
603+
# parsing on RHEL 8's default Python 3.6. Use an ExitStack so the module
604+
# stays importable on the oldest interpreters our plugins run on.
605+
with contextlib.ExitStack() as stack:
606+
image = stack.enter_context(
607+
DockerImage(
608+
path=build_dir,
609+
dockerfile_path=dockerfile_name,
610+
tag=tag,
611+
clean_up=False,
612+
)
613+
)
614+
result = stack.enter_context(
615+
_run_mysql_compatible_resolved(
616+
str(image.tag),
617+
command,
618+
seed,
619+
)
620+
)
617621
yield result
618622

619623

time.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111
"""Provides datetime functions."""
1212

1313
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
14-
__version__ = '2026060701'
14+
__version__ = '2026061901'
1515

1616
import datetime
1717
import re
1818
import time
19-
import zoneinfo
19+
20+
try:
21+
import zoneinfo
22+
except ImportError:
23+
# zoneinfo is part of the standard library since Python 3.9. On older
24+
# interpreters (such as the system Python 3.6 on RHEL 8 / Rocky 8) it is
25+
# missing; degrade to UTC in get_timezone() instead of failing at import,
26+
# so consumers that do not need named time zones keep working.
27+
zoneinfo = None
2028

2129

2230
def epoch2iso(timestamp):
@@ -62,14 +70,16 @@ def get_timezone(tz_name):
6270
>>> get_timezone('Invalid/Zone').key
6371
'Etc/UTC'
6472
"""
73+
if zoneinfo is None:
74+
# Python < 3.9 without the zoneinfo backport
75+
return datetime.timezone.utc
6576
try:
6677
return zoneinfo.ZoneInfo(tz_name)
6778
except Exception:
6879
# Fallback to UTC if the name isn't found
6980
try:
7081
return zoneinfo.ZoneInfo('Etc/UTC')
7182
except Exception:
72-
# Python < 3.9
7383
return datetime.timezone.utc
7484

7585

0 commit comments

Comments
 (0)