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'
|
requires-python = '>3.8'
|
||||||
classifiers = [
|
classifiers = [
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'License :: OSI Approved :: MIT License',
|
|
||||||
'Topic :: Multimedia',
|
'Topic :: Multimedia',
|
||||||
'Topic :: Multimedia :: Video',
|
'Topic :: Multimedia :: Video',
|
||||||
'Topic :: Text Processing',
|
'Topic :: Text Processing',
|
||||||
@@ -60,19 +59,6 @@ indent-width = 4
|
|||||||
[tool.ruff.format]
|
[tool.ruff.format]
|
||||||
docstring-code-line-length = 88
|
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]
|
[build-system]
|
||||||
requires = ["uv_build>=0.9.18,<0.12"]
|
requires = ["uv_build>=0.9.18,<0.12"]
|
||||||
build-backend = "uv_build"
|
build-backend = "uv_build"
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class ChannelMap:
|
|||||||
Represents a set of all the channels to which an event applies.
|
Represents a set of all the channels to which an event applies.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, v=False, audio_channels=set()):
|
def __init__(self, v=False, audio_channels=None):
|
||||||
self._audio_channel_set = audio_channels
|
self._audio_channel_set = audio_channels or set()
|
||||||
self.v = v
|
self.v = v
|
||||||
self._chan_map: dict[str, tuple] = {
|
self._chan_map: dict[str, tuple] = {
|
||||||
"V": (True, False, False),
|
"V": (True, False, False),
|
||||||
|
|||||||
+15
-14
@@ -1,7 +1,8 @@
|
|||||||
# pycmx
|
# pycmx
|
||||||
# (c) 2023-2025 Jamie Hardt
|
# (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 .edit import Edit
|
||||||
from .statements import (
|
from .statements import (
|
||||||
@@ -33,7 +34,7 @@ class Event:
|
|||||||
return int(self._edit_statements()[0].event)
|
return int(self._edit_statements()[0].event)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def edits(self) -> List[Edit]:
|
def edits(self) -> list[Edit]:
|
||||||
"""
|
"""
|
||||||
Returns the edits. Most events will have a single edit, a single event
|
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
|
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
|
# The list the_zip contains one element for each initialization
|
||||||
# parameter in Edit()
|
# 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
|
# 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
|
# "FROM" and "TO" clip name lines. Otherwise we just look for on
|
||||||
# each per edit.
|
# each per edit.
|
||||||
if len(edits_audio) == 2:
|
if len(edits_audio) == 2:
|
||||||
start_name: Optional[StmtClipName] = None
|
start_name: StmtClipName | None = None
|
||||||
end_name: Optional[StmtClipName] = None
|
end_name: StmtClipName | None = None
|
||||||
|
|
||||||
for clip_name in clip_names:
|
for clip_name in clip_names:
|
||||||
if clip_name.affect == "from":
|
if clip_name.affect == "from":
|
||||||
@@ -91,7 +92,7 @@ class Event:
|
|||||||
# attach effects name to last event
|
# attach effects name to last event
|
||||||
try:
|
try:
|
||||||
trans_statement = self._trans_name_statements()[0]
|
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)
|
trans_names.append(trans_statement)
|
||||||
the_zip.append(trans_names)
|
the_zip.append(trans_names)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -120,21 +121,21 @@ class Event:
|
|||||||
if type(s) is StmtUnrecognized:
|
if type(s) is StmtUnrecognized:
|
||||||
yield s
|
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]
|
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]
|
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]
|
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]
|
return [s for s in self.statements if type(s) is StmtSourceFile]
|
||||||
|
|
||||||
def _statements_with_audio_ext(
|
def _statements_with_audio_ext(
|
||||||
self,
|
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:
|
if len(self.statements) == 1 and type(self.statements[0]) is StmtEvent:
|
||||||
yield (self.statements[0], None)
|
yield (self.statements[0], None)
|
||||||
@@ -146,11 +147,11 @@ class Event:
|
|||||||
elif type(s1) is StmtEvent:
|
elif type(s1) is StmtEvent:
|
||||||
yield (s1, None)
|
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)
|
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)
|
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)
|
return next((s for s in self.statements if type(s) is StmtFrmc), None)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
# pycmx
|
# pycmx
|
||||||
# (c) 2018-2025 Jamie Hardt
|
# (c) 2018-2025 Jamie Hardt
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import List, TextIO
|
from typing import TextIO
|
||||||
|
|
||||||
from .cdl import AscSopComponents, Rgb
|
from .cdl import AscSopComponents, Rgb
|
||||||
from .statements import (
|
from .statements import (
|
||||||
@@ -24,7 +26,7 @@ from .statements import (
|
|||||||
from .util import collimate
|
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.
|
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 [
|
return [
|
||||||
event_field_length,
|
event_field_length,
|
||||||
2,
|
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]
|
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)
|
return StmtRemark(line, line_number)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -267,7 +269,7 @@ def _parse_columns_for_standard_form(
|
|||||||
raise EventFormError()
|
raise EventFormError()
|
||||||
|
|
||||||
return StmtEvent(
|
return StmtEvent(
|
||||||
event=column_strings[0],
|
event=int(column_strings[0]),
|
||||||
source=column_strings[2].strip(),
|
source=column_strings[2].strip(),
|
||||||
channels=channels,
|
channels=channels,
|
||||||
trans=trans,
|
trans=trans,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# pycmx
|
# pycmx
|
||||||
# (c) 2023 Jamie Hardt
|
# (c) 2023 Jamie Hardt
|
||||||
|
|
||||||
from typing import Optional
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
class Transition:
|
class Transition:
|
||||||
@@ -22,7 +22,7 @@ class Transition:
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def kind(self) -> Optional[str]:
|
def kind(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
Return the kind of transition: Cut, Wipe, etc.
|
Return the kind of transition: Cut, Wipe, etc.
|
||||||
"""
|
"""
|
||||||
@@ -64,7 +64,7 @@ class Transition:
|
|||||||
return int(self.operand)
|
return int(self.operand)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wipe_number(self) -> Optional[int]:
|
def wipe_number(self) -> int | None:
|
||||||
"Wipes are identified by a particular number."
|
"Wipes are identified by a particular number."
|
||||||
if self.wipe:
|
if self.wipe:
|
||||||
return int(self.transition[1:])
|
return int(self.transition[1:])
|
||||||
|
|||||||
+3
-1
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
# Utility functions
|
# 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
|
Split a list-type thing, like a string, into slices that are column_widths
|
||||||
length.
|
length.
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# ruff: noqa: SIM115
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from pycmx import parse_cmx3600
|
from pycmx import parse_cmx3600
|
||||||
|
|||||||
+9
-5
@@ -4,7 +4,9 @@ import pycmx
|
|||||||
|
|
||||||
|
|
||||||
class TestParse(TestCase):
|
class TestParse(TestCase):
|
||||||
files = [
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.files = [
|
||||||
"INS4_R1_010417.edl",
|
"INS4_R1_010417.edl",
|
||||||
"INS4_R1_DX_092117.edl",
|
"INS4_R1_DX_092117.edl",
|
||||||
"STP R1 v082517.edl",
|
"STP R1 v082517.edl",
|
||||||
@@ -14,28 +16,30 @@ class TestParse(TestCase):
|
|||||||
"INS4_R1_DX_092117.edl",
|
"INS4_R1_DX_092117.edl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
return super().setUp()
|
||||||
|
|
||||||
def test_event_counts(self):
|
def test_event_counts(self):
|
||||||
|
|
||||||
counts = [287, 466, 250, 376, 120, 3, 466]
|
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:
|
with open("tests/edls/" + fn, "r") as f:
|
||||||
edl = pycmx.parse_cmx3600(f)
|
edl = pycmx.parse_cmx3600(f)
|
||||||
actual = len(list(edl.events))
|
actual = len(list(edl.events))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
actual == count,
|
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):
|
def test_list_sanity(self):
|
||||||
for fn in type(self).files:
|
for fn in self.files:
|
||||||
with open("tests/edls/" + fn, "r") as f:
|
with open("tests/edls/" + fn, "r") as f:
|
||||||
edl = pycmx.parse_cmx3600(f)
|
edl = pycmx.parse_cmx3600(f)
|
||||||
self.assertTrue(type(edl.title) is str)
|
self.assertTrue(type(edl.title) is str)
|
||||||
self.assertTrue(len(edl.title) > 0)
|
self.assertTrue(len(edl.title) > 0)
|
||||||
|
|
||||||
def test_event_sanity(self):
|
def test_event_sanity(self):
|
||||||
for fn in type(self).files:
|
for fn in self.files:
|
||||||
path = "tests/edls/" + fn
|
path = "tests/edls/" + fn
|
||||||
with open(path, "r") as f:
|
with open(path, "r") as f:
|
||||||
edl = pycmx.parse_cmx3600(f)
|
edl = pycmx.parse_cmx3600(f)
|
||||||
|
|||||||
Reference in New Issue
Block a user