mirror of
https://github.com/iluvcapra/pycmx.git
synced 2026-10-01 17:27:33 +00:00
Ruff fixes
This commit is contained in:
@@ -13,7 +13,6 @@ keywords = [
|
||||
requires-python = '>3.8'
|
||||
classifiers = [
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Topic :: Multimedia',
|
||||
'Topic :: Multimedia :: Video',
|
||||
'Topic :: Text Processing',
|
||||
@@ -60,19 +59,6 @@ indent-width = 4
|
||||
[tool.ruff.format]
|
||||
docstring-code-line-length = 88
|
||||
|
||||
# [tool.pylint]
|
||||
# max-line-length = 88
|
||||
# disable = [
|
||||
# "C0103", # (invalid-name)
|
||||
# "C0114", # (missing-module-docstring)
|
||||
# "C0115", # (missing-class-docstring)
|
||||
# "C0116", # (missing-function-docstring)
|
||||
# "R0903", # (too-few-public-methods)
|
||||
# "R0913", # (too-many-arguments)
|
||||
# "W0105", # (pointless-string-statement)
|
||||
# ]
|
||||
#
|
||||
|
||||
[build-system]
|
||||
requires = ["uv_build>=0.9.18,<0.12"]
|
||||
build-backend = "uv_build"
|
||||
|
||||
@@ -12,8 +12,8 @@ class ChannelMap:
|
||||
Represents a set of all the channels to which an event applies.
|
||||
"""
|
||||
|
||||
def __init__(self, v=False, audio_channels=set()):
|
||||
self._audio_channel_set = audio_channels
|
||||
def __init__(self, v=False, audio_channels=None):
|
||||
self._audio_channel_set = audio_channels or set()
|
||||
self.v = v
|
||||
self._chan_map: dict[str, tuple] = {
|
||||
"V": (True, False, False),
|
||||
|
||||
+15
-14
@@ -1,7 +1,8 @@
|
||||
# pycmx
|
||||
# (c) 2023-2025 Jamie Hardt
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Generator, List, Optional, Tuple
|
||||
from typing import Any, Generator
|
||||
|
||||
from .edit import Edit
|
||||
from .statements import (
|
||||
@@ -33,7 +34,7 @@ class Event:
|
||||
return int(self._edit_statements()[0].event)
|
||||
|
||||
@property
|
||||
def edits(self) -> List[Edit]:
|
||||
def edits(self) -> list[Edit]:
|
||||
"""
|
||||
Returns the edits. Most events will have a single edit, a single event
|
||||
will have multiple edits when a dissolve, wipe or key transition needs
|
||||
@@ -55,14 +56,14 @@ class Event:
|
||||
|
||||
# The list the_zip contains one element for each initialization
|
||||
# parameter in Edit()
|
||||
the_zip: List[List[Any]] = [edits_audio]
|
||||
the_zip: list[list[Any]] = [edits_audio]
|
||||
|
||||
# If there are two Clip Name statements and two edits, we look for
|
||||
# "FROM" and "TO" clip name lines. Otherwise we just look for on
|
||||
# each per edit.
|
||||
if len(edits_audio) == 2:
|
||||
start_name: Optional[StmtClipName] = None
|
||||
end_name: Optional[StmtClipName] = None
|
||||
start_name: StmtClipName | None = None
|
||||
end_name: StmtClipName | None = None
|
||||
|
||||
for clip_name in clip_names:
|
||||
if clip_name.affect == "from":
|
||||
@@ -91,7 +92,7 @@ class Event:
|
||||
# attach effects name to last event
|
||||
try:
|
||||
trans_statement = self._trans_name_statements()[0]
|
||||
trans_names: List[Optional[Any]] = [None] * (len(edits_audio) - 1)
|
||||
trans_names: list[Any] = [None] * (len(edits_audio) - 1)
|
||||
trans_names.append(trans_statement)
|
||||
the_zip.append(trans_names)
|
||||
except IndexError:
|
||||
@@ -120,21 +121,21 @@ class Event:
|
||||
if type(s) is StmtUnrecognized:
|
||||
yield s
|
||||
|
||||
def _trans_name_statements(self) -> List[StmtEffectsName]:
|
||||
def _trans_name_statements(self) -> list[StmtEffectsName]:
|
||||
return [s for s in self.statements if type(s) is StmtEffectsName]
|
||||
|
||||
def _edit_statements(self) -> List[StmtEvent]:
|
||||
def _edit_statements(self) -> list[StmtEvent]:
|
||||
return [s for s in self.statements if type(s) is StmtEvent]
|
||||
|
||||
def _clip_name_statements(self) -> List[StmtClipName]:
|
||||
def _clip_name_statements(self) -> list[StmtClipName]:
|
||||
return [s for s in self.statements if type(s) is StmtClipName]
|
||||
|
||||
def _source_file_statements(self) -> List[StmtSourceFile]:
|
||||
def _source_file_statements(self) -> list[StmtSourceFile]:
|
||||
return [s for s in self.statements if type(s) is StmtSourceFile]
|
||||
|
||||
def _statements_with_audio_ext(
|
||||
self,
|
||||
) -> Generator[Tuple[StmtEvent, Optional[StmtAudioExt]], None, None]:
|
||||
) -> Generator[tuple[StmtEvent, StmtAudioExt | None], None, None]:
|
||||
|
||||
if len(self.statements) == 1 and type(self.statements[0]) is StmtEvent:
|
||||
yield (self.statements[0], None)
|
||||
@@ -146,11 +147,11 @@ class Event:
|
||||
elif type(s1) is StmtEvent:
|
||||
yield (s1, None)
|
||||
|
||||
def _asc_sop_statement(self) -> Optional[StmtCdlSop]:
|
||||
def _asc_sop_statement(self) -> StmtCdlSop | None:
|
||||
return next((s for s in self.statements if type(s) is StmtCdlSop), None)
|
||||
|
||||
def _asc_sat_statement(self) -> Optional[StmtCdlSat]:
|
||||
def _asc_sat_statement(self) -> StmtCdlSat | None:
|
||||
return next((s for s in self.statements if type(s) is StmtCdlSat), None)
|
||||
|
||||
def _frmc_statement(self) -> Optional[StmtFrmc]:
|
||||
def _frmc_statement(self) -> StmtFrmc | None:
|
||||
return next((s for s in self.statements if type(s) is StmtFrmc), None)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# pycmx
|
||||
# (c) 2018-2025 Jamie Hardt
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import List, TextIO
|
||||
from typing import TextIO
|
||||
|
||||
from .cdl import AscSopComponents, Rgb
|
||||
from .statements import (
|
||||
@@ -24,7 +26,7 @@ from .statements import (
|
||||
from .util import collimate
|
||||
|
||||
|
||||
def parse_cmx3600_statements(file: TextIO, tolerant: bool = False) -> List[object]:
|
||||
def parse_cmx3600_statements(file: TextIO, tolerant: bool = False) -> list[object]:
|
||||
"""
|
||||
Return a list of every statement in the file argument.
|
||||
"""
|
||||
@@ -35,7 +37,7 @@ def parse_cmx3600_statements(file: TextIO, tolerant: bool = False) -> List[objec
|
||||
]
|
||||
|
||||
|
||||
def _edl_column_widths(event_field_length, source_field_length) -> List[int]:
|
||||
def _edl_column_widths(event_field_length, source_field_length) -> list[int]:
|
||||
return [
|
||||
event_field_length,
|
||||
2,
|
||||
@@ -154,7 +156,7 @@ def _parse_remark(line, line_number) -> object:
|
||||
|
||||
v: list[list[str]] = [[a[0] for a in b] for b in v1]
|
||||
|
||||
if len(v) != 3 or any([len(a) != 3 for a in v]):
|
||||
if len(v) != 3 or any(len(a) != 3 for a in v):
|
||||
return StmtRemark(line, line_number)
|
||||
|
||||
else:
|
||||
@@ -267,7 +269,7 @@ def _parse_columns_for_standard_form(
|
||||
raise EventFormError()
|
||||
|
||||
return StmtEvent(
|
||||
event=column_strings[0],
|
||||
event=int(column_strings[0]),
|
||||
source=column_strings[2].strip(),
|
||||
channels=channels,
|
||||
trans=trans,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# pycmx
|
||||
# (c) 2023 Jamie Hardt
|
||||
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class Transition:
|
||||
@@ -22,7 +22,7 @@ class Transition:
|
||||
self.name = name
|
||||
|
||||
@property
|
||||
def kind(self) -> Optional[str]:
|
||||
def kind(self) -> str | None:
|
||||
"""
|
||||
Return the kind of transition: Cut, Wipe, etc.
|
||||
"""
|
||||
@@ -64,7 +64,7 @@ class Transition:
|
||||
return int(self.operand)
|
||||
|
||||
@property
|
||||
def wipe_number(self) -> Optional[int]:
|
||||
def wipe_number(self) -> int | None:
|
||||
"Wipes are identified by a particular number."
|
||||
if self.wipe:
|
||||
return int(self.transition[1:])
|
||||
|
||||
+3
-1
@@ -3,8 +3,10 @@
|
||||
|
||||
# Utility functions
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
def collimate(a_string, column_widths):
|
||||
|
||||
def collimate(a_string, column_widths) -> list[str]:
|
||||
"""
|
||||
Split a list-type thing, like a string, into slices that are column_widths
|
||||
length.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# ruff: noqa: SIM115
|
||||
from unittest import TestCase
|
||||
|
||||
from pycmx import parse_cmx3600
|
||||
|
||||
+17
-13
@@ -4,38 +4,42 @@ import pycmx
|
||||
|
||||
|
||||
class TestParse(TestCase):
|
||||
files = [
|
||||
"INS4_R1_010417.edl",
|
||||
"INS4_R1_DX_092117.edl",
|
||||
"STP R1 v082517.edl",
|
||||
"ToD_R4_LOCK3.1_030618_Video.edl",
|
||||
"TEST.edl",
|
||||
"test_edl_cdl.edl",
|
||||
"INS4_R1_DX_092117.edl",
|
||||
]
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.files = [
|
||||
"INS4_R1_010417.edl",
|
||||
"INS4_R1_DX_092117.edl",
|
||||
"STP R1 v082517.edl",
|
||||
"ToD_R4_LOCK3.1_030618_Video.edl",
|
||||
"TEST.edl",
|
||||
"test_edl_cdl.edl",
|
||||
"INS4_R1_DX_092117.edl",
|
||||
]
|
||||
|
||||
return super().setUp()
|
||||
|
||||
def test_event_counts(self):
|
||||
|
||||
counts = [287, 466, 250, 376, 120, 3, 466]
|
||||
|
||||
for fn, count in zip(type(self).files, counts):
|
||||
for fn, count in zip(self.files, counts):
|
||||
with open("tests/edls/" + fn, "r") as f:
|
||||
edl = pycmx.parse_cmx3600(f)
|
||||
actual = len(list(edl.events))
|
||||
self.assertTrue(
|
||||
actual == count,
|
||||
"expected %i in file %s but found %i" % (count, fn, actual),
|
||||
f"expected {count} in file {fn} but found {actual}"
|
||||
)
|
||||
|
||||
def test_list_sanity(self):
|
||||
for fn in type(self).files:
|
||||
for fn in self.files:
|
||||
with open("tests/edls/" + fn, "r") as f:
|
||||
edl = pycmx.parse_cmx3600(f)
|
||||
self.assertTrue(type(edl.title) is str)
|
||||
self.assertTrue(len(edl.title) > 0)
|
||||
|
||||
def test_event_sanity(self):
|
||||
for fn in type(self).files:
|
||||
for fn in self.files:
|
||||
path = "tests/edls/" + fn
|
||||
with open(path, "r") as f:
|
||||
edl = pycmx.parse_cmx3600(f)
|
||||
|
||||
Reference in New Issue
Block a user