我试图配置我的软件包,以便在安装过程中执行脚本。因此,我从setuptools.command install继承并创建了我的自定义类,ActionOnInstall
以便在安装软件包时进行操作。这个类是通过setuptools的称为setup()
参数cmdclass
描述这里。
这样的setup.py文件的最小示例如下
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})
通过执行构建程序包
pip3 install <path-to-dir-with-setup.py>
运行成功,但不执行中指定的命令ActionOnInstall.run()
。更直接地通过以下方式调用此setup.py
python3 setup.py install
执行中指定的命令ActionOnInstall.run()
。
然后,我发现自己在问:这两种安装软件包的方法的实际区别是什么?我知道,就像其他帖子告诉我们的那样,pip使软件包安装变得更轻松。但是cmdclass
,setup()
没有解释这两种方法如何不同地对待论点。因此,非常感谢您的来信。
pip调用您的setup.py,但它会重定向stdout / stderr。要在pip下测试setup.py,请在固定位置写入文件:
class ActionOnInstall(install):
def run(self):
print("Call install.run(self) works!", file=open('/tmp/debug.log', 'w'))
install.run(self)
之后查看/tmp/debug.log pip install .
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句