Sublime Forum

Have a per-project build file?

#1

Hi, what I am looking for is a way to always run a single file in Sublime Text 2 when a project is open.

For example if my python project has “pyproj.py”, “foo.py”, and “bar.py” and “pyproj.py” imports foo and bar, I want the program to run “pyproj.py” no matter which file I have active.

I would like this file to be included with my project, so whenever I open the project it will use this behavior.

I found that I could do this in the Build System by creating a new Package directory, ex. PyProj and creating a file within that called pyproj.sublime-build with the contents below:

{ "cmd": "python", "-u", "pyproj.py"], "file_regex": "^ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }

However, this could get old really fast as I create new projects and want to add that single Main file to all of them. My packages directory will quickly become polluted with my projects.

Is there a better way to do this, one that possibly involves keeping all of the project-related files together? For example, maybe in the Project definition file or as a file close to where my source code is stored?

Thank you all.

0 Likes

#2

sublimetext.com/docs/2/projects.html or
sublimetext.com/docs/3/projects.html

If you want to have multiple builds systems (per project), you can use my incredibly awesome plugin, per project builds :mrgreen:

0 Likes

#3

Cool thanks. I had just figured this out moments before your reply and wrote a blog post about it. Thanks for the plugin ref, might be good for me!

0 Likes

#4

If I remember well, I used something like that in the past:

{ "cmd": "python", "-u", "${project_base_name}.py"], "file_regex": "^ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
It use the project filename as build filename.
So if you name your project pyproj.sublime-project, it will build pyproj.py, and so on.

Now my build workflow become more tricky (different build based on the files path) and I created a plugin for using as the *target *option of the build file:
http://docs.sublimetext.info/en/latest/reference/build_systems.html#options

0 Likes