From e080ddd3f9242015d1c66031d4f0ac89841c38e6 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Tue, 16 May 2023 18:39:42 -0700 Subject: [PATCH] scc: change SccCode class hierarchy to fix incompatibility with Python 3.11 (#386) Bump ubuntu version on CI --- .github/workflows/main.yml | 18 +++++++++--------- .pylintrc | 2 +- src/main/python/ttconv/scc/codes/__init__.py | 6 ++++-- .../python/ttconv/scc/codes/attribute_codes.py | 3 +-- .../python/ttconv/scc/codes/control_codes.py | 5 ++--- .../python/ttconv/scc/codes/mid_row_codes.py | 3 +-- .../ttconv/scc/codes/special_characters.py | 5 ++--- src/main/python/ttconv/scc/reader.py | 4 ++-- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a9c9361..ddd4c454 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,17 +4,17 @@ on: [push, pull_request] jobs: run: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) steps: - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get -y install python3.7 python3-pip - sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 - sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10 - python3.7 -m pip install pipenv - + + - uses: actions/setup-python@v4 + with: + python-version: '3.7' + + - name: Initialize pip environment + run: python -m pip install pipenv + - name: Checkout repo uses: actions/checkout@v2 with: diff --git a/.pylintrc b/.pylintrc index dd23d4e7..f621b6fd 100644 --- a/.pylintrc +++ b/.pylintrc @@ -421,7 +421,7 @@ contextmanager-decorators=contextlib.contextmanager # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E1101 when accessed. Python regular # expressions are accepted. -generated-members= +generated-members=SccAttributeCode.BMS.value # Tells whether missing members accessed in mixin class should be ignored. A # mixin class is detected if its name ends with "mixin" (case insensitive). diff --git a/src/main/python/ttconv/scc/codes/__init__.py b/src/main/python/ttconv/scc/codes/__init__.py index 38272f36..59d4ecbd 100644 --- a/src/main/python/ttconv/scc/codes/__init__.py +++ b/src/main/python/ttconv/scc/codes/__init__.py @@ -25,6 +25,8 @@ """SCC Codes""" +from enum import Enum +from typing import Tuple from ttconv.style_properties import NamedColors SCC_COLOR_MAPPING = { @@ -45,7 +47,7 @@ } -class SccCode: +class SccCode(Enum): """SCC codes base definition class""" def __init__(self, channel_1: int, channel_2: int): @@ -55,7 +57,7 @@ def __init__(self, channel_1: int, channel_2: int): self._channel_1 = channel_1 self._channel_2 = channel_2 - def get_values(self) -> (int, int): + def get_values(self) -> Tuple[int, int]: """Returns SCC Code values""" return self._channel_1, self._channel_2 diff --git a/src/main/python/ttconv/scc/codes/attribute_codes.py b/src/main/python/ttconv/scc/codes/attribute_codes.py index 874ae2ab..d724e4d9 100644 --- a/src/main/python/ttconv/scc/codes/attribute_codes.py +++ b/src/main/python/ttconv/scc/codes/attribute_codes.py @@ -27,14 +27,13 @@ from __future__ import annotations -from enum import Enum from typing import Optional from ttconv.scc.codes import SccCode from ttconv.style_properties import ColorType, NamedColors, TextDecorationType -class SccAttributeCode(SccCode, Enum): +class SccAttributeCode(SccCode): """SCC Foreground and Background Attribute Codes definition""" BWO = (0x1020, 0x1820, ColorType((0xFF, 0xFF, 0xFF, 0xFF))) # Background White, Opaque BWS = (0x1021, 0x1821, ColorType((0xFF, 0xFF, 0xFF, 0x88))) # Background White, Semi-transparent diff --git a/src/main/python/ttconv/scc/codes/control_codes.py b/src/main/python/ttconv/scc/codes/control_codes.py index 092d58c2..b815086c 100644 --- a/src/main/python/ttconv/scc/codes/control_codes.py +++ b/src/main/python/ttconv/scc/codes/control_codes.py @@ -28,12 +28,11 @@ from __future__ import annotations import typing -from enum import Enum from ttconv.scc.codes import SccCode -class SccControlCode(SccCode, Enum): +class SccControlCode(SccCode): """SCC Control Code definition""" AOF = (0x1422, 0x1C22, 0x1522, 0x1D22) # Reserved (formerly Alarm Off) AON = (0x1423, 0x1C23, 0x1523, 0x1D23) # Reserved (formerly Alarm On) @@ -64,7 +63,7 @@ def get_name(self) -> str: """Retrieves Control Code name""" return self.name - def get_values(self) -> (int, int, int, int): + def get_values(self) -> typing.Tuple[int, int, int, int]: """Returns SCC Control Code values""" return self._channel_1, self._channel_2, self._channel_1_field_2, self._channel_2_field_2 diff --git a/src/main/python/ttconv/scc/codes/mid_row_codes.py b/src/main/python/ttconv/scc/codes/mid_row_codes.py index a880cbe0..789b3d07 100644 --- a/src/main/python/ttconv/scc/codes/mid_row_codes.py +++ b/src/main/python/ttconv/scc/codes/mid_row_codes.py @@ -28,13 +28,12 @@ from __future__ import annotations import typing -from enum import Enum from ttconv.scc.codes import SccCode, SCC_COLOR_MAPPING from ttconv.style_properties import FontStyleType, TextDecorationType, ColorType -class SccMidRowCode(SccCode, Enum): +class SccMidRowCode(SccCode): """SCC Mid-Row Code values""" WHITE = (0x1120, 0x1920) WHITE_UNDERLINE = (0x1121, 0x1921) diff --git a/src/main/python/ttconv/scc/codes/special_characters.py b/src/main/python/ttconv/scc/codes/special_characters.py index bfe40d8b..04b87b7c 100644 --- a/src/main/python/ttconv/scc/codes/special_characters.py +++ b/src/main/python/ttconv/scc/codes/special_characters.py @@ -28,12 +28,11 @@ from __future__ import annotations import typing -from enum import Enum from ttconv.scc.codes import SccCode -class SccSpecialCharacter(SccCode, Enum): +class SccSpecialCharacter(SccCode): """SCC Special character definition""" # Special characters specified in CEA-608 @@ -71,7 +70,7 @@ def find(value: int) -> typing.Optional[SccSpecialCharacter]: return None -class SccExtendedCharacter(SccCode, Enum): +class SccExtendedCharacter(SccCode): """SCC Extended character definition""" # Spanish extended characters diff --git a/src/main/python/ttconv/scc/reader.py b/src/main/python/ttconv/scc/reader.py index 9b441536..ede84777 100644 --- a/src/main/python/ttconv/scc/reader.py +++ b/src/main/python/ttconv/scc/reader.py @@ -29,7 +29,7 @@ import copy import logging -from typing import Optional +from typing import Optional, Tuple from ttconv.model import ContentDocument, Body, Div, CellResolutionType, ActiveAreaType from ttconv.scc.codes.attribute_codes import SccAttributeCode @@ -76,7 +76,7 @@ def __init__(self, config: Optional[SccReaderConfiguration] = None): self.roll_up_depth: int = 0 # Cursor position in the active area - self.active_cursor: (int, int) = (0, 0) + self.active_cursor: Tuple[int, int] = (0, 0) self.current_text_decoration = None self.current_color = None