Sublime Forum

How to do scripting in a build file

#1

I have a standard build file for running Python3 scripts that looks like this:

{
“cmd”: ["/Library/Frameworks/Python.framework/Versions/3.6/bin/python3", “-u”, “$file”],
“file_regex”: “^[ ]File "(…?)”, line ([0-9]*)",
“selector”: “source.python”
}

I want to modify it so when I hit Command-B on a current sub2.py file, it runs the following command instead:

python3 -m mypackage.sub1.sub2

The purpose of it is that I can run my python code as a package relative from the project directory, in order to make all the imports work. It can be done easily, if I could execute a simple Python script in a build file. What I need to do in that script is to remove the project path from the full path to current file using the values from $file and $project_path variables, and then replace the ‘/’ with ‘.’. Is it possible to do this kind of simple script in a build file?

0 Likes