Sublime Forum

Plugin loading order

#1

Hi,

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

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:

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.

0 Likes

#2

Move that import from line 72 to the top where other imports are.

0 Likes

#3

Unfortunately, that doesn’t change anything as Default/exec.py is still loaded after my plugin so it doesn’t find it.

0 Likes

#4

Ok, how about this:

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.'
0 Likes

#5

This works, thank you.

0 Likes

#6

+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…

0 Likes