Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running `chmod` after installing a package using `setup.py`

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...

like image 704
exhuma Avatar asked Nov 04 '22 11:11

exhuma


1 Answers

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.

like image 64
larsks Avatar answered Nov 14 '22 22:11

larsks