Sublime Forum

Plugin not working through Package Control Installation

#1

Hey,

i’ve got a Plugin i created a while ago, which works without a Problem when it’s installed manually as a Folder through download or cloning. But if i install it through Package Control as a “.sublime-package” it doesn’t do anything, not even a single log entry. I i extract that package it works, so the contents in that package itself seem to be correct.

Has anyone ever experienced something like this?

Here’s the repo of the package i’m talking about: github.com/mneuhaus/SublimeFileTemplates

Cheers
Marc

0 Likes

#2

What version of Sublime Text are you using?

If you are using ST3 with the latest package control version, your package is not getting unpacked. As you stated it works fine if you manually extract the file. Package control installs your package into the installed packages directory but never extracts your package. From what I can see you are trying to searching the packages directory for templates which do not exist yet.

I believe you can add an empty file named “.no-sublime-package” to the root of your package and package control will unpack your plugin. I have decided to use this option with a plugin that I’ve developed, but you may be able to load the resources using one of the sublime api calls (load_resource or load_binary_resource) but I cannot say for sure as I have not tried to use these functions yet.

I hope this helps.

-Nick

0 Likes

#3

So, before I get to your problems:

  1. Don’t use so many globals! It will hunt you down eventually and is a very bad habit. Use parameters or class properties where possible, such as for your populate_file function.
  2. You are leaking file handles. Thrice. Use the with operator in Python to reliably close resources like file handles once you are done with them (even when exceptions occur). with is awesome.

Anyway, back to your problem.

In find_templates you use os.walk(sublime.packages_path()).You need to use sublime.find_resource on ST3 instead as it will find files in .sublime-packages (such as this very package when installed) and then use the load_resource API. These are only for ST3 however, so you either need to provide a different mechanism for ST2 or stop supporting it.
I’m not exactly sure if that’s everything, but that is the first and pretty much only offense I found.

And a tip: You may provide the open_file command with text that it will open if the file does not exist. window.run_command("open_file", {"file": filepath, "contents": content}) That will get rid of the very weird on_load construct and the event listener in general.

0 Likes