Home Download Buy Blog Forum Support

Have a per-project build file?

Have a per-project build file?

Postby Arcana on Fri Aug 23, 2013 6:06 am

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:

Code: Select all
{
    "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.
Arcana
 
Posts: 5
Joined: Tue Apr 30, 2013 5:35 pm

Re: Have a per-project build file?

Postby iamntz on Fri Aug 23, 2013 6:45 am

http://www.sublimetext.com/docs/2/projects.html or
http://www.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:
iamntz
 
Posts: 896
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Have a per-project build file?

Postby Arcana on Fri Aug 23, 2013 7:02 am

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!
Arcana
 
Posts: 5
Joined: Tue Apr 30, 2013 5:35 pm

Re: Have a per-project build file?

Postby bizoo on Fri Aug 23, 2013 7:27 am

If I remember well, I used something like that in the past:
Code: Select all
{
    "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
bizoo
 
Posts: 873
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to General Discussion

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 24 guests