Skip to content

Commit

Permalink
Python3 migration (#512)
Browse files Browse the repository at this point in the history
Create first cut Python3 build branch, closes #488 when merged into master.
  • Loading branch information
nigelmegitt authored Oct 11, 2019
1 parent a1f9877 commit 4586ecb
Show file tree
Hide file tree
Showing 48 changed files with 190 additions and 177 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

python:
- '2.7'
- '3.7'

branches:
except:
Expand All @@ -21,22 +21,22 @@ before_install:
- git fetch origin -f gh-pages:gh-pages

install:
- pip install pip==9.0.1
- pip install pip==19.2.3
- make
- python setup.py develop
- pip install coveralls
- pip install ghp-import

script:
- pyxbgen --binding-root=./ebu_tt_live/bindings -m __init__ --schema-root=./ebu_tt_live/xsd/ -r -u ebutt_all.xsd
- python setup.py test
- make bindings
- make test
- export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi)
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"

after_success:
- coveralls
- python setup.py build_sphinx
- make docs
- if [ $BRANCH == "master" ]; then ghp-import -n -p -m "Update gh-pages." docs/build; fi

notifications:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all: init ui

init:
pip install --upgrade -r requirements.txt
pyxbgen --binding-root=./ebu_tt_live/bindings -m __init__ --schema-root=./ebu_tt_live/xsd/ -r -u ebutt_all.xsd
pyxbgen --binding-root=. -m __init__ --schema-root=./ebu_tt_live/xsd/ -r -u ebutt_all.xsd --module-prefix=ebu_tt_live.bindings

initnpm:
ifeq ("$(wildcard node_modules)","")
Expand All @@ -20,7 +20,7 @@ docs:
python setup.py build_sphinx

bindings:
pyxbgen --binding-root=./ebu_tt_live/bindings -m __init__ --schema-root=./ebu_tt_live/xsd/ -r -u ebutt_all.xsd
pyxbgen --binding-root=. -m __init__ --schema-root=./ebu_tt_live/xsd/ -r -u ebutt_all.xsd --module-prefix=ebu_tt_live.bindings

ui: uiclean uibuild

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you would like to contribute or join the Slack team, please contact <subtitli
Preparing the build environment
===============================

Make sure you have python 2.7+. Make sure you have python virtual environment capability.
Make sure you have Python 3+. Make sure you have python virtual environment capability.

If not you can install virtualenv systemwide from your operating system's package repository
or by pip:
Expand Down Expand Up @@ -61,7 +61,7 @@ Windows users
=============

Windows is not the best friend of Makefiles. So there is a make.bat file for those who would like to develop using
Windows. Assuming python 2.7 and virtualenv is installed and are on the PATH. To build the project you will also need node.js. Please read the instructions for your system [here](https://nodejs.org/en/download/package-manager/). Then run :
Windows. Assuming Python 3+ and virtualenv is installed and are on the PATH. To build the project you will also need node.js. Please read the instructions for your system [here](https://nodejs.org/en/download/package-manager/). Then run :

make

Expand Down
20 changes: 10 additions & 10 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@
master_doc = 'index'

# General information about the project.
project = u'EBU-TT-Live Toolkit'
copyright = u'2017, European Broadcasting Union'
author = u'European Broadcasting Union'
project = 'EBU-TT-Live Toolkit'
copyright = '2017, European Broadcasting Union'
author = 'European Broadcasting Union'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'2.1.1'
version = '2.1.1'
# The full version, including alpha/beta/rc tags.
release = u'2.1.1'
release = '2.1.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -153,7 +153,7 @@
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#
# html_title = u'EBU-TT-Live Toolkit v1.0.0rc1'
# html_title = 'EBU-TT-Live Toolkit v1.0.0rc1'

# A shorter title for the navigation bar. Default is the same as html_title.
#
Expand Down Expand Up @@ -279,8 +279,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'EBU-TT-LiveToolkit.tex', u'EBU-TT-Live Toolkit Documentation',
u'European Broadcasting Union', 'manual'),
(master_doc, 'EBU-TT-LiveToolkit.tex', 'EBU-TT-Live Toolkit Documentation',
'European Broadcasting Union', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -315,7 +315,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ebu-tt-livetoolkit', u'EBU-TT-Live Toolkit Documentation',
(master_doc, 'ebu-tt-livetoolkit', 'EBU-TT-Live Toolkit Documentation',
[author], 1)
]

Expand All @@ -330,7 +330,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'EBU-TT-LiveToolkit', u'EBU-TT-Live Toolkit Documentation',
(master_doc, 'EBU-TT-LiveToolkit', 'EBU-TT-Live Toolkit Documentation',
author, 'EBU-TT-LiveToolkit', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
8 changes: 3 additions & 5 deletions ebu_tt_live/adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
# ==========


class IDocumentDataAdapter(object):
class IDocumentDataAdapter(object, metaclass=AutoRegisteringABCMeta):
"""
This adapter is used to do various conversions on the payload between the carriage and the node
"""
__metaclass__ = AutoRegisteringABCMeta

__impl_registry = {}
_expects = AbstractStaticMember(validate_types_only)
Expand All @@ -24,7 +23,7 @@ def auto_register_impl(cls, impl_class):
impl_expects = impl_class.expects()
provides_map = cls.__impl_registry.setdefault(impl_expects, weakref.WeakValueDictionary())
impl_provides = impl_class.provides()
if impl_provides in provides_map.keys():
if impl_provides in list(provides_map.keys()):
log.warning(
'({} -> {}) adapter already registered: {}. Ignoring: {} '.format(
impl_expects,
Expand Down Expand Up @@ -83,14 +82,13 @@ def convert_data(self, data, **kwargs):
raise NotImplementedError()


class INodeCarriageAdapter(object):
class INodeCarriageAdapter(object, metaclass=AutoRegisteringABCMeta):
"""
This adapter wraps the DocumentDataAdapter conversion logic and shows a dual interface. It responsibility is
to facilitate direct communication between incompatible carriage mechanisms and processing nodes.
This is a tricky business because this class does not have a hardcoded expects-provides interface contract.
It works it out as it goes forward from the parameters.
"""
__metaclass__ = AutoRegisteringABCMeta

@abstractproperty
def data_adapters(self):
Expand Down
2 changes: 1 addition & 1 deletion ebu_tt_live/adapters/test/test_document_data_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _assert_output_type(self, result):
self.assertIsInstance(result, self._output_type)

def _assert_kwargs_passtrough(self, result_kwargs, expected_keys):
self.assertEquals(set(result_kwargs.keys()), set(expected_keys))
self.assertEqual(set(result_kwargs.keys()), set(expected_keys))

def _get_xml(self):
with open(self._test_xml_path, 'r') as xml_file:
Expand Down
6 changes: 3 additions & 3 deletions ebu_tt_live/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class style_type(StyledElementMixin, IDMixin, SizingValidationMixin, SemanticVal
_default_attrs = None

def __repr__(self):
return u'<style ID: {id} at {addr}>'.format(
return '<style ID: {id} at {addr}>'.format(
id=self.id,
addr=hex(id(self))
)
Expand Down Expand Up @@ -384,7 +384,7 @@ def compute_style(cls, specified_style, parent_computed_style, region_computed_s
else:
computed.lineHeight = computed_line_height

for attr_name in cls._simple_attr_defaults.keys():
for attr_name in list(cls._simple_attr_defaults.keys()):
comp_attr_value = cls.compute_simple_attribute(
attr_name=attr_name,
specified_style=specified_style
Expand All @@ -398,7 +398,7 @@ def compute_style(cls, specified_style, parent_computed_style, region_computed_s
comp_attr_value
)

for attr_name in cls._inherited_attr_defaults.keys():
for attr_name in list(cls._inherited_attr_defaults.keys()):
comp_attr_value = cls.compute_inherited_attribute(
attr_name=attr_name,
specified_style=specified_style,
Expand Down
16 changes: 5 additions & 11 deletions ebu_tt_live/bindings/_ebuttdt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from raw._ebuttdt import *
from raw import _ebuttdt as ebuttdt_raw
from ebu_tt_live.bindings.raw._ebuttdt import *
from ebu_tt_live.bindings.raw import _ebuttdt as ebuttdt_raw
from datetime import timedelta
from decimal import Decimal
import re, logging
Expand Down Expand Up @@ -319,10 +319,7 @@ def as_timedelta(cls, instance):
:param instance:
:return:
"""
hours, minutes, seconds, milliseconds = map(
lambda x: cls._int_or_none(x),
cls._groups_regex.match(instance).groups()
)
hours, minutes, seconds, milliseconds = [cls._int_or_none(x) for x in cls._groups_regex.match(instance).groups()]
return timedelta(hours=hours, minutes=minutes, seconds=seconds, milliseconds=milliseconds)

@classmethod
Expand Down Expand Up @@ -370,10 +367,7 @@ def as_timedelta(cls, instance):
:param instance:
:return:
"""
hours, minutes, seconds, milliseconds = map(
lambda x: cls._int_or_none(x),
cls._groups_regex.match(instance).groups()
)
hours, minutes, seconds, milliseconds = [cls._int_or_none(x) for x in cls._groups_regex.match(instance).groups()]
return timedelta(hours=hours, minutes=minutes, seconds=seconds, milliseconds=milliseconds)

@classmethod
Expand Down Expand Up @@ -559,7 +553,7 @@ def _do_div(self, other):
else:
return NotImplemented

def __div__(self, other):
def __truediv__(self, other):
return self._do_div(other)

def _do_eq(self, other):
Expand Down
6 changes: 3 additions & 3 deletions ebu_tt_live/bindings/_ebuttlm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from raw._ebuttlm import *
from raw import _ebuttlm as raw
from raw import _ebuttp as ebuttp
from ebu_tt_live.bindings.raw._ebuttlm import *
from ebu_tt_live.bindings.raw import _ebuttlm as raw
from ebu_tt_live.bindings.raw import _ebuttp as ebuttp
from pyxb.utils.domutils import BindingDOMSupport


Expand Down
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_ebuttm.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._ebuttm import *
from ebu_tt_live.bindings.raw._ebuttm import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_ebuttp.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._ebuttp import *
from ebu_tt_live.bindings.raw._ebuttp import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_ebutts.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._ebutts import *
from ebu_tt_live.bindings.raw._ebutts import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_ttm.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._ttm import *
from ebu_tt_live.bindings.raw._ttm import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_ttp.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._ttp import *
from ebu_tt_live.bindings.raw._ttp import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/_tts.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from raw._tts import *
from ebu_tt_live.bindings.raw._tts import *
2 changes: 1 addition & 1 deletion ebu_tt_live/bindings/converters/ebutt3_ebuttd.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _link_adjusted_fonts_styling(self, adjusted_fonts, root_element):
root_element.head = d_head_type()
if root_element.head.styling is None:
root_element.head.styling = d_styling_type()
root_element.head.styling.style.extend(adjusted_fonts.values())
root_element.head.styling.style.extend(list(adjusted_fonts.values()))

def convert_tt(self, tt_in, dataset):
dataset['timeBase'] = tt_in.timeBase
Expand Down
44 changes: 22 additions & 22 deletions ebu_tt_live/bindings/test/test_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,83 @@

class TestPixelFontSizeType(TestCase):

_test_string_1 = u'10px'
_test_string_2 = u'10px 20px'
_test_string_1 = '10px'
_test_string_2 = '10px 20px'
_type_class = ebuttdt.PixelFontSizeType

def test_simple_1dim(self):
test_instance = self._type_class(self._test_string_1)
self.assertIsNone(test_instance.horizontal)
self.assertEquals(test_instance.vertical, 10.0)
self.assertEqual(test_instance.vertical, 10.0)
assert test_instance == self._test_string_1

def test_simple_2dim(self):
test_instance = self._type_class(self._test_string_2)
self.assertEquals(test_instance.horizontal, 10.0)
self.assertEquals(test_instance.vertical, 20.0)
self.assertEqual(test_instance.horizontal, 10.0)
self.assertEqual(test_instance.vertical, 20.0)
assert test_instance == self._test_string_2

def test_instantiate_1dim(self):
test_instance = self._type_class(10)
self.assertIsNone(test_instance.horizontal)
self.assertEquals(test_instance.vertical, 10.0)
self.assertEqual(test_instance.vertical, 10.0)
assert test_instance == self._test_string_1

def test_instantiate_2dim(self):
test_instance = self._type_class(10, 20)
self.assertEquals(test_instance.horizontal, 10.0)
self.assertEquals(test_instance.vertical, 20.0)
self.assertEqual(test_instance.horizontal, 10.0)
self.assertEqual(test_instance.vertical, 20.0)
assert test_instance == self._test_string_2


class TestCellFontSizeType(TestPixelFontSizeType):

_test_string_1 = u'10c'
_test_string_2 = u'10c 20c'
_test_string_1 = '10c'
_test_string_2 = '10c 20c'
_type_class = ebuttdt.CellFontSizeType


class TestPercentageFontSizeType(TestPixelFontSizeType):

_test_string_1 = u'10%'
_test_string_2 = u'10% 20%'
_test_string_1 = '10%'
_test_string_2 = '10% 20%'
_type_class = ebuttdt.PercentageFontSizeType


class TestPixelOriginType(TestCase):

_test_string_1 = u'10px'
_test_string_2 = u'20px 10px'
_test_string_1 = '10px'
_test_string_2 = '20px 10px'
_type_class = ebuttdt.PixelOriginType

def test_simple_1dim(self):
self.assertRaises(SimpleTypeValueError, self._type_class, self._test_string_1)

def test_simple_2dim(self):
instance = self._type_class(self._test_string_2)
self.assertEquals(instance.horizontal, 20.0)
self.assertEquals(instance.vertical, 10.0)
self.assertEqual(instance.horizontal, 20.0)
self.assertEqual(instance.vertical, 10.0)
assert instance == self._test_string_2

def test_instantiate_1dim(self):
self.assertRaises(SimpleTypeValueError, self._type_class, 10)

def test_instantiate_2dim(self):
instance = self._type_class(20, 10)
self.assertEquals(instance.horizontal, 20.0)
self.assertEquals(instance.vertical, 10.0)
self.assertEqual(instance.horizontal, 20.0)
self.assertEqual(instance.vertical, 10.0)
assert instance == self._test_string_2


class TestCellOriginType(TestPixelOriginType):

_test_string_1 = u'10c'
_test_string_2 = u'20c 10c'
_test_string_1 = '10c'
_test_string_2 = '20c 10c'
_type_class = ebuttdt.CellOriginType


class TestPercentageOriginType(TestPixelOriginType):

_test_string_1 = u'10%'
_test_string_2 = u'20% 10%'
_test_string_1 = '10%'
_test_string_2 = '20% 10%'
_type_class = ebuttdt.PercentageOriginType
Loading

0 comments on commit 4586ecb

Please sign in to comment.