-
Notifications
You must be signed in to change notification settings - Fork 19
copy lxml-based plistlib module from fonttools/ufoLib2 #160
Conversation
https://github.com/fonttools/ufoLib2/blob/master/src/ufoLib2/plistlib.py replaces the old ufoLib.plistlib shim, privides a single interface similar to python3's stdlib `plistlib` module, but built on top of lxml. On python < 3, it requires the singledispatch backport. This will be added as conditional installation requirement.
and also set maximum version limit to the next major version of each install_requires, to prevent breakages when major version bumps
this is basically the same cpython plistlib test suite, rewritten as pytest-style tests
for consistency with glifLib
@anthrotype I’m out this week, and think @typesupply is too, if this looks good to you, feel free to merge and cut a 3.0 release as discussed. Thanks for this! |
enjoy you holidays! 🌞 |
we right-justifiy binary data text to max 76 chars (min 16) per line similarly to the way the stdlib plistlib module does (although they use tabs for indentation, equivalent to 8-spaces). We write the plist doctype ourselves, otherwise lxml always adds a newline to it (even wen pretty_print is False).
since 'lib' element is itself contained in 'glyph' root element
I think this is ready to be merged, but another pair of eyes won't hurt. |
I would not change the api of Im missing |
no prob, I'll make backward compatible functions for those to avoid breaking backward compat. |
but can I throw a deprecation warning and suggest to use |
deprecated warning are fine, if not it will break lots of scripts outside ufoLib |
by the way, in the link to that glifViewer extension I don't see any usage of ufoLib.plistlib.readPlist or writePlist, but only of ufoLib.glifLib.readGlyphFromString and writeGlyphToString, which I didn't modify here (they keep working as before). |
and defcon itself doesn't seem to be importing its |
I just wonder, was the Having said that, I'm going to add aliases with deprecation warnings anyway |
oh true, my mistake... (just scared with those kinds of changes) in defcon Im finding this: https://github.com/typesupply/defcon/blob/master/Lib/defcon/objects/layerSet.py#L500 I can change that... |
too late, I've implemeted them :) |
I hate doctests :(
the old readPlist, writePlist, readPlistFromString and writePlistToString are back, with this commit: Another difference that's worth mentioning here between this new In the old python2 In the python3's I chose not implement this in the new ufoLib.plistlib. The behaviour of the new module is the same as the python3's This means that, if you are using python2 and you do not import I think there won't be issues at least in ufoLib or defcon becuase we ported these to py3 since long time and we have gotten accustomed to treating textual data as |
@anthrotype I've tried integrating up to 9735cdc into afdko and got two changes:
- <string>Source Serif Pro</string>
+ <data>
+ U291cmNlIFNlcmlmIFBybw==
+ </data>
- <string>SourceSerifPro-Light</string>
+ <data>
+ U291cmNlU2VyaWZQcm8tTGlnaHQ=
+ </data>
- <string>Light</string>
+ <data>
+ TGlnaHQ=
+ </data> |
that's a feature, right? Finally we get consistent indentation between the GLIF xml files (which have always used 2 spaces) and the plist files (which the standard library's plistlib writer always writes with tabs). With lxml we don't have a choice, so we use 2 spaces everywhere :)
I've explained this in the comment above #160 (comment) you need to make sure you use |
if you are concerned about diff in whitespace and similar stuff, I'd recommend you use the ufonormalizer. |
anyway, thanks Miguel for checking! 👍 |
Fair enough.
Thanks for the details. Have to figure out which of our scripts need to be updated. |
@anthrotype do you think you'll release a new version before Monday, when pyup comes knocking on our door again? |
@anthrotype I've tracked down the data vs. string issue to from mutatorMath.ufo import build
dsPath = 'adobe-type-tools/afdko/Tests/makeinstancesufo_data/input/font.designspace'
build(documentPath=dsPath) Open the |
There's one in <key>creator</key>
- <string>org.robofab.ufoLib</string>
+ <data>
+ b3JnLnJvYm9mYWIudWZvTGli
+ </data> |
Adding |
I added unicode_literals to all modules in the other PR I’m working, it fixed the issue you mentioned I’ll take a look at the mutatormath issue tomorrow, and yes I’ll to make a release before then. Have a nice weekend |
This PR replaces the
ufoLib.plistlib
module with the one from https://github.com/fonttools/ufoLib2/blob/master/src/ufoLib2/plistlib.pyThe module provides the same interface for both py2 and py3 but this time using the python3's
plistlib
module API, not the python2's as the old ufoLib.plistlib.It's also faster because it's written on top of lxml (which is now required by ufoLib), so we don't need to first serialise using the built-in plistlib, then parse as generic XML and re-serialise when we write the GLIF lib element.
For python 2.7, this module has an additional requirement on singledispatch, a backport of
https://docs.python.org/3/library/functools.html#functools.singledispatch
On python 3 this is built into the standard library functools module. This is used to define generic functions whose implementation depends on the type of the first argument (see
_make_element
and how it's used inplistlib.totree
). It does make things a bit faster (about 4% faster to build an element tree from plist data when compared to a more straightforward tree builder with a big if statement --fonttools/ufoLib2@7d5fee5), besides making the code look cleaner and more idiomatic.The module includes a full test suite borrowed from the cpython's test_plistlib.py, but rewritten to use pytest-style tests (we already use pytest as test runner here).