Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fontcExport.glyphsFileFormat plugin #146

Merged
merged 1 commit into from
May 16, 2024

Conversation

anthrotype
Copy link
Contributor

I'm a complete noob so please be kind :)

I believe this is all is needed to add our https://github.com/googlefonts/fontc-export-plugin to the Glyphs.app Plugin Manager, please let me know if I need to modify or add anything thanks!

@florianpircher
Copy link
Collaborator

florianpircher commented May 15, 2024

Hi, thanks for submitting this entry!

On export, I get the following error in the Macro Panel:

$ '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3' -m pip install --disable-pip-version-check --target '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources' -r '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/requirements.txt'
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "__main__.py", line 29
    from pip._internal.cli.main import main as _main
  File "main.py", line 9
    from pip._internal.cli.autocompletion import autocomplete
  File "autocompletion.py", line 10
    from pip._internal.cli.main_parser import create_main_parser
  File "main_parser.py", line 5
    import subprocess
  File "subprocess.py", line 119
    import selectors
  File "selectors.py", line 11
    import math
ImportError: dlopen(/Users/Florian/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/math.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '__PyModule_Add'
Traceback (most recent call last):
  File "GlyphsApp/GlyphsApp/plugins.py", line 259, in exportFont_
  File "plugin.py", line 336, in export
    fontcPath = self.setUpFontc()
                ^^^^^^^^^^^^^^^^^
  File "plugin.py", line 237, in setUpFontc
    run_subprocess_in_macro_window(installCommand, check=True)
  File "plugin.py", line 76, in run_subprocess_in_macro_window
    raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['/Users/Florian/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3', '-m', 'pip', 'install', '--disable-pip-version-check', '--target', '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources', '-r', '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/requirements.txt']' returned non-zero exit status 1.

macOS 14.4.1 (23E224)
Glyphs 3.3 (3306)
Python selected in Glyphs’s settings: 3.11.6 (Glyphs)


Print fontc version works and prints the following:

fontc 0.0.2a9

Clicking the export path does not work, even when the checkbox is checked, nothing happens when clicking on the path.


I assume the How to update the embdedded fontc section in the readme is not for end users of the plugin, but just for people who want to develop/fork the plugin, right? Otherwise, any local changes would get discard by Glyphs’s update process.


The entry in the package index looks good, but plugins often have a screenshot to make them stand out more. If you want, you can include a screenshot of the export dialog or just a simple graphic with a logo.


Let me know if anything is unclear or you need help with anything. I did not look deeply into the plugin source, so there might be something I missed about the workflow.

@anthrotype
Copy link
Contributor Author

Yes those update instructions are for the maintainers of the plugin, not the font developer. The plugin embeds a specific version of fontc fronzen in time, the idea is the whole plugin needs updating if the users wants to update the embedded fontc executable.

I think your python is somehow not set up properly, can you try to reinstall the glyphs python plugin?
It’s failing to import the built in math module which is not even used by our plugin

@anthrotype
Copy link
Contributor Author

Maybe @schriftgestalt knows how to debug/fix this?
I only tested this using the latest beta version of Glyphs.app, I haven’t tried the stable version

@schriftgestalt
Copy link
Owner

Getting pip to work in Glyphs is a bit tricky. We had a discussion about this in with the https://github.com/justinpenner/TalkingLeaves/ plugin.
I added pip to the Glyphs python but it doesn't work properly (the linking to the Python static library is broken and I couldn’t fix it, yet).

So I would recommend to put the binary into the plugin directly, instead of relying on pip to download it.

@florianpircher
Copy link
Collaborator

florianpircher commented May 15, 2024

put the binary into the plugin directly

That might not be easy, as you will need different binaries for ARM and Intel. Maybe you can build a universal binary and serve both. Otherwise, you can offer separate ARM and Intel versions of the plugin, see the readme for details.

@anthrotype
Copy link
Contributor Author

The wheel is already universal2 so works for both architecture.
Sure I can embed the binary directly but it’s a pity that we can’t use pip..

@anthrotype
Copy link
Contributor Author

And why does it work on my machine? I am also using the glyphs python plugin as far as I can tell

@florianpircher
Copy link
Collaborator

Sure I can embed the binary directly but it’s a pity that we can’t use pip..

Yes, we are working towards this, but sadly it’s not working yet.

And why does it work on my machine? I am also using the glyphs python plugin as far as I can tell

It may very well be an issue on my side. @schriftgestalt, can you try if it works for you?

@anthrotype
Copy link
Contributor Author

The “fat” fontc binary weighs 37 MB, checking it in a git repo with all its future iterations as things get updated will make the repository bloat pretty soon

@anthrotype
Copy link
Contributor Author

anthrotype commented May 15, 2024

Alternatively I can download the tar.gz archives with precompiled fontc from Github releases, check their checksums and unpack them inside the plugin without using pip or wheels, just using python stdlib, it’s just a bit more laborious

@florianpircher
Copy link
Collaborator

Updating plugins by re-downloading the latest version as an alternative to Git, another thing on our list. But in this case, the plugin could ship without fontc and fetch the binary from some URL directly, placing it in the Application Support folder somewhere.

@schriftgestalt
Copy link
Owner

And why does it work on my machine? I am also using the glyphs python plugin as far as I can tell
if you have python 3.11 installed, then the Glyphs python will just use it as the files are hard linked to it.

@anthrotype
Copy link
Contributor Author

if you have python 3.11 installed, then the Glyphs python will just use it as the files are hard linked to it.

I see now. Yes I do have Python 3.11 from python.org installed on my machine as well.
So that means this Glyphs Python Plugin is not actually a standalone python distribution because it attempts to dynamicall link to the framework in /Library/Frameworks/Python.framework...

$ otool -L /Users/clupo/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11
/Users/clupo/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11 (architecture x86_64):
	/Library/Frameworks/Python.framework/Versions/3.11/Python (compatibility version 3.11.0, current version 3.11.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
/Users/clupo/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11 (architecture arm64):
	/Library/Frameworks/Python.framework/Versions/3.11/Python (compatibility version 3.11.0, current version 3.11.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

@anthrotype
Copy link
Contributor Author

I think the issue is because the Glyphs Python plugin is created by naively copying a Python.framework from the /Library directory without actually making it relocatable.. Browsing around I found https://github.com/gregneagle/relocatable-python, maybe it could help

@anthrotype
Copy link
Contributor Author

anthrotype commented May 16, 2024

actually it seems to work!

$ python3 make_relocatable_python_framework.py --python-version 3.11.6 --destination dist/ --os-version 11
$ dist/Python.framework/Versions/3.11/bin/python3.11 -m pip install pyobjc

then I replaced the Python.framework inside the Glyphs Python plugin directory with the one I just made, and even when the official /Library/Frameworks/Python.framework is no longer there (I just renamed it to pretend it's not installed and trigger the dyld issue), calling pip from it works!

otool -L now looks like this (notice the @rpath which makes it relative thus relocatable):

$ otool -L /Users/clupo/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11
/Users/clupo/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11 (architecture x86_64):
	@rpath/Versions/3.11/Python (compatibility version 3.11.0, current version 3.11.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
/Users/clupo/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11 (architecture arm64):
	@rpath/Versions/3.11/Python (compatibility version 3.11.0, current version 3.11.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

@schriftgestalt I suggest you repackage the Glyphs Python plugin using the make_relocatable_python_framework.py script

@anthrotype
Copy link
Contributor Author

anthrotype commented May 16, 2024

I used 3.11.6 because that's what the current Glyphs Python Plugin currently has, but you can safely go to 3.11.9 which is the latest 3.11 with a macos universal2 installer: https://www.python.org/downloads/macos/ released April 2024

@schriftgestalt
Copy link
Owner

You are a hero. Thanks for figuring that out.

@schriftgestalt
Copy link
Owner

I pushed the changes. pip should work not.

@florianpircher
Copy link
Collaborator

florianpircher commented May 16, 2024

The plugin does start a download from pypi and then the save dialog is opened where I can pick a location to save the font file. Once I confirm the location, an error message is shown, indicating that something went wrong. This is the output in the Macro Panel:

$ '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3' -m pip install --disable-pip-version-check --target '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources' -r '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/requirements.txt'
Collecting fontc==0.0.2a9 (from -r /Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/requirements.txt (line 3))
  Downloading fontc-0.0.2a9-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (10.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.8/10.8 MB 4.2 MB/s eta 0:00:00
Installing collected packages: fontc
Successfully installed fontc-0.0.2a9
$ '/Users/Florian/Library/Application Support/Glyphs 3/Repositories/fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/bin/fontc' --build-dir '/Users/Florian/Library/Application Support/Glyphs 3/Temp/Neue Schrift-fontc' '/Users/Florian/Library/Application Support/Glyphs 3/Temp/Neue Schrift-fontc/font.glyphs'
Font IR error: 'Unable to parse "/Users/Florian/Library/Application Support/Glyphs 3/Temp/Neue Schrift-fontc/font.glyphs": Unable to read glyphs file: Unable to parse /Users/Florian/Library/Application Support/Glyphs 3/Temp/Neue Schrift-fontc/font.glyphs: Expected numeric value'

This only happens when the document has no file (was not yet saved). Otherwise, it works.


I think this is fine for now. If you want, you can save the current font to a temporary location and export that, if the document has no file. Otherwise, provide an error message explaining that the document first needs to be saved to a file. But this is an edge case, so I would merge this PR for now and you can address this in an update to the plugin.

@florianpircher florianpircher merged commit 2d9e94e into schriftgestalt:glyphs3 May 16, 2024
1 check passed
@florianpircher
Copy link
Collaborator

florianpircher commented May 16, 2024

Note that users will first need to reinstall Python, if they have installed it already, or wait for Glyph’s package update process to install the latest Python from the Package Manager. Glyphs checks for updates on launch and periodically, and installs updates when quitting the app (so no loaded plugins/modules are modified while the app runs).

@anthrotype
Copy link
Contributor Author

The plugin does start a download from pypi and then the save dialog is opened

hm It should only install the first time you do export after you click "Next...", not as soon as the dialog is opened.

an error message is shown, indicating that something went wrong

ok that error simply means fontc couldn't parse the .glypsh file (it's still beta, pls file issue if you can thanks :)

This only happens when the document has no file (was not yet saved). Otherwise, it works.

i'm not sure what you mean "the docment has no file". Do you mean a new font that has never been saved? I actually just tried exporting one after having made sure I removed my local plugin symlink (I have also reinstalled the Glyphs Python plugin that Georg has just made relocatable), and it worked.
I created a new font, drew some stuff and didn't hit save, then exported with fontc, which bootstrapped itself and compiled the font; the input source file was never saved to disk in the regular sense (cmd-S).

If you want, you can save the current font to a temporary location and export that, if the document has no file

that's what we are already doing. We save the current font to a directory inside the Application Support/Glyphs 3/Temp folder, it's suffixed with -fontc (can you see that?)

provide an error message explaining that the document first needs to be saved to a file.

I don't think that's necessary, as I said it should work (worked for me). Maybe your unsaved font contained some stuff that fontc still cannot parse for some reason.

Note that users will first need to reinstall Python

gotcha

Thank you both!

@florianpircher
Copy link
Collaborator

I have shifted the discussion to an issue: googlefonts/fontc-export-plugin#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants