Reputation: 1022
I am using distutils to create a Python (2) package installer. In my package are a couple of binary executable that get called from my Python code. I am listing these as package_data
in my setup.py
file so they get installed along with the package. However, distutils does not copy the executable permission bit on these files when they are installed. Is there a way to force distutils to install package_data
files with executable permissions?
Upvotes: 5
Views: 1488
Reputation: 16480
You could also use setuptools instead of distutils. The setuptools preserves the file modes of the package_data files, whereas distutils doesn't.
Upvotes: 2
Reputation: 1022
Figured it out based on some other SO answers - the following works:
class my_install_lib(distutils.command.install_lib.install_lib):
def run(self):
distutils.command.install_lib.install_lib.run(self)
for fn in self.get_outputs():
if <this is one of the binaries I want to be executable>:
# copied from distutils source - make the binaries executable
mode = ((os.stat(fn).st_mode) | 0555) & 07777
distutils.log.info("changing mode of %s to %o", fn, mode)
os.chmod(fn, mode)
and then pass cmdclass={'install_lib':my_install_lib}
to setup
.
Upvotes: 3