繁体   English   中英

如何使用包含初始化代码的zc.buildout生成自定义python解释器?

[英]How can I generate a custom python interpreter using zc.buildout that includes my initialization code?

对于App Engine项目,我在使用zc.buildout时遇到了一些困难。 我想扩建,以产生一个Python解释器bin/包含path基于在指定库版本所需调整app.yaml 这样,只要我有命令行脚本或交互式shell工作,我就可以使用这个生成的python脚本。

这是我要插入的代码:

import dev_appserver
dev_appserver.fix_sys_path()

这是我的buildout.cfg:

[buildout]
parts =
    python
    gae_sdk
[gae_sdk]
# Downloads and extracts the App Engine SDK.
recipe = appfy.recipe.gae:sdk
url = http://googleappengine.googlecode.com/files/google_appengine_1.8.9.zip
destination = ${buildout:parts-directory}
hash-name = false
clear-destination = true
[python]
recipe = zc.recipe.egg
interpreter = python
initialization = 
    import dev_appserver
    dev_appserver.fix_sys_path()
extra-paths =
    ${gae_sdk:destination}/google_appengine
    ${buildout:directory}/app

结果我错过了zc.recipe.egg的一些魔法,以使其正常工作。 这是正确的来源

[buildout]
parts =
    python
    gae_sdk
[gae_sdk]
# Downloads and extracts the App Engine SDK.
recipe = appfy.recipe.gae:sdk
url = http://googleappengine.googlecode.com/files/google_appengine_1.8.9.zip
destination = ${buildout:parts-directory}
hash-name = false
clear-destination = true
[python]
# use the scripts entry point, not just zc.recipe.egg
recipe = zc.recipe.egg:scripts
interpreter = python
initialization =
    import dev_appserver
    dev_appserver.fix_sys_path()
# even if empty, must be here or else it errors...
eggs =
extra-paths =
    ${gae_sdk:destination}/google_appengine
    ${buildout:directory}/app

其中生成正确的bin/python

#!/usr/local/opt/python/bin/python2.7
import sys
sys.path[0:0] = [
  '/path/to/awesome/parts/google_appengine',
  '/path/to/awesome/app',
  ]
import dev_appserver
dev_appserver.fix_sys_path()
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM