【发布时间】:2013-09-11 15:42:30
【问题描述】:
我有一个随身碟:
- Sublime Text 2 可移植到 Windows(32 位和 64 位)
- 便携式 Python 安装
- Android ADT 等更多内容
目前我有一个批处理文件,它为 cmd 会话“设置”环境变量,然后我从 cmd 运行这些文件。现在显然这不是很理想,也不是很有效。
如何使用同一笔式驱动器上的 python 可执行文件在 Sublime Text 2 中构建/运行文件,比如 .py 文件?
更新:
尝试失败F:\foo\SublimeText2_x64\Data\Packages\Build Systems\My Python.sublime-build
{
"working_dir": "$packages",
"cmd": ["cd ..\\..\\.. && setupenv && cd $file_path &&",
"python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell": true
}
这就是我最终得到的结果:
{
"working_dir": "${packages}\\Build Systems",
"cmd": ["build.bat", "python", "$file_path", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
build.bat(我打算为此添加更多语言,使其成为多语言构建文件)
@echo off
if "%1"=="" call :usage 0 & goto end
if "%2"=="" call :usage 1 & goto end
if "%3"=="" call :usage 2 & goto end
set my_dir=%~dp0\..\..\..\..
::------------------------- Setting Up the Environment -------------------------
:: Python
SET PATH=^
%my_dir%\PortablePython2.7.5.1\App;^
%my_dir%\PortablePython2.7.5.1\App\Scripts;%PATH%
:: Git
SET PATH=%my_dir%\Git\cmd;%PATH%
::------------------------------------------------------------------------------
pushd %2 :: Goto to the directory with the file
python -u %3 & goto end
:: ----------------------------------- Usage -----------------------------------
:usage
echo Error: Need 3 arguments (got %1)
echo Usage:
echo build.bat language file_path file
echo.
echo Arguments:
echo language : The language to build the file with
echo Supported languages - python
echo file_path : Path to the file
echo file : Name of the file (preferably with path)
goto end
::------------------------------------------------------------------------------
:end
popd
【问题讨论】:
标签: python sublimetext2 build-automation