13rac1 / scfbuild

Create OpenType-SVG color fonts from a set of SVG source files.
GNU General Public License v3.0
81 stars 12 forks source link

Python 3 support #18

Closed earboxer closed 4 years ago

earboxer commented 5 years ago

Python 2 is less than a year from end of life. https://pythonclock.org/

We should update this project to Python 3

13rac1 commented 5 years ago

Yes. I've been waiting for Fontforge.

earboxer commented 5 years ago

Apparently Fontforge has had support for python3 for quite a while, (but from what I tried, I was only able to install a binding for one version at a time). What binding you get depends on your package maintainer (in Ubuntu 18.04, installing fontforge with apt-get only gave me the python2 bindings). This PR will allow brew (and shortly linuxbrew) to install the python3 bindings instead of python2.

13rac1 commented 5 years ago

Potentially blocked by https://github.com/fontforge/fontforge/issues/1731 You can see my comments from way back in 2016 about this problem. I should have made an issue on this project to track it then :laughing:

I'm concerned about dealing with linuxbrew for this. Call me Mr GumpyPants 😾 :jeans: , but I already have apt debs, snaps, and flatpaks. Another package manager is asking for hassles, unless I switch entirely to a Docker build. There's no rush to make this change yet, so I prefer to wait on an updated PPA. This comment https://github.com/fontforge/fontforge/issues/1731#issuecomment-495962903 mentions https://launchpad.net/~silnrsi/+archive/ubuntu/smith-py3/ but that PPA hasn't had a new build for fontforge since 2019-01-26. Low priority TODO list to do it myself...

earboxer commented 5 years ago

That's perfectly reasonable. I was mostly glad at how easy it was to update scfbuild to Python3 (after figuring out the fontforge python3 bindings).

Maybe in the meantime, we could make scfbuild bilingual. As I understand it, most major python libraries are already bilingual (though many, including fonttools, have pledged to drop python2 support). In https://github.com/13rac1/scfbuild/pull/19/files, this would mean just

if (1/2 == 0.5):
  record.string = text
else:
  # In Python2, strings need to be forced to unicode.
  record.string = unicode(text)

and

if (1/2 == 0.5):
  # unichr type doesn't exist in python3, as everything is already unicode.
  unichr = chr
u_str = ''.join(map(unichr, u_ids))

Though it might be nice to use something better than (1/2 == 0.5) to check python version. I don't know what the standard practice is for this.

Proximyst commented 5 years ago

Consider this?

import six

if six.PY2:
  # this is python2.x
else:
  # six.PY3
  # this is python3.x
earboxer commented 5 years ago

I think if sys.version_info[0] >= 3: is the way to go...