Nab*_*abs 6 distutils setuptools setup.py python-packaging
我正在将配置从 迁移setup.py到setup.cfg,但我遇到了关键字问题cmdclass。我查看了 setuptools 文档,似乎没有记录或支持此关键字。所以我尝试了options.entry_points。但我不断收到无效命令错误。
这是我所拥有的:
setup.cfg
[options.entry_points]
console_scripts =
install = CustomInstall:run
Run Code Online (Sandbox Code Playgroud)
和
setup.py
from setuptools.command.install import install
from setuptools import setup
class CustomInstall(install):
def run(self):
print('overriden install command')
setup()
Run Code Online (Sandbox Code Playgroud)
结果只是一个正常的安装命令。但是,我想复制运行时得到的行为:
# setup.py
from setuptools.command.install import install
from setuptools import setup
class CustomInstall(install):
def run(self):
print('overriden install command')
setup(cmdclass= {"install": CustomInstall})
Run Code Online (Sandbox Code Playgroud)
它给出了一个覆盖的安装命令。
和[options.entry_points]的console_scripts作用是创建运行代码库中特定功能的 shell 命令。一旦您的软件包安装在环境中,这些命令就会起作用。
install因此,在您的示例中,将创建一个新的 shell 命令,并且它将运行run()名为 的包中的函数CustomInstall。
根据查看源代码,我猜测正确的语法是:
[global]
commands =
install = mypackage.CustomInstall
Run Code Online (Sandbox Code Playgroud)
但我还没能让它发挥作用。
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |