Remove python2 support from tests/utils scripts

This commit is contained in:
Ebrahim Byagowi 2020-02-19 14:56:55 +03:30
parent 2c9fbf5561
commit 8d19907704
27 changed files with 35 additions and 158 deletions

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Copied from https://github.com/xantares/mingw-ldd/blob/master/mingw-ldd.py # Copied from https://github.com/xantares/mingw-ldd/blob/master/mingw-ldd.py
# Modified to point to right prefix location on Fedora. # Modified to point to right prefix location on Fedora.
# WTFPL - Do What the Fuck You Want to Public License # WTFPL - Do What the Fuck You Want to Public License
from __future__ import print_function
import pefile import pefile
import os import os
import sys import sys

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import io, os.path, sys import io, os.path, sys

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import io, os, re, sys import io, os, re, sys

View File

@ -1,6 +1,5 @@
#!/usr/bin/python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys import sys
import os.path import os.path
from collections import OrderedDict from collections import OrderedDict

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import io, sys import io, sys

View File

@ -1,13 +1,9 @@
#!/usr/bin/python #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Generates the code for a sorted unicode range array as used in hb-ot-os2-unicode-ranges.hh # Generates the code for a sorted unicode range array as used in hb-ot-os2-unicode-ranges.hh
# Input is a tab seperated list of unicode ranges from the otspec # Input is a tab seperated list of unicode ranges from the otspec
# (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur). # (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur).
from __future__ import print_function, division, absolute_import
import io import io
import re import re
import sys import sys

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python3
"""Generator of the mapping from OpenType tags to BCP 47 tags and vice """Generator of the mapping from OpenType tags to BCP 47 tags and vice
versa. versa.
@ -22,8 +22,6 @@ Input files:
- https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry - https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
""" """
from __future__ import absolute_import, division, print_function, unicode_literals
import collections import collections
try: try:
from HTMLParser import HTMLParser from HTMLParser import HTMLParser
@ -758,7 +756,7 @@ ot.add_language ('und-Syre', 'SYRE')
ot.add_language ('und-Syrj', 'SYRJ') ot.add_language ('und-Syrj', 'SYRJ')
ot.add_language ('und-Syrn', 'SYRN') ot.add_language ('und-Syrn', 'SYRN')
bcp_47.names['xst'] = u"Silt'e" bcp_47.names['xst'] = "Silt'e"
bcp_47.scopes['xst'] = ' (retired code)' bcp_47.scopes['xst'] = ' (retired code)'
bcp_47.macrolanguages['xst'] = {'stv', 'wle'} bcp_47.macrolanguages['xst'] = {'stv', 'wle'}
@ -865,7 +863,7 @@ def hb_tag (tag):
Returns: Returns:
A snippet of C++ representing ``tag``. A snippet of C++ representing ``tag``.
""" """
return u"HB_TAG('%s','%s','%s','%s')" % tuple (('%-4s' % tag)[:4]) return "HB_TAG('%s','%s','%s','%s')" % tuple (('%-4s' % tag)[:4])
def get_variant_set (name): def get_variant_set (name):
"""Return a set of variant language names from a name. """Return a set of variant language names from a name.
@ -877,7 +875,7 @@ def get_variant_set (name):
Returns: Returns:
A set of normalized language names. A set of normalized language names.
""" """
return set (unicodedata.normalize ('NFD', n.replace ('\u2019', u"'")) return set (unicodedata.normalize ('NFD', n.replace ('\u2019', "'"))
.encode ('ASCII', 'ignore') .encode ('ASCII', 'ignore')
.strip () .strip ()
for n in re.split ('[\n(),]', name) if n) for n in re.split ('[\n(),]', name) if n)

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import io, os.path, sys, re import io, os.path, sys, re
import logging import logging

View File

@ -1,8 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python3
# flake8: noqa # flake8: noqa
from __future__ import print_function, division, absolute_import
import io import io
import sys import sys

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python3
"""Generator of the function to prohibit certain vowel sequences. """Generator of the function to prohibit certain vowel sequences.
@ -9,8 +9,6 @@ This function should be used as the ``preprocess_text`` of an
""" """
from __future__ import absolute_import, division, print_function, unicode_literals
import collections import collections
try: try:
from HTMLParser import HTMLParser from HTMLParser import HTMLParser

View File

@ -1,27 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
import sys import sys
import array import array
from gi.repository import HarfBuzz as hb from gi.repository import HarfBuzz as hb
from gi.repository import GLib from gi.repository import GLib
# Python 2/3 compatibility
try:
unicode
except NameError:
unicode = str
def tounicode(s, encoding='utf-8'):
if not isinstance(s, unicode):
return s.decode(encoding)
else:
return s
fontdata = open (sys.argv[1], 'rb').read () fontdata = open (sys.argv[1], 'rb').read ()
text = tounicode(sys.argv[2]) text = sys.argv[2]
# Need to create GLib.Bytes explicitly until this bug is fixed: # Need to create GLib.Bytes explicitly until this bug is fixed:
# https://bugzilla.gnome.org/show_bug.cgi?id=729541 # https://bugzilla.gnome.org/show_bug.cgi?id=729541
blob = hb.glib_blob_create (GLib.Bytes.new (fontdata)) blob = hb.glib_blob_create (GLib.Bytes.new (fontdata))

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys, os, subprocess, tempfile, threading import sys, os, subprocess, tempfile, threading

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys, os, subprocess, tempfile, threading import sys, os, subprocess, tempfile, threading

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys import sys
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *
import sys, os import sys, os

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from hb_test_tools import * from hb_test_tools import *

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys, os, re, difflib, unicodedata, errno, cgi import sys, os, re, difflib, unicodedata, errno, cgi
from itertools import * from itertools import *
@ -15,78 +13,6 @@ diff_colors = ['red', 'green', 'blue']
def codepoints(s): def codepoints(s):
return (ord (u) for u in s) return (ord (u) for u in s)
try:
unichr = unichr
if sys.maxunicode < 0x10FFFF:
# workarounds for Python 2 "narrow" builds with UCS2-only support.
_narrow_unichr = unichr
def unichr(i):
"""
Return the unicode character whose Unicode code is the integer 'i'.
The valid range is 0 to 0x10FFFF inclusive.
>>> _narrow_unichr(0xFFFF + 1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
>>> unichr(0xFFFF + 1) == u'\U00010000'
True
>>> unichr(1114111) == u'\U0010FFFF'
True
>>> unichr(0x10FFFF + 1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: unichr() arg not in range(0x110000)
"""
try:
return _narrow_unichr(i)
except ValueError:
try:
padded_hex_str = hex(i)[2:].zfill(8)
escape_str = "\\U" + padded_hex_str
return escape_str.decode("unicode-escape")
except UnicodeDecodeError:
raise ValueError('unichr() arg not in range(0x110000)')
def codepoints(s):
high_surrogate = None
for u in s:
cp = ord (u)
if 0xDC00 <= cp <= 0xDFFF:
if high_surrogate:
yield 0x10000 + (high_surrogate - 0xD800) * 0x400 + (cp - 0xDC00)
high_surrogate = None
else:
yield 0xFFFD
else:
if high_surrogate:
yield 0xFFFD
high_surrogate = None
if 0xD800 <= cp <= 0xDBFF:
high_surrogate = cp
else:
yield cp
high_surrogate = None
if high_surrogate:
yield 0xFFFD
except NameError:
unichr = chr
try:
unicode = unicode
except NameError:
unicode = str
def tounicode(s, encoding='ascii', errors='strict'):
if not isinstance(s, unicode):
return s.decode(encoding, errors)
else:
return s
class ColorFormatter: class ColorFormatter:
class Null: class Null:
@ -460,7 +386,7 @@ class Unicode:
@staticmethod @staticmethod
def decode (s): def decode (s):
return u','.join ("U+%04X" % cp for cp in codepoints (tounicode (s, 'utf-8'))) return ','.join ("U+%04X" % cp for cp in codepoints (s))
@staticmethod @staticmethod
def parse (s): def parse (s):
@ -470,9 +396,7 @@ class Unicode:
@staticmethod @staticmethod
def encode (s): def encode (s):
s = u''.join (unichr (x) for x in Unicode.parse (s)) return ''.join (chr (x) for x in Unicode.parse (s))
if sys.version_info[0] == 2: s = s.encode ('utf-8')
return s
shorthands = { shorthands = {
"ZERO WIDTH NON-JOINER": "ZWNJ", "ZERO WIDTH NON-JOINER": "ZWNJ",
@ -508,8 +432,8 @@ class Unicode:
def pretty_names (s): def pretty_names (s):
s = re.sub (r"[<+>\\uU]", " ", s) s = re.sub (r"[<+>\\uU]", " ", s)
s = re.sub (r"0[xX]", " ", s) s = re.sub (r"0[xX]", " ", s)
s = [unichr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)] s = [chr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)]
return u' + '.join (Unicode.pretty_name (x) for x in s).encode ('utf-8') return ' + '.join (Unicode.pretty_name (x) for x in s).encode ('utf-8')
class FileHelpers: class FileHelpers:

View File

@ -115,7 +115,7 @@ exec 3<"$unicodes_file"
exec 4<"$glyphs_file" exec 4<"$glyphs_file"
relative_subset="$subset" relative_subset="$subset"
if test "$out" != "/dev/stdout"; then if test "$out" != "/dev/stdout"; then
relative_subset="$(/usr/bin/python -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")" relative_subset="$(/usr/bin/env python3 -c 'import os, sys; print (os.path.relpath (sys.argv[1], sys.argv[2]))' "$subset" "$(dirname "$out")")"
fi fi
while read uline <&3 && read gline <&4; do while read uline <&3 && read gline <&4; do
echo "$relative_subset:$options:$uline:$gline" >> "$out" echo "$relative_subset:$options:$uline:$gline" >> "$out"

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function, division, absolute_import
import sys, os, subprocess, hashlib, tempfile, shutil import sys, os, subprocess, hashlib, tempfile, shutil

View File

@ -1,10 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Pre-generates the expected output subset files (via fonttools) for # Pre-generates the expected output subset files (via fonttools) for
# specified subset test suite(s). # specified subset test suite(s).
from __future__ import print_function, division, absolute_import
import io import io
import os import os
import sys import sys

View File

@ -1,10 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Runs a subsetting test suite. Compares the results of subsetting via harfbuzz # Runs a subsetting test suite. Compares the results of subsetting via harfbuzz
# to subsetting via fonttools. # to subsetting via fonttools.
from __future__ import print_function, division, absolute_import
import io import io
from difflib import unified_diff from difflib import unified_diff
import os import os

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import io import io
import os import os