justinpenner / TalkingLeaves

A GlyphsApp plugin to help you explore the world’s languages and writing systems
MIT License
27 stars 2 forks source link

Smoother dependency install process #2

Open justinpenner opened 3 months ago

justinpenner commented 3 months ago

Installing dependencies for Glyphs scripts and plugins is tricky. TalkingLeaves requires a few Python libraries (hyperglot, urlreader, vanilla, objc), but installing and managing these modules is complicated due to the following factors:

What all of that boils down to is: Glyphs gives developers two recommended methods for installing packages (Scripts/site-packages and the Plugin Manager). The former method is less user-friendly and has potential for conflicts between plugins. The latter forces plugins to use the same version of modules, eliminating conflicts but also eliminating the developer's choice of module versions. The latter also forces important modules like Vanilla to be beholden to the Glyphs Vanilla fork, which is not updated when the upstream Vanilla is updated.

So, the only package management system I can imagine that solves all these problems, is a custom one that allows TalkingLeaves to install and use any packages, but keeps them private from other plugins. I suspect this could be done in some way, but I need to test some ideas.

justinpenner commented 3 months ago

I tested some things. I think I could write a script, call it gpip.py and drop it into the plugin's Resources folder. The script would be a module that searches for any pip that's already installed on the system, and uses it to install the necessary modules, targeting them to a private folder like Plugins/TalkingLeaves-packages/_tl. Then, if I append Plugins/TalkingLeaves-packages to sys.path, the plugin will be able to use a private prefix like import _tl.hyperglot as hyperglot.

This keeps the dependencies separate from other plugins, and allows me to automate the package install process. I've tested it with different pips in various locations on my system and it doesn't seem to matter what Python version number the pip is from, since it's effectively just putting the packages in the target location, and the packages are the same no matter which pip I use.

justinpenner commented 3 months ago

The prefix idea didn't work, because it prevents the modules from being able to import anything. I should have thought of that. So, I don't think there's any way to make modules even pseudo-private to a plugin, without touching the code inside of the modules. I'm now working under the assumption that all plugins are forced to share common modules.

I've run into a number of roadblocks trying to install dependencies via pip. The main issue is that I cannot get pip to work within GlyphsPython, unless the user has installed the same version of Python from Python.org, which is too much of a burden for users.

Some things I've tried:

justinpenner commented 2 months ago

I wasn't able to find a simple way to fix pip in GlyphsPython, because it seemed like it would involve editing or rebuilding some Python binaries which is far beyond my knowledge. Georg at Glyphs mentioned he'll try to get it working, but in the meantime the workaround must be for users to install their own Python as a pre-requisite for TalkingLeaves. Install instructions in README.md have been updated to make it as easy as possible.

Closing for now, as we now have the best available dependency install process, even if it isn't ideal. Will reopen this issue if anything changes.

justinpenner commented 2 months ago

Before adding TalkingLeaves to the Plugin Manager, I'd like to automate the dependency installs as much as possible.