python-pip-install-wheel具有自定义入口点
在Windows上的python virtualenv中,我安装了一个自定义包,它覆盖setuptools.command.install.easy\u install.get\u script\u args以创建新的自定义类型的入口点“custom\u entry” 我还有另一个包,我想用setuptools准备,它公开了一个自定义入口点 如果我准备了此软件包的egg发行版,并使用修改后的easy_install.exe安装它,则会正确创建自定义入口点 但是,如果我准备了一个控制盘发行版,并使用修改后的pip.exe安装它,则不会添加自定义入口点 为什么pip不遵循与easy_install相同的安装过程 在阅读pip的源代码时,函数get_entrypoints in似乎排除了除控制台_脚本和gui_脚本之外的所有入口点。这是正确的吗 如果是这样,我应该如何为pip安装安装自定义入口点 ----编辑 看起来我应该提供更多的细节 在我的第一个软件包中,python-pip-install-wheel具有自定义入口点,python,windows,pip,entry-point,python-wheel,Python,Windows,Pip,Entry Point,Python Wheel,在Windows上的python virtualenv中,我安装了一个自定义包,它覆盖setuptools.command.install.easy\u install.get\u script\u args以创建新的自定义类型的入口点“custom\u entry” 我还有另一个包,我想用setuptools准备,它公开了一个自定义入口点 如果我准备了此软件包的egg发行版,并使用修改后的easy_install.exe安装它,则会正确创建自定义入口点 但是,如果我准备了一个控制盘发行版,并使
custom installer
,我已经完成了(真的是猴子补丁)easy\u install.get\u script\u args
,在custom\u install.py
:
from setuptools.command import easy_install
_GET_SCRIPT_ARGS = easy_install.get_script_args
def get_script_args(dist, executable, wininst):
for script_arg in _GET_SCRIPT_ARGS(dist, executable, wininst):
yield script_arg # replicate existing behaviour, handles console_scripts and other entry points
for group in ['custom_entry']:
for name, _ in dist.get_entry_map(group).items():
script_text = (
## some custom stuff
)
## do something else
yield (## yield some other stuff) # to create adjunct files to the -custom.py script
yield (name + '-custom.py', script_text, 't')
easy_install.get_script_args = get_script_args
main = easy_install.main
在该软件包的setup.py
中,我为我的自定义安装程序提供了一个(控制台脚本)入口点:
entry_points={
'console_scripts': [
'custom_install = custom_install.__init__:main'
]
}
使用pip正确安装此软件包将创建安装程序脚本/venv/Scripts/custom_install.exe
对于我的第二个软件包,customized
,我可以从setup.py
为两个模块custom
和console
安装常规和自定义入口点
entry_points={
'console_scripts': [
'console = console.__main__:main'
],
'custom_entry': [
'custom = custom.__main__:main'
]
}
无论安装过程如何,我都希望看到这两个入口点都已安装
如果我将包customized
构建为一个egg发行版,并使用custom安装程序创建的custom_install.exe
安装此包,则将安装customized
的两个入口点
我希望能够使用pip将此软件包安装为一个轮子文件,但从阅读源代码来看,pip似乎明确跳过了除“控制台脚本”和“gui脚本”之外的任何入口点:
def get_entrypoints(filename):
if not os.path.exists(filename):
return {}, {}
# This is done because you can pass a string to entry_points wrappers which
# means that they may or may not be valid INI files. The attempt here is to
# strip leading and trailing whitespace in order to make them valid INI
# files.
with open(filename) as fp:
data = StringIO()
for line in fp:
data.write(line.strip())
data.write("\n")
data.seek(0)
cp = configparser.RawConfigParser()
cp.readfp(data)
console = {}
gui = {}
if cp.has_section('console_scripts'):
console = dict(cp.items('console_scripts'))
if cp.has_section('gui_scripts'):
gui = dict(cp.items('gui_scripts'))
return console, gui
随后,pip使用一组完全不同的代码生成入口点脚本,以便于安装。据推测,我可以像easy_install那样超越pip的实现来创建自定义入口点,但我觉得我走错了方向
有谁能建议一种更简单的方法来实现与pip兼容的自定义入口点吗?如果没有,我可以覆盖get\u entrypoints
和move\u wheel\u文件
您可能需要在setup.py
文件中使用关键字console\u scripts
。请参阅以下答案:
它基本上说明您需要在setup.py
脚本中执行以下操作:
entry_points = {
'console_scripts': ['custom_entry_point = mypackage.mymod.test:foo']
}
另请参见:Hi。谢谢你的回复。我想我一定不清楚。我的入口点的配置方式与“控制台脚本”不同。我有一些我想做的自定义设置。好吧,根据公认的答案,这种配置似乎不包括在pip控制盘的设计部署中。“不要将软件包安装和系统部署混用”也许答案是提供一个控制台脚本入口点,该入口点将运行我希望用于自定义入口点的其余配置。阅读更新后,听起来您可能需要编写自定义或补丁pip本身。我想皮普有一个邮件列表。您可能想在这里交叉发布。通过阅读,我认为pip并不适用于安装后的配置设置。我找不到应该使用什么python工具来实现这一点,所以我推出了自己的解决方案。这是一个混乱,但它的工作。