Home Download Buy Blog Forum Support

dynamically loading module st2/st3

dynamically loading module st2/st3

Postby atomi on Tue Jan 29, 2013 8:03 pm

I'm trying to get my package to work with python 3.3 and I have an import statement that dynamically loads a module
Code: Select all
__import__('dictionaries.lang', globals(), locals(), ['TAGS','FUNCTIONS','VARIABLES'])


with ST2 a relative module path is fine, but with ST3 I need to prefix my module name with my package name (eg: 'mypackage.dictionaries.lang').
I tried changing the levels for the __import__ but they seem to behave differently in both versions.

Should I just test for the current ST version and change the module name accordingly?

Also it seems that sublime.load_settings() wont work in my constructor; the get() method returns None.
Is there an easier way to load my module using a string from my settings file?
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: dynamically loading module st2/st3

Postby quarnster on Tue Jan 29, 2013 10:09 pm

You can use the imp module with an absolute path to the python file you want to load. Like this:
Code: Select all
parsehelp = imp.load_source("parsehelp", os.path.join(os.path.dirname(os.path.abspath(__file__)), "parsehelp/parsehelp.py"))
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: dynamically loading module st2/st3

Postby atomi on Tue Jan 29, 2013 11:41 pm

Thanks quarnster.

Any advice on getting settings.load_settings to work? I'd like to use it to load my module.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: dynamically loading module st2/st3

Postby sapphirehamster on Wed Jan 30, 2013 12:26 am

From this response from Jon: viewtopic.php?f=2&t=10780&start=40#p42444

The sublime module is not available from the top-level of your plugin. You'll probably need to move your settings loading code into your plugin class somewhere.
sapphirehamster
 
Posts: 88
Joined: Sun Jul 01, 2012 11:19 pm

Re: dynamically loading module st2/st3

Postby atomi on Wed Jan 30, 2013 2:59 am

sapphirehamster wrote:From this response from Jon: viewtopic.php?f=2&t=10780&start=40#p42444

The sublime module is not available from the top-level of your plugin. You'll probably need to move your settings loading code into your plugin class somewhere.


Thanks! I must have glossed over that.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests