2016-02-05 94 views
2

返回錯誤「OSError:no這樣的文件或目錄」。我們嘗試使用shellCommand構建器中的步驟激活我們新創建的虛擬env venvCI,例如我們無法激活virtualenv venvCI。在這個環境中只有新的東西,所以請幫助我們。謝謝。(Buildbot)無法使用ShellCommand激活virtualenv

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)) 
+0

@varesa我會嘗試一個,並通知你的結果。謝謝! –

+0

@varesa嘿!謝謝。有效。 –

回答

2

由於構建系統將爲每個ShellCommand一個新的外殼,你不能因爲source env/bin/activate只修改活動的shell環境。當Shell(Command)退出時,環境消失了。

事情可以做:

  • 手動給環境爲每ShellCommand(讀什麼 activate一樣)env={...}

  • 創建一個運行在 單殼所有命令的bash腳本(我在其他系統中做過的)

e 。G。

myscript.sh:

#!/bin/bash 

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

Buildbot:

factory.addStep(ShellCommand(command=['bash', 'myscript.sh'])) 

blog post about the issue

2

另一種選擇是直接打電話給你的虛擬環境中的蟒蛇可執行文件,因爲許多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做助手:

import shlex 
from string import Template 

def addstep(cmdline, **kwargs): 
    tmpl = Template(cmdline) 
    factory.addStep(ShellCommand(
     command=shlex.split(tmpl.safe_substitute(**kwargs)) 
    )) 

然後,你可以做這樣的事情:

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

這些都是一些想法上手。請注意,關於shlex的整潔事情是,它將在執行拆分時尊重引用字符串中的空格。