It seems python in msys2 has some weird behavior. For __file__, it
returns a string which uses windows-style separator '\', however,
os.path.dirname only recognizes the unix-style separator '/', and
consequently, the path of Mako is not added properly.
This is a new attempt of #10586, after Simon Sapin's great cleanups in #10749 has landed. I have adjusted the changes to the new structure that was introduced, and also only done a few of the longhand ones. Will certainly continue on this as soon as we have a basic agreement that this style is reasonable.