Difference between revisions of "PluginsTips"

From GNU MediaGoblin Wiki
Jump to navigation Jump to search
Line 10: Line 10:
   
 
==Making an installable plugin==
 
==Making an installable plugin==
If you followed the steps above, you can use your plugin by copying it into the plugins folder; however, to get a plugin that is easily installable by users (e.g. with <tt>pip install myplugin</tt>), it should have a certain folder layout. A good example is the [https://github.com/commonsmachinery/mg-rdfa/ RDFa plugin]. This uses a setup.py file to install the files under the mediagoblin_rdfa folder into the lib/ folder of your mediagoblin installation. If you've checked out both mediagoblin and mg-rdfa in the same folder, e.g. ~/src/, you can do <pre>cd ~/src/mg-rdfa/
+
If you followed the steps above, you can use your plugin by copying it into the plugins folder; however, to get a plugin that is easily installable by users (e.g. with <tt>pip install myplugin</tt>), it should have a certain folder layout.
  +
  +
A good example is the [https://github.com/commonsmachinery/mg-rdfa/ RDFa plugin]. This uses a setup.py file to install the files under the mediagoblin_rdfa folder into the lib/ folder of your mediagoblin installation. If you've checked out both mediagoblin and mg-rdfa in the same folder, e.g. ~/src/, you can do <pre>cd ~/src/mg-rdfa/
 
../mediagoblin/bin/python setup.py build
 
../mediagoblin/bin/python setup.py build
../mediagoblin/bin/python setup.py install</pre> to install it to your mediagoblin instance.n
+
../mediagoblin/bin/python setup.py install</pre> to install it to your mediagoblin instance.
  +
  +
The file layout of the repo is:
  +
<pre>
  +
setup.py
  +
MANIFEST.in
  +
README.md
  +
mediagoblin_rdfa/
  +
__init.py__
  +
templates/
  +
mediagoblin/
  +
plugins/
  +
rdfa/
  +
metadata.html
  +
</pre>
  +
  +
The setup.py file defines an option include_package_data=True, which makes it read the file MANIFEST.in; MANIFEST.in contains rules for which files to include when installing. In this case, rule <tt>recursive-include mediagoblin_rdfa *.html</tt> makes it include the HTML template file (and any other you put under mediagoblin_rdfa), retaining the folder layout.

Revision as of 15:47, 17 January 2014

Quickstart

In the mediagoblin repository, there's a sample plugin under mediagoblin/plugins/sampleplugin that you can use to get started with plugin creation. The simplest way to get up and running is to

  1. Follow HackingHowto#How_to_set_up_and_maintain_an_environment_for_hacking_with_virtualenv to set up a local virtualenv mediagoblin instance
    • run it with ./lazyserver.sh so you get debug output (if you run celeryd separately, you won't see logging.info from stuff run in celery tasks)
  2. cp -r mediagoblin/plugins/sampleplugin mediagoblin/plugins/myplugin (where "myplugin" is your plugin name)
  3. cp mediagoblin.ini mediagoblin_local.ini
  4. edit mediagoblin_local.ini and add [[mediagoblin.plugins.myplugin]] under the [plugins] section to enable your plugin

Now you can look at e.g. other core or non-core plugins for inspiration. See Available Plugins for non-core plugins.

Making an installable plugin

If you followed the steps above, you can use your plugin by copying it into the plugins folder; however, to get a plugin that is easily installable by users (e.g. with pip install myplugin), it should have a certain folder layout.

A good example is the RDFa plugin. This uses a setup.py file to install the files under the mediagoblin_rdfa folder into the lib/ folder of your mediagoblin installation. If you've checked out both mediagoblin and mg-rdfa in the same folder, e.g. ~/src/, you can do

cd ~/src/mg-rdfa/
../mediagoblin/bin/python setup.py build
../mediagoblin/bin/python setup.py install

to install it to your mediagoblin instance.

The file layout of the repo is:

setup.py
MANIFEST.in
README.md
mediagoblin_rdfa/
                 __init.py__
                 templates/
                           mediagoblin/
                                       plugins/
                                               rdfa/
                                                    metadata.html

The setup.py file defines an option include_package_data=True, which makes it read the file MANIFEST.in; MANIFEST.in contains rules for which files to include when installing. In this case, rule recursive-include mediagoblin_rdfa *.html makes it include the HTML template file (and any other you put under mediagoblin_rdfa), retaining the folder layout.