From 6ec9190924e101892d6ca8bd566457a4d9c8dfa6 Mon Sep 17 00:00:00 2001 From: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:42:44 +0000 Subject: [PATCH] :pushpin: Update minimum Python version to `3.9` Signed-off-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> --- .github/workflows/mypy-type-check.yml | 2 +- .github/workflows/pip-install.yml | 2 +- .github/workflows/python-package.yml | 2 +- README.md | 2 +- pyproject.toml | 6 +++--- requirements/requirements.conda.yml | 2 +- requirements/requirements.dev.conda.yml | 2 +- requirements/requirements.win64.conda.yml | 2 +- requirements/requirements.win64.dev.conda.yml | 2 +- setup.py | 4 ++-- tests/test_annotation_stores.py | 7 ++++--- tests/test_app_bokeh.py | 11 +++-------- tiatoolbox/__init__.py | 8 +------- tiatoolbox/annotation/storage.py | 7 ++----- tiatoolbox/cli/visualize.py | 8 +------- tiatoolbox/data/__init__.py | 6 +----- tiatoolbox/tools/stainextract.py | 6 +----- 17 files changed, 26 insertions(+), 53 deletions(-) diff --git a/.github/workflows/mypy-type-check.yml b/.github/workflows/mypy-type-check.yml index a22f339c5..1c026da9e 100644 --- a/.github/workflows/mypy-type-check.yml +++ b/.github/workflows/mypy-type-check.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: diff --git a/.github/workflows/pip-install.yml b/.github/workflows/pip-install.yml index abdb11527..ffa6961c9 100644 --- a/.github/workflows/pip-install.yml +++ b/.github/workflows/pip-install.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] os: [ubuntu-22.04, windows-latest, macos-latest] steps: - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 321316040..9df1550c6 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 0c5de616d..da8c04f06 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Prepare a computer as a convenient platform for further development of the Pytho 5. Create virtual environment for TIAToolbox using ```sh - $ conda create -n tiatoolbox-dev python=3.8 # select version of your choice + $ conda create -n tiatoolbox-dev python=3.9 # select version of your choice $ conda activate tiatoolbox-dev $ pip install -r requirements/requirements_dev.txt ``` diff --git a/pyproject.toml b/pyproject.toml index 05463efe8..0662f9e65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -157,8 +157,8 @@ line-length = 88 # Allow unused variables when underscore-prefixed. lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -# Minimum Python version 3.8. -target-version = "py38" +# Minimum Python version 3.9. +target-version = "py39" [tool.ruff.lint.mccabe] # Unlike Flake8, default to a complexity level of 10. @@ -174,4 +174,4 @@ max-args = 10 [tool.mypy] ignore_missing_imports = true -python_version = 3.8 +python_version = 3.9 diff --git a/requirements/requirements.conda.yml b/requirements/requirements.conda.yml index 09be84a12..0d999ac35 100644 --- a/requirements/requirements.conda.yml +++ b/requirements/requirements.conda.yml @@ -9,6 +9,6 @@ dependencies: - openslide - pip>=20.0.2 - pixman>=0.39.0 - - python>=3.8, <=3.11 + - python>=3.9, <=3.12 - pip: - -r requirements.txt diff --git a/requirements/requirements.dev.conda.yml b/requirements/requirements.dev.conda.yml index 494d5a0d3..4a743d837 100644 --- a/requirements/requirements.dev.conda.yml +++ b/requirements/requirements.dev.conda.yml @@ -9,6 +9,6 @@ dependencies: - openslide - pip>=20.0.2 - pixman>=0.39.0 - - python>=3.8, <=3.11 + - python>=3.9, <=3.12 - pip: - -r requirements_dev.txt diff --git a/requirements/requirements.win64.conda.yml b/requirements/requirements.win64.conda.yml index f6386597f..1aeff0a7a 100644 --- a/requirements/requirements.win64.conda.yml +++ b/requirements/requirements.win64.conda.yml @@ -9,6 +9,6 @@ dependencies: - openjpeg>=2.4.0 - pip>=20.0.2 - pixman>=0.39.0 - - python>=3.8, <=3.11 + - python>=3.9, <=3.12 - pip: - -r requirements.txt diff --git a/requirements/requirements.win64.dev.conda.yml b/requirements/requirements.win64.dev.conda.yml index 078d75a38..64b4b07d1 100644 --- a/requirements/requirements.win64.dev.conda.yml +++ b/requirements/requirements.win64.dev.conda.yml @@ -9,6 +9,6 @@ dependencies: - openjpeg>=2.4.0 - pip>=20.0.2 - pixman>=0.39.0 - - python>=3.8, <=3.11 + - python>=3.9, <=3.12 - pip: - -r requirements_dev.txt diff --git a/setup.py b/setup.py index 92fe58e0b..efb7f20ec 100644 --- a/setup.py +++ b/setup.py @@ -34,16 +34,16 @@ setup( author="TIA Centre", author_email="tia@dcs.warwick.ac.uk", - python_requires=">=3.8, <3.12", + python_requires=">=3.9, <3.13", classifiers=[ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python :: 3", - "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", ], description="Computational pathology toolbox developed by TIA Centre.", dependency_links=dependency_links, diff --git a/tests/test_annotation_stores.py b/tests/test_annotation_stores.py index 562e9a8a1..7ec0f0f88 100644 --- a/tests/test_annotation_stores.py +++ b/tests/test_annotation_stores.py @@ -6,10 +6,11 @@ import pickle import sqlite3 import sys +from collections.abc import Generator from itertools import repeat, zip_longest from pathlib import Path from timeit import timeit -from typing import TYPE_CHECKING, Callable, ClassVar, Generator +from typing import TYPE_CHECKING, Callable, ClassVar import numpy as np import pandas as pd @@ -1806,8 +1807,8 @@ def test_py38_init( store_cls: type[AnnotationStore], monkeypatch: object, ) -> None: - """Test that __init__ is compatible with Python 3.8.""" - py38_version = (3, 8, 0) + """Test that __init__ is compatible with Python 3.9.""" + py38_version = (3, 9, 0) class Connection(sqlite3.Connection): """Mock SQLite connection.""" diff --git a/tests/test_app_bokeh.py b/tests/test_app_bokeh.py index 3d072a919..047f1d591 100644 --- a/tests/test_app_bokeh.py +++ b/tests/test_app_bokeh.py @@ -2,24 +2,19 @@ from __future__ import annotations +import importlib.resources as importlib_resources import io import json import multiprocessing import re -import sys import time +from collections.abc import Generator from pathlib import Path -from typing import TYPE_CHECKING, Generator +from typing import TYPE_CHECKING import bokeh.models as bkmodels import matplotlib.pyplot as plt import numpy as np - -if sys.version_info >= (3, 9): # pragma: no cover - import importlib.resources as importlib_resources -else: # pragma: no cover - # To support Python 3.8 - import importlib_resources # type: ignore[import-not-found] import pytest import requests from bokeh.application import Application diff --git a/tiatoolbox/__init__.py b/tiatoolbox/__init__.py index 88d2eabc9..7effbca69 100644 --- a/tiatoolbox/__init__.py +++ b/tiatoolbox/__init__.py @@ -2,17 +2,12 @@ from __future__ import annotations +import importlib.resources as importlib_resources import importlib.util import sys from pathlib import Path from typing import TYPE_CHECKING, Dict, TypedDict -if sys.version_info >= (3, 9): # pragma: no cover - import importlib.resources as importlib_resources -else: # pragma: no cover - # To support Python 3.8 - import importlib_resources # type: ignore[import-not-found] - import yaml if TYPE_CHECKING: # pragma: no cover @@ -92,7 +87,6 @@ def read_registry_files(path_to_registry: str | Path) -> dict: """ - path_to_registry = str(path_to_registry) # To pass tests with Python 3.8 pretrained_files_registry_path = importlib_resources.as_file( importlib_resources.files("tiatoolbox") / path_to_registry, ) diff --git a/tiatoolbox/annotation/storage.py b/tiatoolbox/annotation/storage.py index 3fb786374..470ed977a 100644 --- a/tiatoolbox/annotation/storage.py +++ b/tiatoolbox/annotation/storage.py @@ -40,7 +40,7 @@ import zlib from abc import ABC, abstractmethod from collections import defaultdict -from collections.abc import MutableMapping +from collections.abc import Generator, Iterable, Iterator, MutableMapping from dataclasses import dataclass, field from functools import lru_cache from pathlib import Path @@ -50,9 +50,6 @@ Any, Callable, ClassVar, - Generator, - Iterable, - Iterator, ) import numpy as np @@ -2278,7 +2275,7 @@ def register_custom_function( ) -> None: """Register a custom SQLite function. - Only Python >= 3.8 supports deterministic functions, + Only Python >= 3.9 supports deterministic functions, fallback to without this argument if not available. Args: diff --git a/tiatoolbox/cli/visualize.py b/tiatoolbox/cli/visualize.py index 7f5ed0ad5..86810954a 100644 --- a/tiatoolbox/cli/visualize.py +++ b/tiatoolbox/cli/visualize.py @@ -2,19 +2,13 @@ from __future__ import annotations +import importlib.resources as importlib_resources import os import subprocess -import sys from pathlib import Path from threading import Thread import click - -if sys.version_info >= (3, 9): # pragma: no cover - import importlib.resources as importlib_resources -else: # pragma: no cover - # To support Python 3.8 - import importlib_resources # type: ignore[import-not-found] from flask_cors import CORS from tiatoolbox.cli.common import tiatoolbox_cli diff --git a/tiatoolbox/data/__init__.py b/tiatoolbox/data/__init__.py index 1ac4e8e31..d7058493e 100644 --- a/tiatoolbox/data/__init__.py +++ b/tiatoolbox/data/__init__.py @@ -2,6 +2,7 @@ """Package to define datasets available to download via TIAToolbox.""" from __future__ import annotations +import importlib.resources as importlib_resources import sys import tempfile import zipfile @@ -9,11 +10,6 @@ from typing import TYPE_CHECKING from urllib.parse import urlparse -if sys.version_info >= (3, 9): # pragma: no cover - import importlib.resources as importlib_resources -else: # pragma: no cover - import importlib_resources # To support Python 3.8 - from tiatoolbox import logger, read_registry_files if TYPE_CHECKING: # pragma: no cover diff --git a/tiatoolbox/tools/stainextract.py b/tiatoolbox/tools/stainextract.py index 4126f7e55..ff2ba8c19 100644 --- a/tiatoolbox/tools/stainextract.py +++ b/tiatoolbox/tools/stainextract.py @@ -11,12 +11,8 @@ from tiatoolbox.utils.transforms import rgb2od if TYPE_CHECKING: # pragma: no cover - import sys - if sys.version_info >= (3, 9): - from typing import Self - else: # pragma: no cover - from typing_extensions import Self # To support Python 3.8 + from typing import Self def vectors_in_correct_direction(e_vectors: np.ndarray) -> np.ndarray: