Sharan Sg
Sharan Sg

Reputation: 1

No build system showing in status bar (sublime text)

I am encountering an issue with my build system configuration in Sublime Text. Here is the configuration:

json

{
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "shell": true,
    "working_dir": "${file_path}"
}

I have also defined a key binding for this build system:

json

{
     "keys": ["ctrl+f5"],
    "command": "build",
    "args": {"variant": "run_python"},
    "selector": "source.python",
    "working_dir": "$file_path"
}

However, when I save my code and press ctrl+f5, it shows an error message: "No build system with variant run_python".

Can anyone please help me solve this issue?

Please make sure to provide additional context or relevant information if necessary when posting on Stack Overflow.

Upvotes: 0

Views: 456

Answers (1)

OdatNurd
OdatNurd

Reputation: 22811

The reason this is happening is that your key binding is incorrect; partly because it contains keys that are not valid in a key binding (which is harmless but confusing to you when you look at it) but mostly because it doesn't line up with the build you're using.

If we examine the key binding itself:

{
     "keys": ["ctrl+f5"],
    "command": "build",
    "args": {"variant": "run_python"},
    "selector": "source.python",
    "working_dir": "$file_path"
}

The keys selector and working_dir are not valid in a key binding; those are things that exist only in the sublime-build file. So, while they will be ignored, they also do nothing; you should remove them or you will confuse yourself when you try to edit them and nothing happens.

The arguments you're providing to the build command tell it that it should be trying to invoke a build with a variant named run_python, but your build file does not have any variants in it.

What you're asking it to do is find some build somewhere with a run_python variant, and then run the variant. But, since there is not one, the command does nothing and you see a message in the status bar to that effect:

No variant build error

Use of a variant is usually reserved for situations where a build can do multiple things and you want to specifically select one of them. In your case your build just runs Python. So, you should adjust your key binding to somethig like the following, but note that you will need to adjust the name of the build system based on what you named yours:

{
    "keys": ["ctrl+f5"],
    "command": "build",
    "args": {
        "build_system": "Packages/User/RunPython.sublime-build",
        "variant": "",
    },
},

This tells Sublime to specifically use the named build, with no variant.

You can also remove the variant argument since in this case it is not needed, but it can be a handy reminder that should your build actually contain variants, you can enter its name to have the binding always execute that specific variant.

Note also that in your case you could just set the build to Automatic in the Tools > Build System menu and then use the normal build command to execute (See the key binding for that in Tools > Build), but presumably you are going more for an IDE feel with a specific key combination for running your code.

Just note that when defined this way, your key binding will always try to execute Python, even if that's not correct for the situation. If you use more than one language, you can set up multiple key bindings for the key, with a different context entry for each that makes them available only in specific file types.

I have a video that demonstrates this whole process on my YouTube Channel if you would like a more visual runthough, as well as a complete build system playlist that provides more details on how builds work in general, including a video dedicated to variants and how to set them up.

Upvotes: 0

Related Questions