gpt4 book ai didi

python - fabric 没有获取 Django 环境

转载 作者:太空宇宙 更新时间:2023-11-04 12:59:06 24 4
gpt4 key购买 nike

我的本​​地系统中有一个结构文件,我用它在远程服务器(在 virtualenv 中)部署代码并想测试它。方法定义如下。

    def test_deploy(gitid = '930bfc4'):
# manually put the commit id at the end
path = '/tmp/testapp/app1/source/demo4'
with cd(path):
commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
# change the settings.py file and update the database
run (commit_id)
run ('cat .git/FETCH_HEAD')

path1 = '/tmp/testvehic/vehic'
with cd(path1):
run ('pwd')
env.activate = 'source /tmp/testapp/app1/bin/activate'
run ('python /tmp/testapp/app1/source/demo4/manage.py test')`

表明

ImportError: No module named django.core.management

在谷歌搜索后,我才知道它实际上并没有定位我的 django 环境。
我的虚拟环境路径是/tmp/testapp/app1
源代码在/tmp/testapp/app1/source/app1/
当我在服务器终端运行命令 python manage.py test 时,它工作正常。我如何通过织物进行测试?

最佳答案

我从下面的链接得到了答案

http://nurupoga.org/articles/deployment-with-fabric-and-virtualenv/

我的代码片段现在看起来像这样

VENV_DIR = '/home/rootuser/testvehic/vehic'
PROJECT_DIR = '/home/rootuser/testvehic/vehic/source/cabsdemo4'

@contextmanager
def source_virtualenv():
with prefix('source ' + os.path.join(VENV_DIR, 'bin/activate')):
yield
def test_deploy(gitid = '930bfc4'):
# manually put the commit id at the end
path = '/tmp/testapp/app1/source/demo4'
with cd(path):
commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
# change the settings.py file and update the database
run (commit_id)
run ('cat .git/FETCH_HEAD')
with settings(warn_only=True):
with cd(PROJECT_DIR):
with source_virtualenv():
run('pip install -r requirements.txt')
run('python manage.py test')

关于python - fabric 没有获取 Django 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34769974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com