Sublime Forum

Build a main file

#1

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.

0 Likes

#2

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.

0 Likes

#3

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:
sublimetext.info/docs/en/core/build_systems.html
sublimetext.info/docs/en/referen … stems.html

From there you can see this snippet:

{ "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.

0 Likes

#4

It worked fantastically :smile: 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.

0 Likes

#5

Sublime allows project specific build systems

sublimetext.com/docs/2/projects.html

0 Likes

#6

[quote=“atomi”]Sublime allows project specific build systems

sublimetext.com/docs/2/projects.html[/quote]

Ah well there we go :smile: I wasn’t aware of that.

0 Likes