justinfx/MayaSublime — pull request #11 by fredrikaverpil (2013-07-29 15:18:30+00:00)
Title: Passing on __file__ with the __main__.__dict__

When sending a file to execfile() I also pass on __file__ which is great. Now my scripts can import or link to other files which locations are defined relative to the script file's file path (__file__).

I wasn't sure on how to pull the latest file from your repo and go from there, so I copy-pasted the contents of your current MayaSublime.py and changed the following:

PY_CMD_TEMPLATE = textwrap.dedent('''
import traceback
import __main__
g = __main__.__dict__.copy()
g['__file__'] = '{2}'
try:
{0}({1!r}, g, g)
except:
traceback.print_exc()
''')

and...

mCmd = self.PY_CMD_TEMPLATE.format(execType, mCmd, file_path)

I'll close the issue I made regarding this.