> Could you provide an example of how to import and egg
> programmatically?
Well that is the catch. Eggs rely on setuptools to do install,
versioning, and dependencies. It will be a little tricky to make site-
packages for each application, since setup tools was not created to
have more than one site-packages dir, thus virtualenv, but virtualenv
also monkeys with the sys.path.
So here is one idea:
Use easy_install to install dependencies to python's site-packages dir
or better yet web2py/site-packages, then have another web2py script
that reads an applications egg spec and copies the versions of all
required eggs from site-packages to applications/foo/plugins/ .
When run, the script needs to be fully automated to remove/add eggs
with the latest required versions from root site-packages, this way
applications contain the eggs/versions they need and only the eggs/
versions they need.
This way you get the benefits of setuptools/eggs and applications can
be distributed as stand alone.
The next part is how to actually import them:
This is where setuptools goes wrong:
from pkg_resources import require
require("SomePackage", "OtherPackage", "MyPackage")
"which will put the latest installed version of the specified packages
on sys.path for you."
We do not want to modify the sys.path so we make our own require, it
could be mixed into the exec_env:
Internally require could use mod_import from here:
http://groups.google.com/group/web2py/browse_thread/thread/f9e117f081cfab24/e2f66268d0fb0471?hl=en&lnk=gst&q=__import__#e2f66268d0fb0471
def require(app):
def require(name_and_version):
plugin = rewrite_plugin_str(name_and_version)
return mod_import('applications.%s.plugins.%s'%(app,plugin))
return require
require = require(request.application)
...
simplejson = require('simplejson<2.0')
or
simplejson = require('simplejson')
So each application would need an egg spec that lists its plugins
(eggs) and any specific versions. Dependencies are resolved and all
needed eggs are copied to the application's plugins dir.
Say you want to install 'ThatPlugin':
easy_install ThatPlugin
add ThatPlugin as a dependency in myapps's egg spec
python web2py/scripts/install_plugins myapp #reads specs, copies eggs
The install_plugins script could make full use of setuptools locally
to parse the specs, we2py.plugins.require will need to be compatible
with setuptools but not depend on setuptools because setuptools will
not be available on the production platform (eg GAE).
Robin
> On Jan 21, 10:56 am, Robin B <[email protected]> wrote:
>
> > To do 'last_modification_timestamp' add the more general cases:
> > oncreate= and onupdate= callbacks to db.Field.
>
> > A plugin system needs versioning and dependencies, and instead of
> > creating a one off web2py plugin spec, it is better to reuse the
> > standard egg spec. Eggs can be installed as directories or zip files
> > (works on GAE too). Ian Bicking's virtualenv, which uses eggs, is
> > used for Pylon's plugin system. The reason web2py does not use
> > virtualenv is because virtualenv modifies the sys.path. The solution
> > for web2py plugins is to use eggs and import them without modifying
> > the sys.path (use __import__ trick).
>
> > Robin
>
> > On Jan 21, 10:09 am, mdipierro <[email protected]> wrote:
>
> > > Hi Bill,
>
> > > I will try to answer some of the questions you raised in the thread.
>
> > > We had an IRC meeting last week and we agreed that T2 was becoming
> > > common and people started to rely on it. At the same time maintaining
> > > web2py+T2+T3 as separate entities was becoming a nightmare. We agreed
> > > that it was possible to incorporate some parts of T2 (those that we
> > > consider good practice and those that only require python modules)
> > > into web2py.
> > > This includes:
> > > - Authentication
> > > - Role Based Authorization
> > > - Smarter Crud than SQLFORM provides (integration with authentication,
> > > more restful paths)
>
> > > The current T2 would become an example on how to extend this core, in
> > > the same fashion as you suggest.
>
> > > T3 will stay an anonymous app that based only on web2py and perhaps,
> > > once polished, it could be distributed with web2py in the future.
>
> > > About the "concept" of plugin. I agree with almost everything you say
> > > but let me insist: A PLUGIN IS AN APPLICATION. Just a special type of
> > > app. It can have modules, models, controllers, views, static files,
> > > services. It does not deserve a special folder but plugin apps need to
> > > identify themselves. I think a PLUGIN file in the app folder should do
> > > the task.
>
> > > We do need to write API specs on how to write plugins.
>
> > > For example. By having Auth provided now by web2py code, a plugin
> > > could be
>
> > > class CasAuth(Auth): ...
>
> > > which exposes the same APis as Auth but uses CAS. The plugin would
> > > also include a CAS provider app.
>
> > > Massimo
>
> > > On Jan 21, 9:19 am, billf <[email protected]> wrote:
>
> > > > RE plugins, I think the other area that could be addressed is how
> > > > web2py allows certain types of plugin to operate.
>
> > > > For example, it would be nice if web2py says "I provide for the
> > > > following types of authorisation at point x, y, and z where I will
> > > > call a function (either called a, b and c or stored in attributes d, e
> > > > and f)", i.e. the api that a "standard" authorisation plugin must
> > > > meet. That way a) anyone writing their own know what they have to
> > > > provide and b) it documents what web2py must support for backwards-
> > > > compatibility.
>
> > > > There are probably some internal areas that might benefit from a
> > > > similar api document, e.g. the "api" exposed to a view, although I
> > > > can't quite envisage it at present.
>
> > > > On Jan 21, 2:47 pm, billf <[email protected]> wrote:
>
> > > > > For now, I don't know if there is a difference between module and
> > > > > plugin but let's assume there is to keep it discreet.
>
> > > > > * a plugin folder
>
> > > > > * each plugin is a) a file or b) a folder - latter is more flexible if
> > > > > more than file required
>
> > > > > * an admin UI can display all plugins from the plugin folder
>
> > > > > * a means of stating dependency upon other plugins and conflict with
> > > > > other plugins so that the admin UI can automatically check/include/
> > > > > warn - is this by lines within the main(?) plugin file or a separate
> > > > > config/manifest/descriptor file
>
> > > > > * a means of describing the plugin - in text including syntax (same
> > > > > points as above lines or file)
>
> > > > > * I don't know the best way to actually import/include into app/
> > > > > project - any ideas?
>
> > > > > Bill
>
> > > > > On Jan 21, 2:08 pm, Timothy Farrell <[email protected]> wrote:
>
> > > > > > So the big question is...what would a plugin system look like? What
> > > > > > would you want it to control?
>
> > > > > > Currently the T2 functionality is a set of Python methods that you
> > > > > > can
> > > > > > expose and add to your app. I agree that it looks cludgy, but how
> > > > > > can
> > > > > > it be made better?
>
> > > > > > I want to keep things narrow in this discussion. So let's have an
> > > > > > example: Authentication. Let's say I have an app and I want to add
> > > > > > authentication to it (aside from Basic HTTP auth). How would a
> > > > > > plugin
> > > > > > add this functionality to my app?
>
> > > > > > -tim
>
> > > > > > billf wrote:
> > > > > > > I've been away a while so I am trying to catch up with all the new
> > > > > > > stuff. I've downloaded the version in trunk and I'm trying to
> > > > > > > get my
> > > > > > > head around it all. My first (admittedly very early) impressions
> > > > > > > are:
>
> > > > > > > 1) The functionality is nice but, personally, I don't see utils.py
> > > > > > > stuff as core web2py.
>
> > > > > > > 2) I would prefer to see a simple, well-defined, rock-solid core
> > > > > > > and
> > > > > > > everything else as a plugin. I accept that where you draw the
> > > > > > > line is
> > > > > > > totally subjective. For example , I have no problem with a
> > > > > > > mandatory
> > > > > > > 'id' and would like to see an optional
> > > > > > > 'last_modification_timestamp'
> > > > > > > included in the core. Others want neither. I have a problem with
> > > > > > > Mail, Auth and Crud in the core. I'm sure others see no problem.
>
> > > > > > > 3) Someone devise a good plugin system pleeeeeease. Or a
> > > > > > > requirements
> > > > > > > spec for one? I know; "do it yourself" :-)
>
> > > > > > > 4) There is a bug in utils.py: lines 821, 833 and 849 should all
> > > > > > > refer
> > > > > > > to self.settings. not self.setting.
>
> > > > > > > [BTW is it possible to override the redirect at the end of
> > > > > > > create(),
> > > > > > > update() and delete()? I couldn't.]
>
> > > > > > > 5) The url
> > > > > > > format:http://..../[app]/default/database/create/[app]_event
> > > > > > > ...has got to be the least elegant way of saying "I want a form
> > > > > > > to add
> > > > > > > a record to table [app]_event" you could think of. Shouldn't the
> > > > > > > goal
> > > > > > > be:http://..../[app]/default/[app]_event ?
>
> > > > > > > 6) Crud just seems a way to minimise the need to write function
> > > > > > > stubs
> > > > > > > (by enforcing action/table/id in the url) and enforcing a call to
> > > > > > > Auth
> > > > > > > if present. It's just really a pattern for a do-everything
> > > > > > > function.
>
> > > > > > > 7) I think web2py is struggling to define itself. Is it:
>
> > > > > > > - a powerful general-purpose framework (that could do with a
> > > > > > > little
> > > > > > > attention to its foundations)?
>
> > > > > > > - a cms with a long way to go?
>
> > > > > > > - some sort of app-builder app for plugins/modules with no plugin/
> > > > > > > module api/infrastructure?
>
> > > > > > > I don't think it will succeed if it tries to be more than one of
> > > > > > > the
> > > > > > > above. But maybe I'm just not aspirational enough.
>
> > > > > > > Obviously, the above is mostly personal hot air but then that's
> > > > > > > what a
> > > > > > > forum's for :-)
>
> > > > > > > Bill
>
> > > > > > > On Jan 21, 9:46 am, mdipierro <[email protected]> wrote:
>
> > > > > > >> yes but only so that you can test them and provide feedback. I
> > > > > > >> hope to
> > > > > > >> finalize the APIs and documentations within the week.
>
> > > > > > >> also I would like to change the name of the file from utils.py to
> > > > > > >> something more catchy. Any suggestion?
>
> > > > > > >> Massimo
>
> > > > > > >> On Jan 21, 1:33 am, David Marko <[email protected]> wrote:
>
> > > > > > >>> These things look very nice.
> > > > > > >>> Does it mean that described changes are available in svn trunk
> > > > > > >>> version?
>
> > > > > > >>> David
>
> > > > > > >>> On 21 Led, 00:36, mdipierro <[email protected]> wrote:
>
> > > > > > >>>> I have a preliminary version of inclusion if T2 functionality
> > > > > > >>>> into
> > > > > > >>>> web2py core. I am not yet promising backward compatibility
> > > > > > >>>> here. The
> > > > > > >>>> module name many change. For now it is in trunk as
> > > > > > >>>> gluon/utils.py
>
> > > > > > >>>> Here is how you use it (assuming [app] is you application
> > > > > > >>>> name).
>
> > > > > > >>>> 1) put this in your model
>
> > > > > > >>>> from gluon.utils import *
> > > > > > >>>> auth=Auth(globals(),db)
> > > > > > >>>> auth.define_tables()
> > > > > > >>>> crud=Crud(globals(),db)
>
> > > > > > >>>> 2) put this in your "default" controller
>
> > > > > > >>>> def user(): return dict(form=auth())
> > > > > > >>>> def database(): return dict(form=crud())
> > > > > > >>>> def download(): return response.download()
>
> > > > > > >>>> def index():
> > > > > > >>>> response.flash=T('Welcome to web2py')
> > > > > > >>>> return dict(message=T('Hello World'))
>
> > > > > > >>>> Now
> > > > > > >>>> visit:http://..../[app]/default/user/registerhttp://..../[app]/default/user/loginhttp://..../[app]/default/user/profilehttp://..../[app]/default/user/change_passwordhttp://..../[app]/default/user/groupshttp://..../[app]/default/user/logouthttp://..../[app]/default/user/retrieve_password
>
> > > > > > >>>>http://..../[app]/default/database/tableshttp://..../[app]/default/database/select/[app]_eventhttp://..../[app]/default/database/create/[app]_eventhttp://..../[app]/default/database/read/[app]_event/1http://..../[app]/default/database/update/[app]_event/1http://..../[app]/default/database/delete/[app]_event/1
>
> > > > > > >>>> now add to the model
>
> > > > > > >>>> mail=Mail()
> > > > > > >>>> mail.settings.server='smtp.whetever.com'
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---