gep*_*och 12 python distutils setuptools
我使用众所周知的第三方包装系统打包一些python包,我遇到了创建入口点的问题.
当我在我的机器上安装一个入口点时,入口点将包含指向任何python解释器的shebang,如下所示:
在/home/me/development/test/setup.py中
from setuptools import setup
setup(
entry_points={
"console_scripts": [
'some-entry-point = test:main',
]
}
)
Run Code Online (Sandbox Code Playgroud)
在/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')()
)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,入口点样板文件包含一个硬编码的python解释器路径,该路径位于我用于创建第三方软件包的虚拟环境中.
使用我的第三方打包系统安装此入口点会导致在计算机上安装入口点.但是,通过对目标机器上不存在的python解释器的这种硬编码引用,用户必须运行python /path/to/some-entry-point.
shebang使这个非常不可移植.(这肯定不是virtualenv的设计目标;但我只需要在这里使它更便携.)
我宁愿不诉诸疯狂的find/xargs/sed命令.(虽然这是我的后备.)
有没有什么方法可以在shebang使用setuptools旗帜或配置后改变解释器路径?
Dam*_*ian 18
您可以通过设置'sys.executable'来自定义console_scripts的shebang行(从debian错误报告中学到这一点).也就是说...
sys.executable = '/bin/custom_python'
setup(
entry_points={
'console_scripts': [
... etc...
]
}
)
Run Code Online (Sandbox Code Playgroud)
更好的是在构建时包含'execute'参数...
setup(
entry_points={
'console_scripts': [
... etc...
]
},
options={
'build_scripts': {
'executable': '/bin/custom_python',
},
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3362 次 |
| 最近记录: |