6

I have a command-line program (foo) written in an esoteric programming language. I'd like to distribute this program as part of an existing python package that uses setuptools. foo should appear in the user's path and be executable from the command line, much like the behavior of distutil's scripts or setuptools' entry_points.

It's feasible for me to cross-compile the program for every platform and then build a different egg for each platform with a platform-specific binary of foo. The problem is, I don't know how to convince setuptools to copy the binary to a platform-appropriate place on the target system.

For example, I tried using the scripts directive:

setup(
...
scripts=["foo"]
...
)

but it appears setuptools doesn't like a "script" with non-utf8 data.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

I could declare it as a resource, but that wouldn't put it in the user's path.

How do I ship a binary command-line utility as part of a python package?

asked Jul 10, 2014 at 21:45
1

1 Answer 1

7

My solution was as follows:

  • Create a wrapper module foowrapper.
  • foowrapper contains foo (but renamed to foo_bin) and a new script called foo, contents below:

.

 #!python
 file = __file__
 import os.path
 cmd = os.path.join(os.path.dirname(__file__),"foo_bin")
 import subprocess
 subprocess.call([cmd] + sys.argv[1:])
  • Update setup.py to contain foowrapper, foo, and foo_bin

.

setup(
 ...
 package_data={
 'foowrapper':['foo_bin']
 },
 packages=['foowrapper],
 scripts=['foowrapper/foo']
 ...
)
answered Jul 11, 2014 at 8:56
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.