一个与zc.buildout.egg向后兼容的实验性的buildout配方,但为挂架用户提供了额外的功能。
pylons_sandbox的Python项目详细描述
这是一个用于构建的配方。和Buildout的一样 zc.recipe.egg但有以下额外功能:
- 可以从任何依赖包安装脚本
- 如果您提供合适的 为您的平台申请
警告
这是非常阿尔法软件,只有在德比安蚀刻测试。 其他平台(如windows)上可能存在漏洞。它是设计的 更多的是作为概念的证明,而不是生产准备配方。
要开始,请先下载构建引导程序:
wget "http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py"
然后创建一个buildout.cfg文件,将/path/to/pylons/app/src替换为 pylons应用程序的路径并用名称替换PylonsApp。 您的应用程序:
[buildout] develop = /path/to/pylons/app/src parts = python [python] recipe = pylons_sandbox interpreter = python eggs = PylonsApp
您现在可以构建应用程序:
$ python bootstrap.py $ bin/buildout
到目前为止,pylons_sandbox配方的exaclty行为与 默认zc.buildout.eggrecipe,安装所有必需的依赖项 你的挂架应用到本地建筑沙箱。它也让你 可以使用的bin/python脚本和bin/buildout脚本 建立任何未来的变化。
对于pylons使用,您应该设置选项dependent_scripts=True,以便 来自Nose和PasteScript包的脚本在 bindirectoy:
[buildout] develop = /path/to/pylons/app/src parts = python [python] recipe = pylons_sandbox interpreter = python eggs = PylonsApp dependent_scripts = True
现在运行以下命令重新构建目录:
$ bin/buildout -N
-N选项意味着buildout不会寻找新的依赖项 可以从它已经安装的文件中找到它们。这意味着有点 更快地重新构建目录。
现在您应该有一个bin/paster命令,可以用来为您的挂架服务 申请。
对于大多数用户来说,这个设置是可以的,但是pylons_sandbox recipe还有一个特性,launcher选项。
如果要将构建设置视为真正的沙盒,则需要 python解释器,它是一个实际的可执行文件,以便其他脚本可以使用 你的沙盒python解释器在一个!脚本(如cgi)中的行 apache使用的脚本。buildout生成的python文件实际上是 只是一个python脚本本身,所以不能以这种方式使用。
如果设置launcher选项,pylons_sandbox配方将创建 通过将.buildout附加到 interpreter选项,它将添加一个工具,以便 调用脚本位于sys.path上。然后它将复制由 将launcher选项设置为interpreter选项中指定的名称。在 到目前为止,我们的示例意味着buildoutpython脚本将在 bin/python.buildout和启动它的应用程序 bin/python,现在可以在#!行中使用。
这一切都很好,但是您需要应用程序本身。这里有一些C++ 编译时将创建适当应用程序的代码。一直以来 描述为“可怕”,所以我很高兴接受一个补丁与一些新的C++。 创建一个包含以下内容的launcher.cc文件:
/* * Buildout Launcher * +++++++++++++++++ * * This application excutes a python script in the same directory as the * application. This is useful because it effectively turns a Python script * into a real executable which you can use on the #! line of other scripts. * * The script to be executed should have the same name as the the filename of * this compiled program but with a .py extension added to the end. The real * Python interpreter used to execute the script is dermined from the script's * #! line or /usr/bin/python is used as a fallback if no Python interpreter * can be found. * * The Python interpreters generated by Buildout are actually just Python * scripts so this application allows them to be run from a real executable. * * Compile this file with the following command: * * g++ launcher.cc -o launcher * * Copyright James Gardner. MIT license. No warranty to the maximum extent * possible under the law. * */ #include <vector> #include <string> #include <unistd.h> #include <fstream> using namespace std; int main(int argc,char *argv[]) { vector<string> args; int i; args.push_back("python"); for (i=0;i<argc;i++) args.push_back(argv[i]); args[1] = strcat(argv[0], ".buildout"); char *new_argv[argc+1]; for (int i=0 ; i<argc+1 ; i++) { new_argv[i] = (char *)args[i].c_str(); } new_argv[argc+1] = NULL; vector<string> text_file; ifstream ifs(new_argv[1]); string temp; string temp_short; getline(ifs, temp); if (strncmp((char *)temp.c_str(), "#!", 2)) { /* default to /usr/bin/python if no #! header */ temp_short = "/usr/bin/python"; } else { temp_short = temp.substr(2,(temp.length()-2)); } char python[temp_short.length()]; strcpy(python, (char *)temp_short.c_str()); return execv(python, new_argv); }
使用以下命令编译此文件:
$ g++ launcher.cc -o launcher
并将launcher应用程序与 buildout.cfg。然后您可以更新您的buildout.cfg如下:
[buildout] develop = /path/to/pylons/app/src parts = python [python] recipe = pylons_sandbox interpreter = python eggs = PylonsApp dependent_scripts = True launcher = launcher
现在重新构建:
$ bin/buildout -N
您应该有一个运行良好的沙盒,其中还包含一个真正的python可执行文件 与使用构建系统部署的所有其他好处一样。
测试:
$ bin/python >>> import pylons >>>
正如您所看到的,所有的模块依赖项都存在。