From 03bcf51219fc9c332ffa3264ad780d5c04a04e39 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 8 Jan 2018 21:33:35 -0500 Subject: [PATCH] pyinstaller build method pyinstaller packages up all of a python script's dependencies and builds them into standalone executables. It can either do a directory (containing a single executable and a bunch of shared libraries) or a self-contained executable that effectively just contains a compressed version of the directory. The problem is, if you have several scripts like we do, you get several large directories or standalone binaries, and there's a ton of duplication between them. Fortunately it looks like using the directory method and just combining the directories works fine (for this project). --- .gitignore | 7 ++++++- Makefile | 17 +++++++++++++++++ stub.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 stub.py diff --git a/.gitignore b/.gitignore index 9f526dcb0..c0a09e7ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ .*.swp -*.pyc \ No newline at end of file +*.pyc +*.spec +*.zip +*.tar.gz +dist/ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..50a9ff290 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +EXTENSIONS:=embroider embroider_params embroider_simulate embroider_update +VERSION:=$(shell git tag -l | grep ^v | tail -n 1) +TARBALL:=inkstitch-$(VERSION)-$(shell uname)-$(shell uname -m).tar.gz + +dist: distclean + mkdir -p dist/inkstitch/bin + for extension in $(EXTENSIONS); do \ + pyinstaller -p /usr/share/inkscape/extensions $${extension}.py; \ + cp -a dist/$${extension}/* dist/inkstitch/bin; \ + rm -rf dist/$${extension}; \ + cp stub.py dist/$${extension}.py; \ + done; + cp *.inx dist + cd dist; tar zcf ../$(TARBALL) * + +distclean: + rm -rf build dist *.spec *.tar.gz diff --git a/stub.py b/stub.py new file mode 100644 index 000000000..9fa331607 --- /dev/null +++ b/stub.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import sys +import os + +# ink/stitch +# +# stub.py: pyinstaller execution stub +# +# pyinstaller packages the inkstitch extensions into nice tidy executables. +# That's great, but Inkscape can't execute a plain binary as an extension(!). +# +# This Python script exists only to execute the actual extension binary. It +# can be copied to, e.g., "embroider_params.py", in which case it will look +# for a binary at inkstitch/bin/embroider_params. + +script_name = os.path.basename(__file__) + +if script_name.endswith('.py'): + binary_name = script_name[:-3] +else: + # Probably not right, but we can at least try. + binary_name = script_name + +binary_path = os.path.join("inkstitch", "bin", binary_name) + +args = sys.argv[:] +args[0] = binary_path + +os.execv(binary_path, args)