googlefonts / pyfontaine

Python tool to check font files for language/character set support
https://github.com/googlefonts/pyfontaine
GNU General Public License v3.0
104 stars 20 forks source link

Python 3 seems to be unsupported #101

Closed devosb closed 5 years ago

devosb commented 5 years ago

I ran pyfontaine U+0041 CharisSIL-R.ttf and the result was

Traceback (most recent call last):
  File "/home/bobby/.local/bin/pyfontaine", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/srv/bobby/builds/pyfontaine3/bin/pyfontaine", line 448, in <module>
    main()
  File "/srv/bobby/builds/pyfontaine3/bin/pyfontaine", line 219, in main
    unicodecode = check_for_unicodechar(filename)
  File "/srv/bobby/builds/pyfontaine3/bin/pyfontaine", line 189, in check_for_unicodechar
    char = char.decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

while using Python 3 on Ubuntu Bionic amd64

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux

If I use python 2

Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2

then I get the expected output of

Font             U+0041
CharisSIL-R.ttf  True

The difference was Python 2 versus 3. Am I missing something to get pyfontaine to run under Python 3?

achmurzy commented 5 years ago

I came to a similar conclusion. For me, the code attempts to import the 'StringIO' module which was deprecated in Python3. Would love to use this tool but need Python 3

davelab6 commented 5 years ago

I just got

pyfontaine
Traceback (most recent call last):
  File "/usr/local/bin/pyfontaine", line 25, in <module>
    from fontaine.cmap import library
  File "/usr/local/lib/python3.7/site-packages/fontaine/cmap.py", line 56
    except (ImportError, AttributeError), ex:
                                        ^
SyntaxError: invalid syntax

@felipesanches please could you take a look at this as a "p0" as I need this tool right now to do my work, and that it isn't working is super frustrating :)

felipesanches commented 5 years ago

sure!

I'll try to fix this tomorrow asap.

felipesanches commented 5 years ago

I am now working on a port to python 3. I think it will not take much time, while also not being super trivial. But I think it is worth the effort.

And there's also a pretty good outcome of porting it to python 3: using it as a dependency of fontbakery to chart glyph coverage of several glyph sets on the font families being checked.

felipesanches commented 5 years ago

The reason for the several commits in this issue is that I am amending and pushing my single-commit for the port to python 3 and observing the build logs on Travis.

Even though we lack a test suite in this project, I configured Travis to run all of the usage examples from our README and ensurer none of them crash.

felipesanches commented 5 years ago

@davelab6, @devosb, @achmurzy: Now the code from git master should be python 3 compatible. Please let me know if you see something that does not work.