2

My Python module contains an external script that users can execute from the command line. I'd like users to be able to install the Python module and script all in one go. Using setuptools, I have tried adding:

scripts=['bin/mybin']

which almost does the trick. Instead of adding mybin to the user's PATH, it adds a small script that calls mybin:

#!/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-SCRIPT: 'myscript==2.0.4','mybin'
__requires__ = 'myscript==2.0.4'
__import__('pkg_resources').run_script('myscript==2.0.4', 'mybin')

This indirection is causing some problems, notably a small lag when the script is executed (compared to copying mybin to the PATH directly).

Is there any way to have setuptools copy the script directly to the PATH rather than have it call my script indirectly?

My first thought is to write a custom post-install function to copy the script to the user's path. But if there is a way to do this natively in setuptools, I would prefer that.

Jeff
  • 12,147
  • 10
  • 51
  • 87

1 Answers1

3

One solution is to add this to your setup.py:

  data_files=[
    ('/usr/local/bin', ['bin/mybin'])
    ]

which copies bin/mybin to /usr/local/bin.

Another solution that does not require hard-coding a bin directory is to first detect the script directory that setuptools would copy your script to, then use data_files to copy it there directly. This StackOverflow answer explains how to detect the setuptools script path.

Jeff
  • 12,147
  • 10
  • 51
  • 87