googlefonts / gf-glyphs-scripts

Scripts for Glyphs
21 stars 11 forks source link

io.UnsupportedOperation: seek #38

Closed weiweihuanghuang closed 6 years ago

weiweihuanghuang commented 6 years ago

macOS 10.13.6 GA Version 2.5.2 (1176) fontTools "3.31.0"

Traceback (most recent call last):
  File "fixfonts.py", line 265, in <module>
    main()
  File "fixfonts.py", line 250, in main
    ttfs_gf = download_gf_family(font.familyName)
  File "~/Library/Application Support/Glyphs/Scripts/gf-glyphs-scripts-master/Google Fonts/utils.py", line 66, in download_gf_family
    return fonts_from_zip(family_zip)
  File "~/Library/Application Support/Glyphs/Scripts/gf-glyphs-scripts-master/Google Fonts/utils.py", line 58, in fonts_from_zip
    ttfs.append(TTFont(zipfile.open(file_name)))
  File "~/Library/Application Support/Glyphs/Scripts/fontTools/ttLib/ttFont.py", line 127, in __init__
    file.seek(0)
io.UnsupportedOperation: seek
anthrotype commented 6 years ago

I would have expected this to work if you load TTFont with lazy=False at least, but I see that it’s still trying to call seek(0) method to rewind the stream. Maybe for now try to read all data into an in-memory BytesIO and pass that one to fonttools.

schriftgestalt commented 6 years ago

Is this a python23 problem?

m4rc1e commented 6 years ago

Glyphsapp says I'm running fontTools 3.4.0 which seems crazy because the current is "3.32.1.dev0", https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/__init__.py#L7.

@schriftgestalt Are you supplying a custom version of fontTools for Glyphs?

I'm guessing when you install fontTools using this Glyphsapp menu:

screen shot 2018-11-06 at 10 19 27

It will install a custom fonttools to the system Python.

I can't replicate this issue with my version of fonttools.

schriftgestalt commented 6 years ago

Glyphs gets fonttools from this URL: https://github.com/behdad/fonttools/archive/master.zip

schriftgestalt commented 6 years ago

And by looking at that, I see that it is outdated. I’ll fix this.

weiweihuanghuang commented 6 years ago

I copied in the last fontTools I installed ("3.31.0") from /usr/local/lib/python2.7/site-packages/fontTools/ (some reason Glyphs app doesn't see this?) and I still get the same issue

anthrotype commented 6 years ago

the issue is in the current fonttools, and it's not a py23 issue. basically at some point (can't remember when but probably when behdad added support for writing collection fonts) the TTFont constructor started to call seek(0) on incoming file objects (rewinding them at the start offset), but some streams like the standard input or a zipfile like in your specific case are unseekable by definition. I would like to restore support for those at some point. I suggested a workaround.

anthrotype commented 6 years ago

@schriftgestalt I recommend you use pip (as a subprocess) to install/upgrade fonttools for Glyphs.app. It's not enough to download the tarball from github, unzip and run it. Some modules have extra dependencies now.

anthrotype commented 6 years ago

anyway, the canonical distribution is uploaded to the Python Package Index at each release. https://pypi.org/project/FontTools/#files

anthrotype commented 6 years ago

@schriftgestalt if you want to install third-party modules to some private directory in ~/Library/Application Support/Glyhps that is only in Glyphs' own PYTHONPATH -- you can use pip --target option: https://pip.pypa.io/en/stable/reference/pip_install/?highlight=target#cmdoption-t

pip doesn't support a programmatic API, can only be used as a script; they recommend calling it as a subprocess from other python code.

m4rc1e commented 6 years ago

Thanks Cosimo!

My glyphsapp now has the same fonttools as everyone else. I will produce a workaround.

m4rc1e commented 6 years ago

Alright, I'm closing this.

A fix has been implemented in 681da884830cb3229752d3135dbeb2e1352989ff. Regardless of whether the issue is in fontTools, the script should always run.

@weiweihuanghuang please repull and try again.

I'll keep an eye on the fonttools issue. Thanks everyone.