首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有自定义入口点的python安装轮

带有自定义入口点的python安装轮
EN

Stack Overflow用户
提问于 2014-11-19 17:18:53
回答 1查看 2.8K关注 0票数 1

在Windows上的python中,我安装了一个自定义包,它覆盖setuptools.command.install.easy_install.get_script_args创建一个新的自定义入口点“custom_entry”类型。

我有另一个包,我想准备用setuptools公开一个自定义入口点。

如果我准备了这个包的鸡蛋分发版并用修改过的easy_install.exe安装它,这就正确地创建了自定义入口点。

但是,如果我准备了一个轮式发行版并使用修改后的pip.exe安装它,则不会添加自定义入口点。

为什么pip不遵循与easy_install相同的安装过程?

阅读pip的源代码后,似乎wheel.py中的函数wheel.py排除了除console_scripts和gui_scripts之外的所有入口点。这是正确的吗?

如果是,我应该如何安装pip安装的自定义入口点?

-编辑

看来我应该提供更多细节。

在我的第一个包,custom-installer,我是过激(猴子补丁,真的) easy_install.get_script_args,在custom_install.__init__.py

代码语言:javascript
复制
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中,我为自定义安装程序提供了一个(console_script)入口点:

代码语言:javascript
复制
entry_points={
    'console_scripts': [
        'custom_install = custom_install.__init__:main'
    ]
}

使用pip正确安装此包将创建安装程序脚本/venv/Scripts/custom_install.exe

使用我的第二个包customized,我可以从setup.py安装常规入口点和自定义入口点,用于两个模块customconsole

代码语言:javascript
复制
entry_points={
    'console_scripts': [
        'console = console.__main__:main'
    ],
    'custom_entry': [
        'custom = custom.__main__:main'
    ]
}

无论安装过程如何,我都希望安装这两个入口点。

如果我将包customized构建为一个鸡蛋发行版,并使用custom-installer创建的custom_install.exe安装这个包,那么就安装了customized的两个入口点。

我希望能够使用pip将这个包作为一个轮转文件来安装,但是从读取源代码来看,pip似乎显式地跳过和除'console_scripts‘和’gui_script‘以外的任何入口点:

代码语言:javascript
复制
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的实现来创建我的自定义入口点,就像使用easy_install一样,但是我觉得我走错了方向。

有人能建议一种更简单的方法来实现我的自定义入口点,与pip兼容吗?如果没有,我可以重写get_entrypointsmove_wheel_files

EN

回答 1

Stack Overflow用户

发布于 2014-11-19 22:04:06

您可能需要在您的console_scripts文件中使用关键字setup.py。见以下答复:

它基本上说明您需要在setup.py脚本中执行以下操作:

代码语言:javascript
复制
entry_points = {
       'console_scripts': ['custom_entry_point = mypackage.mymod.test:foo']
       }

另见:http://calvinx.com/2012/09/09/python-packaging-define-an-entry-point-for-console-commands/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27022986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档