我跟随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-*
,所以没有任何内容写入到我想要的输出文件中
如何在安装之前获取包目录的路径?在
pip
builds a wheel right away。这包括作为中间步骤安装到临时目录。所以所有不符合包装条件的东西都会丢失。在可编辑安装时just runs ^{} 。在
相关问题 更多 >
编程相关推荐