Home Download Buy Blog Forum Support

build a main file

build a main file

Postby nicor on Thu Feb 02, 2012 11:22 pm

Hi there,

I'm working on a Python project containing several files, one of which is the main one. I'm quite the newbie both to Python and to this sublime Sublime Editor, so here goes the question: how can I set up the build system so that the main file is built every time I hit the shortcut?

Thanks in advance for any response, fellows.
nicor
 
Posts: 3
Joined: Thu Feb 02, 2012 11:20 pm

Re: build a main file

Postby nicor on Sun Feb 05, 2012 5:35 am

I just re-read this post and maybe it isn't clear enough. What I want is to be able to build the main file despite being editing another file. That is, I want to skip clicking on the main file and then building.
nicor
 
Posts: 3
Joined: Thu Feb 02, 2012 11:20 pm

Re: build a main file

Postby skaet on Sun Feb 05, 2012 9:05 am

If I understand this, you're looking for a way to tell Sublime to build a specific file regardless of which file has focus/is open at the time?

The Build Systems pages on st.info can probably help:
http://sublimetext.info/docs/en/core/build_systems.html
http://sublimetext.info/docs/en/referen ... stems.html

From there you can see this snippet:
Code: Select all
{
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}


Simply replace "$file" on the cmd line with an absolute path to the main file of your project and save it as a .sublime-build file in your User directory. This should give you a project-specific build system which you can select from the menu. This approach isn't very flexible and you'll need to edit it or create a new .sublime-build file for each project. If your projects share a common naming scheme and folder structure, you might try using either "$file_path" or "$project_path" variables to create a more robust build file. This can be handy if you move between environments like Windows and Linux, or have multiple workstations that may not be configured the same way.
skaet
 
Posts: 93
Joined: Thu Sep 16, 2010 3:37 pm

Re: build a main file

Postby nicor on Sun Feb 05, 2012 7:13 pm

It worked fantastically :) Thanks so much! I wonder whether this wouldn't be a nice feature anytime you work in a project, as they tend to be multifile.
nicor
 
Posts: 3
Joined: Thu Feb 02, 2012 11:20 pm

Re: build a main file

Postby atomi on Sun Feb 05, 2012 9:07 pm

Sublime allows project specific build systems

http://www.sublimetext.com/docs/2/projects.html
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: build a main file

Postby skaet on Sun Feb 05, 2012 9:36 pm

atomi wrote:Sublime allows project specific build systems

http://www.sublimetext.com/docs/2/projects.html

Ah well there we go :) I wasn't aware of that.
skaet
 
Posts: 93
Joined: Thu Sep 16, 2010 3:37 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 12 guests