(Buildbot)无法使用ShellCommand激活virtualenv

2024-09-30 18:32:16 发布

您现在位置:Python中文网/ 问答频道 /正文

返回错误“OSError:没有这样的文件或目录”。我们试图使用builder中的步骤激活我们新创建的虚拟env venvCIshellCommand。似乎就好像我们不能激活virtualenv venvCI一样。在这种环境下才刚开始,所以请帮忙我们。谢谢. 在

from buildbot.steps.shell import ShellCommand

factory = util.BuildFactory()

# STEPS for example-slave:

factory.addStep(ShellCommand(command=['virtualenv', 'venvCI']))

factory.addStep(ShellCommand(command=['source', 'venvCI/bin/activate']))

factory.addStep(ShellCommand(command=['pip', 'install', '-r','development.pip']))

factory.addStep(ShellCommand(command=['pyflakes', 'calculator.py']))

factory.addStep(ShellCommand(command=['python', 'test.py']))

c['builders'] = []
c['builders'].append(
    util.BuilderConfig(name="runtests",
      slavenames=["example-slave"],
      factory=factory))

Tags: pip文件pyvirtualenvexamplefactory错误util
2条回答

由于buildsystem为每个Shell命令创建一个新的Shell,您不能source env/bin/activate,因为这只会修改活动Shell的环境。当Shell(命令)退出时,环境就消失了。在

你可以做的事情:

  • 为每个shell命令手动提供环境(读什么 activate做)env={...}

  • 创建一个运行所有命令的bash脚本 一个shell(我在其他系统中所做的)

例如

在myscript.sh公司名称:

#!/bin/bash

source env/bin/activate
pip install x
python y.py

建筑机器人:

^{pr2}$

blog post about the issue

另一个选择是在虚拟环境中直接调用python可执行文件,因为许多提供命令行命令的python工具通常都可以作为模块执行:

from buildbot.steps.shell import ShellCommand

factory = util.BuildFactory()

# STEPS for example-slave:

factory.addStep(ShellCommand(command=['virtualenv', 'venvCI']))

factory.addStep(ShellCommand(
    command=['./venvCI/bin/python', '-m', 'pip', 'install', '-r', 'development.pip']))

factory.addStep(ShellCommand(
    command=['./venvCI/bin/python', '-m', 'pyflakes', 'calculator.py']))

factory.addStep(ShellCommand(command=['python', 'test.py']))

然而,过了一段时间,这确实会让人厌烦。您可以使用string.Template生成辅助对象:

^{pr2}$

然后你可以这样做:

addstep('$python -m pip install pytest', python='./venvCI/bin/python')

这些是一些开始的想法。请注意,shlex的一个妙处是,在进行拆分时,它将考虑带引号的字符串内的空格。在

相关问题 更多 >