我正在尝试为基于virtualenv的Python项目建立一个Python构建系统。
通常我的所有Python virtualenv项目都以相同的方式设置:包含/ src(我的代码所在的位置)的单个项目文件夹,以及virtualenv python解释器与激活脚本一起生成的/ bin。
我想将$ project_path / src添加到可变的PYTHONPATH环境中。为了调试这个我设置了这样一个项目:
{
"build_systems":
[
{
"name": "pythonX",
"env":
{
"PYTHONPATH":"${project_path}/xxxxxyy"
},
"working_dir": "${project_path:${folder}}/src",
"cmd":
[
"${project_path}/bin/python2.7",
"-u",
"$file"
]
}
],
"folders":
[
{
"path": "/home/sal/workspace/pythonmoo"
}
]
}
我制作了一个Python脚本来测试它 - 我刚打印出sys.path(它应该选择Pythonpath),但是我看到了以下内容:
'/home/sal/workspace/pythonmoo/src/${project_path}/xxxxxyy',
很明显,变量没有扩展。
我在这里做错了什么?是否有更好的方法来实现我的目标?
更新0:
正如所建议的那样,我将其重新实现为.sublime-build文件。结果完全相同: - 变量扩展在cmd中工作正常,但在env中没有。
{
"env":
{
"PYTHONPATH":"$project_path/src"
},
"working_dir": "${project_path:${folder}}/src",
"cmd":
[
"${project_path}/bin/python2.7",
"-u",
"$file"
]
}
答案 0 :(得分:0)
不确定这是否是您正在寻找的,但我做了类似的事情,并设置了"evn":{"PYTHONPATH":"."}
并为我提取了src
目录。
{
"build_systems": [
{
"name": "python-test",
"cmd": ["${project_path}/Scripts/python", "-u", "$file"],
"working_dir": "${project_path:${folder}}/src",
"selector": "source.python",
"env": {
"PYTHONPATH": "."
}
}
],
"folders": [
{
"path": "/C/projects/python/test"
}
]
}
当我运行设置virtualenv的脚本时创建了这个。
项目test
的结构是:
test/
|-- Include/
|-- Lib/
|-- Scripts/
|-- src/
| |-- ospaths.py
| |-- package/
| | |-- test.py
ospaths.py
import sys
def get():
return sys.path
package/test.py
import ospaths
for path in ospaths.get():
print path
这给了我以下输出:
C:\projects\python\test\src\package
C:\projects\python\test\lib\site-packages\setuptools-0.6c11-py2.7.egg
C:\projects\python\test\lib\site-packages\pip-1.3.1-py2.7.egg
C:\projects\python\test\src
C:\Windows\system32\python27.zip
C:\projects\python\test\DLLs
C:\projects\python\test\lib
C:\projects\python\test\lib\plat-win
C:\projects\python\test\lib\lib-tk
C:\projects\python\test\Scripts
C:\Python27\Lib
C:\Python27\DLLs
C:\Python27\Lib\lib-tk
C:\projects\python\test
C:\projects\python\test\lib\site-packages
[Finished in 0.6s]