Skip to content

Commit

Permalink
Add support for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Nov 6, 2023
1 parent c05d0c5 commit 75a72a7
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
*.so
MANIFEST.in
charidotella/assets
.venv
12 changes: 5 additions & 7 deletions charidotella/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
import copy
import functools
Expand Down Expand Up @@ -27,7 +29,7 @@
pathlib.Path,
int,
int,
dict[str, typing.Any],
"dict[str, typing.Any]",
],
None,
]
Expand All @@ -46,7 +48,7 @@
pathlib.Path,
int,
int,
dict[str, typing.Any],
"dict[str, typing.Any]",
],
None,
]
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions charidotella/filters/arbiter_saturation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down
2 changes: 2 additions & 0 deletions charidotella/filters/default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down
2 changes: 2 additions & 0 deletions charidotella/filters/hot_pixels.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down
2 changes: 2 additions & 0 deletions charidotella/filters/refractory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down
2 changes: 2 additions & 0 deletions charidotella/filters/transpose.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down
4 changes: 3 additions & 1 deletion charidotella/tasks/colourtime.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand Down Expand Up @@ -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=(
Expand Down
8 changes: 5 additions & 3 deletions charidotella/tasks/event_rate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations

import importlib.resources
import pathlib
import subprocess
import typing

from .. import utilities

EXTENSION = ".svg"


Expand All @@ -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}",
Expand Down
12 changes: 6 additions & 6 deletions charidotella/tasks/spatiospectrogram.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import atexit
import importlib.resources
import pathlib
import subprocess
import typing

from .. import utilities

EXTENSION = ".mp4"


Expand All @@ -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,
Expand All @@ -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}",
Expand Down
6 changes: 5 additions & 1 deletion charidotella/tasks/spectrogram.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations

import importlib.resources
import pathlib
import subprocess
import typing

from .. import utilities

EXTENSION = ".png"


Expand All @@ -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")),
Expand Down
8 changes: 6 additions & 2 deletions charidotella/tasks/video.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import atexit
import importlib.resources
import pathlib
import subprocess
import typing

from .. import utilities

EXTENSION = ".mp4"


Expand All @@ -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,
Expand All @@ -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}",
Expand Down
8 changes: 3 additions & 5 deletions charidotella/tasks/wiggle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import importlib.resources
import pathlib
import shutil
Expand Down Expand Up @@ -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}",
Expand Down
7 changes: 7 additions & 0 deletions charidotella/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import importlib.resources
import os
import pathlib
import re
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 75a72a7

Please sign in to comment.