From 75a72a7947516a00be286e8681086f6e700245c5 Mon Sep 17 00:00:00 2001 From: Alexandre Marcireau Date: Mon, 6 Nov 2023 17:39:50 +1100 Subject: [PATCH] Add support for Python 3.8 --- .gitignore | 1 + charidotella/__init__.py | 12 +++++------- charidotella/filters/arbiter_saturation.py | 2 ++ charidotella/filters/default.py | 2 ++ charidotella/filters/hot_pixels.py | 2 ++ charidotella/filters/refractory.py | 2 ++ charidotella/filters/transpose.py | 2 ++ charidotella/tasks/colourtime.py | 4 +++- charidotella/tasks/event_rate.py | 8 +++++--- charidotella/tasks/spatiospectrogram.py | 12 ++++++------ charidotella/tasks/spectrogram.py | 6 +++++- charidotella/tasks/video.py | 8 ++++++-- charidotella/tasks/wiggle.py | 8 +++----- charidotella/utilities.py | 7 +++++++ pyproject.toml | 4 ++-- 15 files changed, 53 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 679f041..9f03d08 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ *.so MANIFEST.in charidotella/assets +.venv diff --git a/charidotella/__init__.py b/charidotella/__init__.py index e266d81..1e6d0f2 100644 --- a/charidotella/__init__.py +++ b/charidotella/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import copy import functools @@ -27,7 +29,7 @@ pathlib.Path, int, int, - dict[str, typing.Any], + "dict[str, typing.Any]", ], None, ] @@ -46,7 +48,7 @@ pathlib.Path, int, int, - dict[str, typing.Any], + "dict[str, typing.Any]", ], None, ] @@ -202,11 +204,7 @@ def dump_sections(self, o, sup): @functools.lru_cache(maxsize=None) def configuration_schema(): with open( - str( - importlib.resources.files("charidotella").joinpath( - "assets/configuration-schema.json" - ) - ), + str(utilities.asset_path("configuration-schema.json")), "r", ) as configuration_schema_file: return json.load(configuration_schema_file) diff --git a/charidotella/filters/arbiter_saturation.py b/charidotella/filters/arbiter_saturation.py index 88d8c98..10461ff 100644 --- a/charidotella/filters/arbiter_saturation.py +++ b/charidotella/filters/arbiter_saturation.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing diff --git a/charidotella/filters/default.py b/charidotella/filters/default.py index 1516717..4ac2b0e 100644 --- a/charidotella/filters/default.py +++ b/charidotella/filters/default.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing diff --git a/charidotella/filters/hot_pixels.py b/charidotella/filters/hot_pixels.py index 9b09233..3b6325d 100644 --- a/charidotella/filters/hot_pixels.py +++ b/charidotella/filters/hot_pixels.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing diff --git a/charidotella/filters/refractory.py b/charidotella/filters/refractory.py index 0f8023e..f57cfb5 100644 --- a/charidotella/filters/refractory.py +++ b/charidotella/filters/refractory.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing diff --git a/charidotella/filters/transpose.py b/charidotella/filters/transpose.py index d22bfc6..089536c 100644 --- a/charidotella/filters/transpose.py +++ b/charidotella/filters/transpose.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing diff --git a/charidotella/tasks/colourtime.py b/charidotella/tasks/colourtime.py index 79d2ca7..ac86c87 100644 --- a/charidotella/tasks/colourtime.py +++ b/charidotella/tasks/colourtime.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pathlib import typing @@ -34,7 +36,7 @@ def run( colormap=matplotlib.colormaps[parameters["colormap"]], # type: ignore time_mapping=time_mapping, alpha=parameters["alpha"], - background_colour=matplotlib.colors.to_rgba(parameters["background_color"]), + background_colour=matplotlib.colors.to_rgba(parameters["background_color"]), # type: ignore ) image.resize( size=( diff --git a/charidotella/tasks/event_rate.py b/charidotella/tasks/event_rate.py index 4e13463..aff5f69 100644 --- a/charidotella/tasks/event_rate.py +++ b/charidotella/tasks/event_rate.py @@ -1,8 +1,12 @@ +from __future__ import annotations + import importlib.resources import pathlib import subprocess import typing +from .. import utilities + EXTENSION = ".svg" @@ -15,9 +19,7 @@ def run( ): subprocess.run( [ - str( - importlib.resources.files("charidotella").joinpath("assets/event_rate") - ), + str(utilities.asset_path("event_rate")), str(input), str(output), f"--begin={begin}", diff --git a/charidotella/tasks/spatiospectrogram.py b/charidotella/tasks/spatiospectrogram.py index 53f0b92..facb95b 100644 --- a/charidotella/tasks/spatiospectrogram.py +++ b/charidotella/tasks/spatiospectrogram.py @@ -1,9 +1,13 @@ +from __future__ import annotations + import atexit import importlib.resources import pathlib import subprocess import typing +from .. import utilities + EXTENSION = ".mp4" @@ -18,7 +22,7 @@ def run( int(value) for value in subprocess.run( [ - str(importlib.resources.files("charidotella").joinpath("assets/size")), + str(utilities.asset_path("size")), str(input), ], check=True, @@ -28,11 +32,7 @@ def run( width *= parameters["scale"] height *= parameters["scale"] spatiospectrogram_arguments = [ - str( - importlib.resources.files("charidotella").joinpath( - "assets/spatiospectrogram" - ) - ), + str(utilities.asset_path("spatiospectrogram")), f"--input={input}", f"--begin={begin}", f"--end={end}", diff --git a/charidotella/tasks/spectrogram.py b/charidotella/tasks/spectrogram.py index 9d8b649..f0c3230 100644 --- a/charidotella/tasks/spectrogram.py +++ b/charidotella/tasks/spectrogram.py @@ -1,8 +1,12 @@ +from __future__ import annotations + import importlib.resources import pathlib import subprocess import typing +from .. import utilities + EXTENSION = ".png" @@ -14,7 +18,7 @@ def run( parameters: dict[str, typing.Any], ): arguments = [ - str(importlib.resources.files("charidotella").joinpath("assets/spectrogram")), + str(utilities.asset_path("spectrogram")), str(input), str(output), str((output.parent / output.stem).with_suffix(".json")), diff --git a/charidotella/tasks/video.py b/charidotella/tasks/video.py index a48e021..e5e8883 100644 --- a/charidotella/tasks/video.py +++ b/charidotella/tasks/video.py @@ -1,9 +1,13 @@ +from __future__ import annotations + import atexit import importlib.resources import pathlib import subprocess import typing +from .. import utilities + EXTENSION = ".mp4" @@ -18,7 +22,7 @@ def run( int(value) for value in subprocess.run( [ - str(importlib.resources.files("charidotella").joinpath("assets/size")), + str(utilities.asset_path("size")), str(input), ], check=True, @@ -28,7 +32,7 @@ def run( width *= parameters["scale"] height *= parameters["scale"] es_to_frames_arguments = [ - str(importlib.resources.files("charidotella").joinpath("assets/es_to_frames")), + str(utilities.asset_path("es_to_frames")), f"--input={input}", f"--begin={begin}", f"--end={end}", diff --git a/charidotella/tasks/wiggle.py b/charidotella/tasks/wiggle.py index aa4d52b..fbb0f38 100644 --- a/charidotella/tasks/wiggle.py +++ b/charidotella/tasks/wiggle.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import importlib.resources import pathlib import shutil @@ -29,11 +31,7 @@ def run( base_frames = temporary_directory / "base_frames" base_frames.mkdir(exist_ok=True) es_to_frames_arguments = [ - str( - importlib.resources.files("charidotella").joinpath( - "assets/es_to_frames" - ) - ), + str(utilities.asset_path("es_to_frames")), f"--input={input}", f"--output={base_frames}", f"--begin={begin}", diff --git a/charidotella/utilities.py b/charidotella/utilities.py index e2e578d..01d2eed 100644 --- a/charidotella/utilities.py +++ b/charidotella/utilities.py @@ -1,4 +1,5 @@ import argparse +import importlib.resources import os import pathlib import re @@ -74,3 +75,9 @@ def timecode(value: str) -> int: else: result += round(float("0." + fraction_string) * 1e6) return result + + +def asset_path(name: str) -> pathlib.Path: + if sys.version_info[0:3] < (3, 9, 0): + return importlib.resources.path("charidotella", f"assets/{name}").__enter__() # type: ignore + return importlib.resources.files("charidotella").joinpath(f"assets/{name}") # type: ignore diff --git a/pyproject.toml b/pyproject.toml index 25f27c6..1c8ae0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,8 +7,8 @@ extend-exclude = "command_line_tools" [tool.pyright] typeCheckingMode = "basic" -exclude = ["command_line_tools"] +exclude = ["command_line_tools", ".venv"] [tool.isort] profile = "black" -skip = "command_line_tools" +extend_skip = "command_line_tools, .venv"