Skip to content

Commit

Permalink
Merge pull request #291 from robotools/fix-ufo-format
Browse files Browse the repository at this point in the history
Fix bw compatibility issue with font.ufoFormatVersion
  • Loading branch information
benkiel committed May 27, 2020
2 parents c0484e1 + 21383c1 commit 0a91e22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 16 additions & 1 deletion Lib/defcon/objects/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,24 @@ def _set_path(self, path):
path = property(_get_path, _set_path, doc="The location of the file on disk. Setting the path should only be done when the user has moved the file in the OS interface. Setting the path is not the same as a save operation.")

def _get_ufoFormatVersion(self):
import warnings

warnings.warn(
"The 'ufoFormatVersion' attribute is deprecated; use the 'ufoFormatVersionTuple'",
DeprecationWarning,
stacklevel=2,
)
if self._ufoFormatVersion is None:
return None
else:
return self._ufoFormatVersion.major

ufoFormatVersion = property(_get_ufoFormatVersion, doc="The UFO format major version that will be used when saving. This is taken from a loaded UFO during __init__. If this font was not loaded from a UFO, this will return None until the font has been saved. Deprecated, use ufoFormatVersionTuple instead.")

def _get_ufoFormatVersionTuple(self):
return self._ufoFormatVersion

ufoFormatVersion = property(_get_ufoFormatVersion, doc="The UFO format version that will be used when saving. This is taken from a loaded UFO during __init__. If this font was not loaded from a UFO, this will return None until the font has been saved.")
ufoFormatVersionTuple = property(_get_ufoFormatVersionTuple, doc="The UFO format (major, minor) version tuple that will be used when saving. This is taken from a loaded UFO during __init__. If this font was not loaded from a UFO, this will return None until the font has been saved.")

def _get_ufoFileStructure(self):
return self._ufoFileStructure
Expand Down
11 changes: 9 additions & 2 deletions Lib/defcon/test/objects/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,19 @@ def test_save_new_font_to_existing_file(self):
elif os.path.isdir(path):
shutil.rmtree(path)

def test_new_font_format(self):
font = Font()
self.assertEqual(font.ufoFormatVersion, None)
self.assertEqual(font.ufoFormatVersionTuple, None)

def test_save_in_place_different_format(self):
path = makeTestFontCopy()
font = Font(path)
self.assertEqual(font._ufoFormatVersion, (3, 0))
self.assertEqual(font.ufoFormatVersion, 3)
self.assertEqual(font.ufoFormatVersionTuple, (3, 0))
font.save(formatVersion=2)
self.assertEqual(font._ufoFormatVersion, (2, 0))
self.assertEqual(font.ufoFormatVersion, 2)
self.assertEqual(font.ufoFormatVersionTuple, (2, 0))

def test_save_in_place_invalid_ufo(self):
path = makeTestFontCopy()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ def run(self):
'pytest>=3.0.3',
],
install_requires=[
"fonttools[ufo,unicode] >= 3.31.0",
"fonttools[ufo,unicode] >= 4.10.0",
],
extras_require={
'pens': ["fontPens>=0.1.0"],
'lxml': ["fonttools[lxml] >= 3.31.0"],
'lxml': ["fonttools[lxml] >= 4.10.0"],
},
cmdclass={
"release": release,
Expand Down

0 comments on commit 0a91e22

Please sign in to comment.