Home Download Buy Blog Forum Support

Plugin loading order

Plugin loading order

Postby tom_s on Fri Aug 24, 2012 3:51 pm

Hi,

I'm writing a build plugin based on exec.py like this:

Code: Select all
execcmd = __import__("exec")
class BuildThisCommand(execcmd.ExecCommand):


However, since Sublime Text loads the packages in alphabetical order, Default/exec.py isn't loaded yet when my plugin loads when ST2 starts, I get this error:

Code: Select all
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 62, in reload_plugin
  File ".\BuildThis.py", line 72, in <module>
    execcmd = __import__("exec")
ImportError: No module named exec


Could Sublime Text be changed to load the Default folder first and then the others (would be my preference)? Or can I delay loading my plugin? I don't want to change the name so it's behind Default and I don't want to copy the whole exec.py and insert my code into it.
tom_s
 
Posts: 7
Joined: Fri Aug 24, 2012 3:32 pm

Re: Plugin loading order

Postby madnomad on Fri Aug 24, 2012 10:15 pm

Move that import from line 72 to the top where other imports are.
madnomad
 
Posts: 18
Joined: Tue Aug 14, 2012 8:34 pm

Re: Plugin loading order

Postby tom_s on Sat Aug 25, 2012 7:46 am

Unfortunately, that doesn't change anything as Default/exec.py is still loaded after my plugin so it doesn't find it.
tom_s
 
Posts: 7
Joined: Fri Aug 24, 2012 3:32 pm

Re: Plugin loading order

Postby madnomad on Sat Aug 25, 2012 9:06 am

Ok, how about this:

Code: Select all
import sublime, sublime_plugin
import os, sys

sys.path.append(os.path.join(sublime.packages_path(), 'Default'))
execcmd = __import__("exec")
sys.path.remove(os.path.join(sublime.packages_path(), 'Default'))

class BuildThisCommand(execcmd.ExecCommand):
    print __name__, 'class.'
    def run(self):
        print __name__, 'run.'
madnomad
 
Posts: 18
Joined: Tue Aug 14, 2012 8:34 pm

Re: Plugin loading order

Postby tom_s on Sat Aug 25, 2012 9:21 am

This works, thank you.
tom_s
 
Posts: 7
Joined: Fri Aug 24, 2012 3:32 pm

Re: Plugin loading order

Postby bizoo on Mon Aug 27, 2012 6:53 am

tom_s wrote:Could Sublime Text be changed to load the Default folder first and then the others (would be my preference)?

+1
and User folder should be probably the last loaded.

You have this kind of issue when you want to inherit from a class defined in the Default folder and your package folder begin with A or B or C...
bizoo
 
Posts: 880
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests