Skip to content

Commit

Permalink
Remove Python 2 compatibility lines
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Jun 17, 2019
1 parent f6fa241 commit d6f7bb4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 51 deletions.
2 changes: 0 additions & 2 deletions Lib/fontmake/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

from argparse import ArgumentParser
from contextlib import contextmanager

Expand Down
71 changes: 27 additions & 44 deletions Lib/fontmake/font_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import absolute_import, division, print_function, unicode_literals

import glob
import logging
import math
Expand All @@ -24,15 +21,14 @@
from collections import OrderedDict
from contextlib import contextmanager
from functools import partial, wraps
from plistlib import load as readPlist
from re import fullmatch

import ufo2ft
from defcon import Font
from defcon.objects.base import setUfoLibReadValidate, setUfoLibWriteValidate
from fontmake.errors import FontmakeError, TTFAError
from fontmake.ttfautohint import ttfautohint
from fontTools import designspaceLib
from fontTools.misc.loggingTools import Timer, configLogger
from fontTools.misc.py23 import basestring, tobytes, zip
from fontTools.misc.transform import Transform
from fontTools.pens.reverseContourPen import ReverseContourPen
from fontTools.pens.transformPen import TransformPen
Expand All @@ -43,20 +39,8 @@
from ufo2ft.featureWriters import FEATURE_WRITERS_KEY, loadFeatureWriters
from ufo2ft.util import makeOfficialGlyphOrder

try:
from plistlib import load as readPlist # PY3
except ImportError:
from plistlib import readPlist # PY2

try:
from re import fullmatch
except ImportError:
import re

def fullmatch(regex, string, flags=0):
"""Backport of python3.4 re.fullmatch()."""
return re.match("(?:" + regex + r")\Z", string, flags=flags)

from fontmake.errors import FontmakeError, TTFAError
from fontmake.ttfautohint import ttfautohint

logger = logging.getLogger(__name__)
timer = Timer(logging.getLogger("fontmake.timer"), level=logging.DEBUG)
Expand Down Expand Up @@ -129,7 +113,7 @@ def temporarily_disabling_axis_maps(designspace_path):
os.remove(temp_designspace_path)


class FontProject(object):
class FontProject:
"""Provides methods for building fonts."""

def __init__(self, timing=False, verbose="INFO", validate_ufo=False):
Expand Down Expand Up @@ -314,7 +298,7 @@ def build_ttfs(self, ufos, **kwargs):
def _load_designspace_sources(designspace):
if hasattr(designspace, "__fspath__"):
ds_path = designspace.__fspath__()
if isinstance(designspace, basestring):
if isinstance(designspace, str):
ds_path = designspace
else:
# reload designspace from its path so we have a new copy
Expand All @@ -336,7 +320,7 @@ def _build_interpolatable_masters(
conversion_error=None,
feature_writers=None,
cff_round_tolerance=None,
**kwargs
**kwargs,
):
designspace = self._load_designspace_sources(designspace)

Expand Down Expand Up @@ -382,7 +366,7 @@ def build_variable_font(
conversion_error=None,
feature_writers=None,
cff_round_tolerance=None,
**kwargs
**kwargs,
):
"""Build OpenType variable font from masters in a designspace."""
assert not (output_path and output_dir), "mutually exclusive args"
Expand Down Expand Up @@ -436,7 +420,7 @@ def _iter_compile(self, ufos, ttf=False, **kwargs):

for ufo in ufos:
name = self._font_name(ufo)
logger.info("Building {} for {}".format(fmt, name))
logger.info(f"Building {fmt} for {name}")

yield compile_func(ufo, **options)

Expand Down Expand Up @@ -570,7 +554,7 @@ def save_otfs(
overlapsBackend=overlaps_backend,
optimizeCFF=optimize_cff,
roundTolerance=cff_round_tolerance,
**compiler_options
**compiler_options,
)

do_autohint = ttf and autohint is not None
Expand Down Expand Up @@ -732,7 +716,7 @@ def run_from_glyphs(
instance_dir=None,
family_name=None,
mti_source=None,
**kwargs
**kwargs,
):
"""Run toolchain from Glyphs source.
Expand Down Expand Up @@ -847,7 +831,7 @@ def run_from_designspace(
round_instances=False,
feature_writers=None,
expand_features_to_instances=False,
**kwargs
**kwargs,
):
"""Run toolchain from a DesignSpace document to produce either static
instance fonts (ttf or otf), interpolatable or variable fonts.
Expand Down Expand Up @@ -904,14 +888,14 @@ def run_from_designspace(
round_instances=round_instances,
feature_writers=feature_writers,
expand_features_to_instances=expand_features_to_instances,
**kwargs
**kwargs,
)
if interp_outputs:
self._run_from_designspace_interpolatable(
designspace,
outputs=interp_outputs,
feature_writers=feature_writers,
**kwargs
**kwargs,
)

def _run_from_designspace_static(
Expand All @@ -924,13 +908,13 @@ def _run_from_designspace_static(
round_instances=False,
feature_writers=None,
expand_features_to_instances=False,
**kwargs
**kwargs,
):
ufos = []
if not interpolate or masters_as_instances:
ufos.extend(s.path for s in designspace.sources if s.path)
if interpolate:
pattern = interpolate if isinstance(interpolate, basestring) else None
pattern = interpolate if isinstance(interpolate, str) else None
ufos.extend(
self.interpolate_instance_ufos(
designspace,
Expand All @@ -944,7 +928,7 @@ def _run_from_designspace_static(
interpolate_layout_from = interpolate_layout_dir = None
else:
interpolate_layout_from = designspace
if isinstance(interpolate_binary_layout, basestring):
if isinstance(interpolate_binary_layout, str):
interpolate_layout_dir = interpolate_binary_layout
else:
interpolate_layout_dir = None
Expand All @@ -956,7 +940,7 @@ def _run_from_designspace_static(
interpolate_layout_from=interpolate_layout_from,
interpolate_layout_dir=interpolate_layout_dir,
feature_writers=feature_writers,
**kwargs
**kwargs,
)

def _run_from_designspace_interpolatable(
Expand All @@ -979,7 +963,7 @@ def _run_from_designspace_interpolatable(
output_path=output_path,
output_dir=output_dir,
ttf=False,
**kwargs
**kwargs,
)

if "otf-interpolatable" in outputs:
Expand All @@ -1001,12 +985,12 @@ def run_from_ufos(self, ufos, output=(), **kwargs):
# the `ufos` parameter can be a list of UFO objects
# or it can be a path (string) with a glob syntax
ufo_paths = []
if isinstance(ufos, basestring):
if isinstance(ufos, str):
ufo_paths = glob.glob(ufos)
ufos = [Font(x) for x in ufo_paths]
elif isinstance(ufos, list):
# ufos can be either paths or open Font objects, so normalize them
ufos = [Font(x) if isinstance(x, basestring) else x for x in ufos]
ufos = [Font(x) if isinstance(x, str) else x for x in ufos]
ufo_paths = [x.path for x in ufos]
else:
raise FontmakeError(
Expand Down Expand Up @@ -1049,7 +1033,7 @@ def _font_name(self, ufo):
if ufo.info.styleName is not None
else "None"
)
return "{}-{}".format(family_name, style_name)
return f"{family_name}-{style_name}"

def _output_dir(
self,
Expand Down Expand Up @@ -1098,7 +1082,7 @@ def _output_path(
):
"""Generate output path for a font file with given extension."""

if isinstance(ufo_or_font_name, basestring):
if isinstance(ufo_or_font_name, str):
font_name = ufo_or_font_name
elif ufo_or_font_name.path:
font_name = os.path.splitext(
Expand All @@ -1115,9 +1099,9 @@ def _output_path(
os.makedirs(output_dir)

if suffix:
return os.path.join(output_dir, "{}-{}.{}".format(font_name, suffix, ext))
return os.path.join(output_dir, f"{font_name}-{suffix}.{ext}")
else:
return os.path.join(output_dir, "{}.{}".format(font_name, ext))
return os.path.join(output_dir, f"{font_name}.{ext}")

def _designspace_locations(self, designspace):
"""Map font filenames to their locations in a designspace."""
Expand Down Expand Up @@ -1156,7 +1140,6 @@ def buildTables(self):
return

import subprocess
from fontTools.misc.py23 import tostr

outline_path = feasrc_path = fea_path = None
try:
Expand All @@ -1168,7 +1151,7 @@ def buildTables(self):
os.close(fd)

fd, fea_path = tempfile.mkstemp()
os.write(fd, tobytes(self.features, encoding="utf-8"))
os.write(fd, bytes(self.features, encoding="utf-8"))
os.close(fd)

process = subprocess.Popen(
Expand All @@ -1179,7 +1162,7 @@ def buildTables(self):
stdout, stderr = process.communicate()
retcode = process.poll()

report = tostr(stdout + (b"\n" + stderr if stderr else b""))
report = str(stdout + (b"\n" + stderr if stderr else b""))
logger.info(report)

# before afdko >= 2.7.1rc1, makeotf did not exit with non-zero
Expand Down
2 changes: 1 addition & 1 deletion build_pyz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PLATFORMS=(manylinux1_x86_64 macosx_10_6_intel win32 win_amd64)
PYTHON_VERSIONS=(3.6 3.7)
FONTMAKE_VERSION="$(python setup.py --version)"

FONTMAKE_WHEEL="${HERE}/dist/fontmake-${FONTMAKE_VERSION}-py2.py3-none-any.whl"
FONTMAKE_WHEEL="${HERE}/dist/fontmake-${FONTMAKE_VERSION}-py3-none-any.whl"
REQUIREMENTS="${HERE}/requirements.txt"
LICENSE_FILE="${HERE}/LICENSE"

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ requires = [
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ["py27"]
target-version = ["py36"]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[wheel]
universal = 1
universal = 0

[sdist]
formats = zip
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import sys
from io import open

from setuptools import find_packages, setup

Expand Down Expand Up @@ -60,7 +59,6 @@
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Graphics",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
Expand Down

0 comments on commit d6f7bb4

Please sign in to comment.