不,对于一个 '--relocatable' 不会更新 'virtualenv/bin/activate' 脚本。是的,您可以按照 zeekay 的建议通过重新运行虚拟环境设置来解决这个问题,但是仍然无法导入放置在“virtualenv/src”中的任何“pip -e git ...”安装,因此您将不得不重新运行那些 pip 手动安装。
随着我作为开发人员获得了经验,我现在避免了额外的依赖和抽象层,它们往往会成为失败点。
所以现在我不使用 pip 可编辑(-e)安装,如果需要手动将存储库克隆到 'project/src/' 而不是 'project/virtualenv/src' 并auto_prep_pythonpath.py
在启动我的项目之前加载以下脚本(我在我的django.wsgi
脚本中引用它)。
作为旁注,我将“定制”附加到放置在“项目/src”中的任何被修改/被黑客攻击的包中,这样我就不必担心向后兼容性,并且我可以像在线存储库一样跟踪代码控制下的所有源代码并且会给你刹车。
希望这可以帮助。
"""
Prepares python path to include additional project/src/<APP> in PYTHONPATH - This file gets automatically loaded by projects __init__.py
This script lives in 'project/src/django-project/auto_prep_pythonpath.py', modify
'SOURCE_ROOT' if you place it somewhere else.
"""
import logging
import os
import sys
SOURCE_ROOT = os.path.dirname(os.path.abspath(__file__)).replace('\\','/') # the replacements are when on windows
SOURCE_ROOT = os.path.join(SOURCE_ROOT, '../').replace('\\','/')
SOURCE_ROOT = os.path.normpath(SOURCE_ROOT)
logger = logging.getLogger(__name__)
logger.info("Adding packages in 'src/*' required by project to PYTHONPATH.")
dirlist_arr = os.listdir(SOURCE_ROOT)
while dirlist_arr:
item_path = os.path.join(SOURCE_ROOT, dirlist_arr.pop()).replace('\\','/') # replace dashes is for win based file system
if os.path.isdir(item_path):
if not item_path in sys.path:
sys.path.insert(0, item_path) # we use insert to take precedence over any global paths - minimizes import conflict surprises
logger.debug("Path '%s' added." % item_path)