The way to address these deficiences is:
- Get the full path to the Python interpreter executing
setup.py
fromsys.executable
. Classes inheriting from
distutils.cmd.Command
(such asdistutils.command.install.install
which we use here) implement theexecute
method, which executes a given function in a "safe way" i.e. respecting the dry-run flag.Note however that the
--dry-run
option is currently broken and does not work as intended anyway.
I ended up with the following solution:
import os, sys
from distutils.core import setup
from distutils.command.install import install as _install
def _post_install(dir):
from subprocess import call
call([sys.executable, 'scriptname.py'],
cwd=os.path.join(dir, 'packagename'))
class install(_install):
def run(self):
_install.run(self)
self.execute(_post_install, (self.install_lib,),
msg="Running post install task")
setup(
...
cmdclass={'install': install},
)
Note that I use the class name install
for my derived class because that is what python setup.py --help-commands
will use.