I tried to configure my package such that a script is executed on the installation process. Therefore, I inherited from setuptools.command install and created my custom class ActionOnInstall
to do stuff when package is installed. This class is called via setuptools setup()
argument cmdclass
as described here.
A minimal example of such a setup.py file looks like
from setuptools import find_packages, setup
from setuptools.command.install import install
class ActionOnInstall(install):
def run(self):
print("Call install.run(self) works!")
install.run(self)
setup(name='name',
cmdclass={
'install': ActionOnInstall})
Building the package by executing
pip3 install <path-to-dir-with-setup.py>
runs successfully but does not execute commands specified in ActionOnInstall.run()
. More directly calling this setup.py by
python3 setup.py install
executes commands specified in ActionOnInstall.run()
.
Then, I found myself asking: what is the actual difference of these both approaches to install a package. I know, like other posts tell us, pip makes life easier regarding package installation. But how these both approaches treat the cmdclass
argument of setup()
differently is not explained. Thus, I would highly appreciate to hear from you guys.
pip calls your setup.py but it redirects stdout/stderr. To test setup.py under pip write to a file in a fixed location:
Look into /tmp/debug.log after
pip install .
pip does run
python setup.py install
when installing your package - it does not change the way your setup.py feel is executed.The reason you don't see any output is, as @phd mentioned, that pip by default hides all the output from running the
setup.py
file since most of the information printed when runningpython setup.py install
is not useful to most users.You can see this hidden output, along with everything else pip does, by passing the "--verbose" option to
pip install
: