我跟随mertyildiran's top answer在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,
},
)
..但是只有当我pip install -e .
时,我才会在测试文件中获得输出。当我尝试pip install .
时,没有任何内容写入所需的输出文件,因为文件路径更改为/tmp/pip-req-build-*
如何在设置之前获取包目录的路径?
答案 0 :(得分:1)
pip
builds a wheel right away。这包括安装到临时目录作为中间步骤。因此,所有不符合包装条件的物品都会丢失。
可编辑的安装just runs setup.py develop
中。