Sublime Forum

Plugin organization / importing

#1

Hi all,

I’m at the point where my plugins are getting pretty hairy and I’m looking for the right way to organize my code into manegable bite-sized chunks. This has lead me to try and implement a workspace hierarchy, but I am having trouble importing sub modules. For me, I typically organize my code into workspaces > projects

So under “Sublime Text 3 / Packages” directory I have the “workspace_txt” directory
Inside “workspace_txt” there are a number of projects, mostly proof of concept stuff… used to gradually piece together the various functionality for a working system

Example:

workspace_txt

sublimeplgn_dothis
    plgnfile1.py
    plgnfile2.py
    plgnfile3.py

sublimeplgn_dothat
    plgnfile1.py
    plgnfile2.py
    plgnfile3.py

sublimeplgn_dobedobedo
    etc...

I understand from reading the forum that sublime only ‘imports’ one level. That is, things were working with my big hairy plugins as long as they were directly under “Sublime Text 3 /Packages/workspace_txt”. One would see it load in the console upon starting sublime. But upon organizing them into project sub directories i.e. “sublimeplgn_dothis” they no longer are loading when sublime starts up.

So is there a way to implement this sort of organization / structure? Or should I be doing this differently?

thanks for any and all help :slight_smile:

1 Like

#2

Right, so I’ve found this but its a few years old…

Please my good fellows, might one of you have a bit of code to get me started down the right path in figuring out my problem? I am not sure how to use the reload functionality, though from what I see, the python docs say now this is imp.load_module. I’ve been trying to figure it out, but god, I’m at that stage where I’m putting it out there.

:slightly_smiling:

0 Likes

#3

 
I wrote this implementation of imp.load_module, but I’m note sure that it will address your issue.

The code I linked to reloads any imported modules whenever the primary plugin file is saved.

From what I can gather from the OP, you are looking to figure out a way for Sublime Text to load plugins that are nested beyond a single subdirectory.  I’m not sure that there’s a way to do that.

1 Like

#4

Thank you fico, I was in the process of bastardizing module_loader, trying to figure out something. :slight_smile: It is just so strange to think something so simple isn’t out there. How does one usually put together organized “scratch” programming areas? I like to organize my exploratory programing around certain “workspaces” then I go write the real code. Basically, I try and digest a language / tech a little bit at a time, and have many “hello world” programs in a “workspace” directory which contain projects that build on one another. Again, thank you for any help :slight_smile: And thank you for contributing your source code for module_loader so I can probably make it worse :smiley: lol…

2 Likes

#5

@stupid

 
I have a TEST.py file that I use for:

  • testing functions before adding them to my plugins
  • writing solutions to forum & StackOverflow questions.

It contains class TestCommand( sublime_plugin.TextCommand ), which is bound to Ctrl + Super + Alt + NumPad/, so it’s easy to test whatever I’m working on.

Any code in there is pretty short lived, as it either gets posted as a solution or integrated into a plugin with it’s own key-bindings, settings files, etc.

When working on plugins, I’ll usually start by writing a simplified version of what I’ll need in the actual plugin @ TEST.py, and once it works I’ll move it to the plugin where it then gets refactored & further tested.

Additionally, I have a utils directory with a bunch of custom modules which contain code that I know I’ll be using frequently ( which is what I wrote module_loader for ).
 



 
I find that using a single file for staging keeps things easy to manage and forces it’s contents to either be finalized & implemented elsewhere, or discarded.

At times, I have unfinished code for multiple projects in TEST.py, at which point I comment out all code that isn’t currently active.  This allows me to use the same key-binding no matter what code I’m testing.  Here’s a simplified example of how that file might look ( and a useful EventListener reference at the end ).

1 Like

#6

Thanks again fico,

I’m a bit of a code-hoarder. lol. For me, at least the learning curve of sublime is steep, so I keep a lot of my little plugin projects (where i document the hell out of the functionality) Often I zip back into one of those old projects and pull out a couple lines of code… stuff I remember writing / getting to work a certain way. They are like my legos.

As it stands for tonight, my current idea is essentially a dummy plugin, which essentially is your module_loader at root. I put more-or-less your code into:

def plugin_loaded()

this method executes when api loads all its stuff, thus, I was seeing whether or not I can force the dynamic loading of plugins after… either through imp or importlib. Python is not my native language so, I just keep fighting and reading stack overflow, docs, and a bunch of blogs. :slight_smile:

Thanks again :slightly_smiling:

1 Like

#7

this worked for me:
http://docs.sublimetext.info/en/latest/extensibility/packages.html

0 Likes