kateliev / TypeRig

Proxy API and Font Development Toolkit for FontLab
https://kateliev.github.io/TypeRig/
BSD 3-Clause "New" or "Revised" License
48 stars 3 forks source link

Cannot import name pFont #56

Closed hyvyys closed 2 years ago

hyvyys commented 3 years ago

Fresh Windows & FontLab 7 installation, installed TypeRig via Scripts > Update/Install, restarted, and failed to run a script:

from typerig.proxy import pFont
cannot import name pFont

What am I missing?

kateliev commented 2 years ago

Hi @hyvyys , this is mainly doe to the fact that after the EOF version the syntax changed a bit. As TR is now Py3 based (and 2.7 backwards compatible) i hat to make some changes. Now the imports are more strict and also the FL (Fontlab) proxy has moved one node deeper.

Correct syntax would be: from typerig.proxy.fl.font import pFont

hyvyys commented 2 years ago

Hi @kateliev, I installed the latest version from this repo, and modified my script to the following:

from typerig.proxy.fl.font import pFont

Now I get this error:

No module named font (line 5): 
Traceback (most recent call last):
  File "<string>", line 5, in <module>
ImportError: No module named font
hyvyys commented 2 years ago
from typerig.proxy.fl.objects.font import pFont

This worked for me instead.

kateliev commented 2 years ago

@hyvyys Yes this is the correct way to do it! Sorry for dropping a word in the suggested solution above!

StefanPeev commented 2 years ago

@kateliev Report of an error in Delta Machine

Traceback (most recent call last): File "C:/Users/Context/Documents/FontLab/FontLab 7/Scripts/Delta Machine/DeltaMachine.py", line 26, in from typerig.proxy.fl.objects.font import pFont File "C:\Users\Context\Documents\FontLab\FontLab 7\python\2.7\site-packages\typerig\proxy\fl\objects\font.py", line 24, in from typerig.proxy.fl.objects.glyph import pGlyph, eGlyph File "C:\Users\Context\Documents\FontLab\FontLab 7\python\2.7\site-packages\typerig\proxy\fl\objects\glyph.py", line 21, in from fontlab_private.fontTools.pens import statisticsPen ImportError: No module named fontlab_private.fontTools.pens

twardoch commented 2 years ago

@kateliev A safe backwards- and future-compatible fix for this would be:

try: 
  from fontlab_private.fontTools.pens import statisticsPen
except ImportError:
  from fontTools.pens import statisticsPen
twardoch commented 2 years ago

(And similar in the other portions that use fontTools)

twardoch commented 2 years ago

Alternatively, you (@kateliev ) might create your own slim proxy for some fontTools objects that does this try/except importing, and in your real code just import that

twardoch commented 2 years ago

@StefanPeev TypeRig is now updated on https://github.com/kateliev/TypeRig