更改用于打包的console_script入口点解释器 [英] Changing console_script entry point interpreter for packaging

查看:77
本文介绍了更改用于打包的console_script入口点解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个著名的第三方打包系统来打包一些python软件包,但是在创建入口点的方式上遇到了问题。

I'm packaging some python packages using a well known third party packaging system, and I'm encountering an issue with the way entry points are created.

何时我在机器上安装了一个入口点,该入口点将包含一个指向任何python解释器的shebang,例如:

When I install an entry point on my machine, the entry point will contain a shebang pointed at whatever python interpreter, like so:

/ home / me / development中/test/setup.py

from setuptools import setup
setup(
    entry_points={
        "console_scripts": [
            'some-entry-point = test:main',
        ]
    }
)        

/home/me/.virtualenvs/test/bin/some-entry-point

#!/home/me/.virtualenvs/test/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'test==1.0.0','console_scripts','some-entry-point'
__requires__ = 'test==1.0.0'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('test==1.0.0', 'console_scripts', 'some-entry-point')()
)

如您所见,入口点样板包含一个指向python解释器的硬编码路径,该路径位于我用于创建第三方程序包的虚拟环境中。

As you can see, the entry point boilerplate contains a hard-coded path to the python interpreter that's in the virtual environment that I'm using to create my third party package.

使用我的第三方打包系统安装此入口点会导致在计算机上安装了入口点。但是,使用目标计算机上不存在的对python解释器的硬编码引用,用户必须运行 python / path / to / some-entry-point

Installing this entry point using my third-party packaging system results in the entry point being installed on the machine. However, with this hard-coded reference to a python interpreter which doesn't exist on the target machine, the user must run python /path/to/some-entry-point.

shebang使得这种便携性不强。 (当然,这不是virtualenv的设计目标,但我只需要在这里使其更具便携性即可。)

The shebang makes this pretty unportable. (which isn't a design goal of virtualenv for sure; but I just need to MAKE it a little more portable here.)

我宁愿不疯狂使用查找/ xargs / sed命令。 (尽管那是我的后备。)

I'd rather not resort to crazed find/xargs/sed commands. (Although that's my fallback.)

有什么方法可以使我在使用爆炸后的解释器路径使用 setuptools 标志或配置?

Is there some way that I can change the interpreter path after the shebang using setuptools flags or configs?

推荐答案

您可以通过设置'sys.executable'来自定义console_scripts的shebang行(从 debian错误报告)。那就是说...

You can customize the console_scripts' shebang line by setting 'sys.executable' (learned this from a debian bug report). That is to say...

sys.executable = '/bin/custom_python'

setup(
  entry_points={
    'console_scripts': [
       ... etc...
    ]
  }
)

更好的做法是在构建...时包括执行参数。

Better though would be to include the 'execute' argument when building...

setup(
  entry_points={
    'console_scripts': [
       ... etc...
    ]
  },
  options={
      'build_scripts': {
          'executable': '/bin/custom_python',
      },
  }
)

这篇关于更改用于打包的console_script入口点解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆