5

Let's assume I have a package which calls an executable file somewhere in the code (for example a third-party c/java-program). Let's further assume, the application is small/trivial enough to bundle with the package. For example a single executable file (cfoo).

I could go ahead, and put the files into the following structure:

.
|-- foo
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- core.py
|   |-- corebin
|   |   `-- cfoo
|   `-- foomain.py
`-- setup.py

And prepare a setup.py as follows:

from setuptools import setup

setup(
    name='foo',
    version='1.0',
    packages=['foo'],
    scripts=['foo/foomain.py'],
    package_data={'foo': ['corebin/*']},
    zip_safe=False
)

This will allow me to properly install the package. Later, in the package-code I could do this:

from subprocess import call

import pkg_resources as res

def main():
    fn = res.resource_filename('foo', 'corebin/cfoo')
    print "Resource located at:", fn
    call([fn])

Unfortunately, the executable file will be installed without executable flag set. Even if the original file had it set. Adding a chmod call at the end of the setup.py script is not as easy, as one would need to figure out the proper installation path first. I tried with resource_filename but that returned the local file (as in "pre-installation").

How can this problem be solved? Also with virtualenv in mind...

3
  • First: are you generating and installing a .tar.gz distribution, or one of those old deprecated .egg distributions? Because this might at some point involve the question of which archive formats preserve which file attributes on while operating systems. :) Commented Nov 7, 2011 at 13:40
  • If you install it using the scripts keyword, it will get the correct mode (and get installed in an appropriate bin/ directory). Commented Nov 7, 2011 at 15:04
  • @larsks: In my case, the executable is a file provided by a third-party. The script is used as a wrapper around this file. Your comment indeed solves my problem. But this question remains still interesting nonetheless: How would you execute something on files contained inside a package after install? Commented Nov 8, 2011 at 14:45

1 Answer 1

2

I'm promoting my comment to an answer:

If you install it using the scripts keyword, it will get the correct mode (and get installed in an appropriate bin/ directory).

How would you execute something on files contained inside a package after install?

This question would appear to address the same situation, and it looks like it has a reasonable answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.