Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 3.8 support #484

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
CIBW_ARCHS_LINUX: x86_64 i686 aarch64
CIBW_ARCHS_MACOS: x86_64 universal2
CIBW_ARCHS_WINDOWS: AMD64 x86 ARM64
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-*"

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
strategy:
matrix:
python-version:
- 3.8
- 3.9
- '3.10'
- '3.11'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py39-plus]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

* Drop Python 3.8 support.

2.15.0 (2024-08-06)
-------------------

Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Use **pip**:

python -m pip install time-machine

Python 3.8 to 3.13 supported.
Python 3.9 to 3.13 supported.
Only CPython is supported at this time because time-machine directly hooks into the C-level API.


Expand Down Expand Up @@ -210,17 +210,13 @@ Timezone mocking

If the ``destination`` passed to ``time_machine.travel()`` or ``Coordinates.move_to()`` has its ``tzinfo`` set to a |zoneinfo-instance2|_, the current timezone will be mocked.
This will be done by calling |time-tzset|_, so it is only available on Unix.
The ``zoneinfo`` module is new in Python 3.8 - on older Python versions use the |backports-zoneinfo-package|_, by the original ``zoneinfo`` author.

.. |zoneinfo-instance2| replace:: ``zoneinfo.ZoneInfo`` instance
.. _zoneinfo-instance2: https://docs.python.org/3/library/zoneinfo.html#zoneinfo.ZoneInfo

.. |time-tzset| replace:: ``time.tzset()``
.. _time-tzset: https://docs.python.org/3/library/time.html#time.tzset

.. |backports-zoneinfo-package| replace:: ``backports.zoneinfo`` package
.. _backports-zoneinfo-package: https://pypi.org/project/backports.zoneinfo/

``time.tzset()`` changes the ``time`` module’s `timezone constants <https://docs.python.org/3/library/time.html#timezone-constants>`__ and features that rely on those, such as ``time.localtime()``.
It won’t affect other concepts of “the current timezone”, such as Django’s (which can be changed with its |timezone-override|_).

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ keywords = [
authors = [
{ name = "Adam Johnson", email = "me@adamj.eu" },
]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Pytest",
Expand All @@ -31,7 +31,6 @@ classifiers = [
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
31 changes: 6 additions & 25 deletions src/time_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
import sys
import time as time_module
import uuid
from collections.abc import Awaitable
from collections.abc import Generator
from collections.abc import Generator as TypingGenerator
from time import gmtime as orig_gmtime
from time import struct_time
from types import TracebackType
from typing import Any
from typing import Awaitable
from typing import Callable
from typing import Generator as TypingGenerator
from typing import Tuple
from typing import Type
from typing import TypeVar
from typing import Union
from typing import cast
from typing import overload
from unittest import TestCase
from unittest import mock
from zoneinfo import ZoneInfo

import _time_machine
from dateutil.parser import parse as parse_datetime
Expand All @@ -43,19 +42,6 @@
# Windows
HAVE_TZSET = False

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo

HAVE_ZONEINFO = True
else:
try:
from backports.zoneinfo import ZoneInfo

HAVE_ZONEINFO = True
except ImportError: # pragma: no cover
HAVE_ZONEINFO = False


try:
import pytest
except ImportError: # pragma: no cover
Expand Down Expand Up @@ -97,10 +83,10 @@

_F = TypeVar("_F", bound=Callable[..., Any])
_AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])
TestCaseType = TypeVar("TestCaseType", bound=Type[TestCase])
TestCaseType = TypeVar("TestCaseType", bound=type[TestCase])

# copied from typeshed:
_TimeTuple = Tuple[int, int, int, int, int, int, int, int, int]
_TimeTuple = tuple[int, int, int, int, int, int, int, int, int]


def extract_timestamp_tzname(
Expand All @@ -121,7 +107,7 @@ def extract_timestamp_tzname(
elif isinstance(dest, float):
timestamp = dest
elif isinstance(dest, dt.datetime):
if HAVE_ZONEINFO and isinstance(dest.tzinfo, ZoneInfo):
if isinstance(dest.tzinfo, ZoneInfo):
tzname = dest.tzinfo.key
if dest.tzinfo is None:
dest = dest.replace(tzinfo=dt.timezone.utc)
Expand Down Expand Up @@ -233,11 +219,6 @@ def start(self) -> Coordinates:
_time_machine.patch_if_needed()

if not coordinates_stack:
if sys.version_info < (3, 9):
# We need to cause the functions to be loaded before we patch
# them out, which is done by this internal function before:
# https://github.com/python/cpython/pull/19948
uuid._load_system_functions()
uuid_generate_time_patcher.start()
uuid_uuid_create_patcher.start()

Expand Down
1 change: 0 additions & 1 deletion tests/requirements/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*sys.argv[1:],
]
run = partial(subprocess.run, check=True)
run([*common_args, "--python", "3.8", "--output-file", "py38.txt"])
run([*common_args, "--python", "3.9", "--output-file", "py39.txt"])
run([*common_args, "--python", "3.10", "--output-file", "py310.txt"])
run([*common_args, "--python", "3.11", "--output-file", "py311.txt"])
Expand Down
142 changes: 0 additions & 142 deletions tests/requirements/py38.txt

This file was deleted.

7 changes: 1 addition & 6 deletions tests/test_time_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
from unittest import SkipTest
from unittest import TestCase
from unittest import mock
from zoneinfo import ZoneInfo

import pytest
from dateutil import tz

import time_machine

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
else:
from backports.zoneinfo import ZoneInfo


NANOSECONDS_PER_SECOND = time_machine.NANOSECONDS_PER_SECOND
EPOCH_DATETIME = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
EPOCH = EPOCH_DATETIME.timestamp()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires =
tox>=4.2
env_list =
py{313, 312, 311, 310, 39, 38}
py{313, 312, 311, 310, 39}

[testenv]
package = wheel
Expand Down