Skip to content

Commit b9ef96a

Browse files
committed
update to modern python unions, add python3.14 to ci
1 parent 2b799aa commit b9ef96a

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.10", "3.11", "3.12", "3.13"]
14+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
1515

1616
steps:
1717
- uses: actions/checkout@v5

mpv_history_daemon/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def cli():
3030
def _parse_polling(
3131
ctx: click.Context,
3232
param: click.Parameter,
33-
value: Union[str, int],
34-
) -> Union[Literal["disabled"], int]:
33+
value: str | int,
34+
) -> Literal["disabled"] | int:
3535
if value == "disabled":
3636
return "disabled"
3737
if isinstance(value, int):
@@ -78,9 +78,9 @@ def daemon(
7878
socket_dir: str,
7979
data_dir: str,
8080
log_file: str,
81-
scan_time: Union[Literal["disabled"], int],
82-
write_period: Optional[int],
83-
socket_class_qualname: Optional[str],
81+
scan_time: Literal["disabled"] | int,
82+
write_period: int | None,
83+
socket_class_qualname: str | None,
8484
) -> None:
8585
"""
8686
Socket dir is the directory with mpv sockets (/tmp/mpvsockets, probably)
@@ -177,7 +177,7 @@ def parse(data_files: Sequence[str], all_events: bool, debug: bool) -> None:
177177
help="If files have been modified in this amount of time, don't merge them",
178178
)
179179
def merge(
180-
data_files: Sequence[str], move: Optional[Path], write_to: Path, mtime_seconds: int
180+
data_files: Sequence[str], move: Path | None, write_to: Path, mtime_seconds: int
181181
) -> None:
182182
"""
183183
merges multiple files into a single merged event file

mpv_history_daemon/daemon.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(
102102
socket: MPV,
103103
socket_loc: str,
104104
data_dir: str,
105-
write_period: Optional[int] = None,
105+
write_period: int | None = None,
106106
):
107107
self.socket = socket
108108
self.socket_loc = socket_loc
@@ -159,7 +159,7 @@ def write(self) -> None:
159159
) as event_f:
160160
event_f.write(serialized)
161161

162-
def nevent(self, event_name: str, event_data: Optional[Any] = None) -> None:
162+
def nevent(self, event_name: str, event_data: Any | None = None) -> None:
163163
"""add an event"""
164164
ct = time()
165165
logger.debug(f"{self.socket_time}|{ct}|{event_name}|{event_data}")
@@ -278,8 +278,8 @@ def __init__(
278278
data_dir: str,
279279
*,
280280
autostart: bool = True,
281-
write_period: Optional[int],
282-
poll_time: Optional[int] = 10,
281+
write_period: int | None,
282+
poll_time: int | None = 10,
283283
socket_data_cls: type[SocketData] = SocketData,
284284
):
285285
self.data_dir: str = data_dir
@@ -299,7 +299,7 @@ def scan_sockets(self) -> None:
299299
"""
300300
Look for any new sockets at socket_dir, remove any dead ones
301301
"""
302-
socket_loc_scoped: Optional[str] = None # to access this after the try/except
302+
socket_loc_scoped: str | None = None # to access this after the try/except
303303
try:
304304
# iterate through all files
305305
for socket_name in os.listdir(self.socket_dir):
@@ -497,9 +497,9 @@ def run(
497497
socket_dir: str,
498498
data_dir: str,
499499
log_file: str,
500-
write_period: Optional[int],
500+
write_period: int | None,
501501
socket_data_cls: type[SocketData],
502-
poll_time: Optional[int],
502+
poll_time: int | None,
503503
) -> None:
504504
# if the daemon launched before any mpv instances
505505
if not os.path.exists(socket_dir):

mpv_history_daemon/events.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Any,
1414
Optional,
1515
Union,
16-
Callable,
1716
)
17+
from collections.abc import Callable
1818
from collections.abc import Iterator, Sequence
1919

2020
from logzero import setup_logger # type: ignore[import]
@@ -29,7 +29,7 @@
2929
EventData = Any
3030

3131

32-
def parse_datetime_sec(d: Union[str, float, int]) -> datetime:
32+
def parse_datetime_sec(d: str | float | int) -> datetime:
3333
return datetime.fromtimestamp(float(d), tz=timezone.utc)
3434

3535

@@ -41,7 +41,7 @@ class Action(NamedTuple):
4141
since_started: float
4242
action: str
4343
# this can be None if its a livestream, those dont have a percent-pos
44-
percentage: Optional[float]
44+
percentage: float | None
4545

4646

4747
class Media(NamedTuple):
@@ -50,9 +50,9 @@ class Media(NamedTuple):
5050
start_time: datetime # when the media started playing
5151
end_time: datetime # when the media was closed/finished
5252
pause_duration: float # how long the media was paused for (typically 0)
53-
media_duration: Optional[float] # length of the media
53+
media_duration: float | None # length of the media
5454
# title of the media (if URL, could be <title>...</title> from ytdl
55-
media_title: Optional[str]
55+
media_title: str | None
5656
# additional metadata on what % I was through the media while pausing/playing/seeking
5757
actions: list[Action]
5858
metadata: dict[str, Any] # metadata from the file, if it exists
@@ -147,7 +147,7 @@ def _read_event_stream(
147147
continue
148148
if d["end_time"] < d["start_time"]:
149149
logger.warning(f"End time is less than start time! {d}")
150-
fdur: Optional[float] = None
150+
fdur: float | None = None
151151
if "duration" in d:
152152
fdur = float(d["duration"])
153153
start_time = parse_datetime_sec(float(d["start_time"]))
@@ -223,7 +223,7 @@ def _reconstruct_event_stream(
223223
# exec "$mpv_path" "${mpv_options[@]}"
224224
#
225225
# get when mpv launched from the filename
226-
start_time: Optional[float] = None
226+
start_time: float | None = None
227227
try:
228228
start_time = float(int(PurePath(filename).stem) / 1e9)
229229
except ValueError as ve:
@@ -242,7 +242,7 @@ def _reconstruct_event_stream(
242242
# used to help determine state
243243
is_playing = True # assume playing at beginning
244244
pause_duration = 0.0 # pause duration for this entry
245-
pause_start_time: Optional[float] = None # if the entry is paused, when it started
245+
pause_start_time: float | None = None # if the entry is paused, when it started
246246
actions: dict[float, tuple[str, float]] = {}
247247

248248
# a heuristic to determine if this is an old file, is-paused can be useful

mpv_history_daemon/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MusicMetadata(NamedTuple):
2121
def music_parse_metadata_from_blob(
2222
data: dict[str, Any],
2323
strip_whitespace: bool = False,
24-
) -> Optional[MusicMetadata]:
24+
) -> MusicMetadata | None:
2525
if "title" not in data or "album" not in data or "artist" not in data:
2626
return None
2727
title = data["title"]
@@ -54,13 +54,13 @@ class MediaAllowed:
5454
def __init__(
5555
self,
5656
*,
57-
allow_prefixes: Optional[list[str]] = None,
58-
ignore_prefixes: Optional[list[str]] = None,
59-
allow_extensions: Optional[list[str]] = None,
60-
ignore_extensions: Optional[list[str]] = None,
57+
allow_prefixes: list[str] | None = None,
58+
ignore_prefixes: list[str] | None = None,
59+
allow_extensions: list[str] | None = None,
60+
ignore_extensions: list[str] | None = None,
6161
allow_stream: bool = False,
6262
strict: bool = True,
63-
logger: Optional[logging.Logger] = None,
63+
logger: logging.Logger | None = None,
6464
):
6565
self.allow_prefixes = allow_prefixes if allow_prefixes else []
6666
self.ignored_prefixes = ignore_prefixes if ignore_prefixes else []

0 commit comments

Comments
 (0)