don't rely on os.getcwd to get master basedir when looking for templates

Fixes #2586.