I followed mertyildiran's top answer to write a post-install script in setup.py
:
from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install
here = os.path.abspath(os.path.dirname(__file__))
class PostDevelopCommand(develop):
"""Post-installation for development mode."""
def run(self):
file = os.path.join(here, 'TESTFILE')
print(file) # /path/to/my/package/TESTFILE
with open(file, 'a') as file:
file.write('This is development.')
develop.run(self)
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
file = os.path.join(here, 'TESTFILE')
print(file) # /tmp/pip-req-build-*/TESTFILE
with open(file, 'a') as file:
file.write('This is Sparta!')
install.run(self)
setup(
..
cmdclass={
'install': PostInstallCommand,
'develop': PostDevelopCommand,
},
)
..but only when I pip install -e .
do I get the output in the test file. When I try pip install .
nothing gets written to my desired output file because the file path changes to /tmp/pip-req-build-*
How can I get the path to the package directory before setup?