Sublime Forum

Cannot get my `file_regex` to match

#1

Dear group,

using ST4 build 4199 under Ubuntu Linux, my project file looks like this:

{
	"folders":
	[
		{
			"path": "..",
			"folder_exclude_patterns": ["__pycache__", ".venv", ".ruff_cache"]
		}
	],

    "build_systems":
    [
        {
            "name": "ruff check",
            "working_dir": "$folder",
            "shell_cmd": "source ./.venv/bin/activate && ruff check",
            "file_regex": "(\\w+\\.py):(\\d+):(\\d+)",
            "quiet": true,
        },
    ],
}

When I run the “ruff check” build, the output is like this:

SIM103 Return the condition `(date.today() - d).days < 3` directly
  --> backup.py:21:5
   |
19 |           return True
20 |
...

However, the file_regex doesn’t match and whatever I try, I cannot make it match.

Can someone please give me a hint?

0 Likes

#2

Maybe it is anchored implicitly or something? Does adding \\s+-->\\s+ beforehand make any difference?

Also if you have subfolders this approach would need tweaking

0 Likes

#3

No, unfortunately not.

(Also, I’m not sure if I can start with a smallest possible regex for testing, then work from there? :thinking: )

Because of the \\w+? Yes, I’m aware of that.

0 Likes

#4

Whoa, it works!

No idea where I picked up that assumption, but I had somehow expected ST to highlight the file_regex match directly in the build output. (Is it even supposed to do that?) So it took me a while to notice that the status bar briefly flashes “build completed with … errors” whenever the regex matches. After that, I tried double-clicking the filenames more deliberately — and yep, that finally did the trick.

Sorry for the false alarm!

I do have a few follow-up questions, though:

  • Is there any way to have the regex match actually highlighted in the build output? That would make things a lot easier.
  • Can a build command be modified dynamically before it runs? For example, a test command usually runs the full suite, but sometimes I’d like to pass an extra parameter to limit which tests get executed.
  • If a build process writes to both stdout and stderr, is the output shown in the panel in the same order as it would be on a real console? It looks like stderr gets batched and appended after stdout, instead of being interleaved as usual.
0 Likes