Home Download Buy Blog Forum Support

Common Directory to reuse functions

Common Directory to reuse functions

Postby tgkeul on Wed Apr 15, 2009 7:18 pm

I saw that sublime replicated his decorator @threaded in multiple (at least 2) packages.
I don't like such things so I searched for a solution. This is a very simple one.
Add this line in sublimeplugin.py in the program directory
Code: Select all
sys.path.append (os.path.join (sublime.packagesPath(), 'Common')

Create directory 'Common' in %APPDATA%\Sublime Text\Packages
Move plugin_helpers.py or other files with commonly used objects to Common.
No other code changes are needed.

Any Comments?
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: Common Directory to reuse functions

Postby SteveCooperOrg on Thu Apr 16, 2009 3:20 pm

One possible angle is to start looking at resurrecting the PackageDownloader plugin;

http://www.sublimetextwiki.com/pages/Pa ... oader.html

This was a plugin I wrote to help people keep their systems up to date with the repo. Currently, it downloads a fixed number of packages, but it could easily be updated to allow the user to choose from a list of all the available packages in the repo.

When the user chooses a package, that packages should declare its dependencies, and the package downloader gets those as part of the update.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: Common Directory to reuse functions

Postby tgkeul on Thu Apr 16, 2009 9:13 pm

Thanks for the insight. I never looked at AAALoadFirstExtensions because I thought I don't need 'FirstExtensions'. I also looked at Plugins PackageDownloader package.
Reading and thinking about it I came to this preliminary conclusions:
  • Altering sys.path is currently not an option because of unicode problems and high effort
  • A library to reuse code will be fine
  • Users will prefer self contained packages.
Only plugin developers may be interested in a library. I suggest to
  • rename the Plugins package to PluginDevelopment
  • enhance the Lib subdir with a lot of goodies like threaded.py, wich can be copied to the plugin in development.
  • create some more snippets to possibly standardize plugin code to some degree
  • No commands here please! They should move to seperate plugins (Text ?).
This solution provides a library for reuse and self contained packages. It is quite simple and to the developers to feed the library.

Not solved is the dependecy problem between packages.
Extending PackageDownloader is not bad, but there has to be someone who takes care to define the dependencies. As nobody will do this a dependency analyser should be developed to do the job.
The analyser may get the information from __init__.py. The dependent plugin should define which plugins are needed. Somewhat like this:
Code: Select all
if not os.path.exists ('../CTags/ctags.py'):
    sublime.statusmessage ('please install package CTags')
    do_something_to_prevent_plugin_from_execution_or_to_download_CTags()

The packages are self-managed and PackageDownloader is not needed for this purpose. Although I like the idea of a package manager which is highlighting updated packages - but this is a different thread.

Hmm, rereading my test I see that you can force the user to install a common package. But self contained packages are prefered for easy installation.

I hope this discussion will lead to a simple and robust solution to reuse code.
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: Common Directory to reuse functions

Postby SteveCooperOrg on Fri Apr 17, 2009 12:48 pm

Anther approach; Subversion allows you to import external branches into your working copy.

http://svnbook.red-bean.com/nightly/en/ ... rnals.html

I believe this allows you to declare that a separate library folder should be checked out underneath the plugin folder. So you can create this in the repo;

trunk
/lib
/customplugin

and add a property to say that `customplugin/importedlib` is a copy of `trunk/lib`

This means, I believe, that when you check out customplugin, you get a copy of the lib folder at customplugin/importedlib. Any number of plugins can do the same trick, meaning that a plugin can bring in shard dependent files. This should work for both developers and for people getting the files from http://www.sublimetextwiki.com.

At least, I believe this is how things should work. Someone'll have to try it out. I don't know if it'll do everything you need.

Steve
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: Common Directory to reuse functions

Postby SteveCooperOrg on Wed Apr 29, 2009 2:49 pm

I've been playing around with this in my own repository, and it seems to work fine. The summary is;

- add a subversion property to the package directory. This should read, eg

Code: Select all
../MyCommonLib common


When you chekc this folder out, you'll end up with a common folder. Note that you can use relative paths to specify the common codebase.

- Remember to include a __init__.py file in the common folder. This turns the common folder into a python package, allowing you to use import statements like;

Code: Select all
import common.directoryfuncs


to include the code in common/directoryfuncs.py

- you can add files directly into common, and normal add/commit/update operations will work as you expect, committing the details to ../MyCommonLib.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: Common Directory to reuse functions

Postby jps on Thu May 28, 2009 12:59 pm

If there's a set of common functionality that's used across a bunch of plugins, I'm happy to start including it in the default install of Sublime to make life a little simpler. It wouldn't solve the issues mentioned above, but it may help.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Next

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 5 guests