Cross-Project code sharing...modules/plugins in Cherrypy?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2

Hello all,

I am new to the Python web-programming world and trying to decide on
frameworks.  I have been looking at Cherrypy for some time.  However,
I have run across a show stopper for me unless I
have missed something in the documentation.  Does Cherrypy support
some kind of module/plugin architecture that will allow me to develop
"plug-in" functionality across projects?  What would be called in
Django an "app".

For example, I would like to have a "news", "blog", and "calendar"
module that I can plug into different applications.  The goal is to
have everything for the module contained in one subdirectory including
any configuration, routing, templates, controllers, model, etc.  So,
something like this:

/modules/news/...
/modules/calendar/...
/modules/blog/...

Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Łukasz Michalski
rcs_comp pisze:

> Hello all,
>
> I am new to the Python web-programming world and trying to decide on
> frameworks.  I have been looking at Cherrypy for some time.  However,
> I have run across a show stopper for me unless I
> have missed something in the documentation.  Does Cherrypy support
> some kind of module/plugin architecture that will allow me to develop
> "plug-in" functionality across projects?  What would be called in
> Django an "app".
>
I am new too, but maybe this would help you:
http://www.cherrypy.org/wiki/WSGIServeMulipleApplications

You can also attach module to url with similar untested code:

blog.py file:
-------------------------
class Blog:
     @cherrypy.expose
     def index(self):
         return "I'am Blog"

forum.py file:
-------------------------
class Forum:
     @cherrypy.expose
     def index(self):
         return "I'am Forum"


root.py file:
-------------------------
import cherrypy
from blog import Blog
from forum import Forum

class Root:
     #you can automate this some way...
     blog = Blog()
     forum = Forum()

     @cherrypy.expose
     def index(self):
         return "I'am root"

cherrypy.quickstart(Root())

This way under http://localhost:8080/blog/ you have blog plugin and
http://localhost:8080/forum/ you have forum plugin.

Regards,
Łukasz


signature.asc (266 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Sylvain Hellegouarch


> rcs_comp pisze:
>> Hello all,
>>
>> I am new to the Python web-programming world and trying to decide on
>> frameworks.  I have been looking at Cherrypy for some time.  However,
>> I have run across a show stopper for me unless I
>> have missed something in the documentation.  Does Cherrypy support
>> some kind of module/plugin architecture that will allow me to develop
>> "plug-in" functionality across projects?  What would be called in
>> Django an "app".
>>
>
> I am new too, but maybe this would help you:
> http://www.cherrypy.org/wiki/WSGIServeMulipleApplications
>
> You can also attach module to url with similar untested code:
>
> blog.py file:
> -------------------------
> class Blog:
>      @cherrypy.expose
>      def index(self):
>          return "I'am Blog"
>
> forum.py file:
> -------------------------
> class Forum:
>      @cherrypy.expose
>      def index(self):
>          return "I'am Forum"
>
>
> root.py file:
> -------------------------
> import cherrypy
> from blog import Blog
> from forum import Forum
>
> class Root:
>      #you can automate this some way...
>      blog = Blog()
>      forum = Forum()
>
>      @cherrypy.expose
>      def index(self):
>          return "I'am root"
>
> cherrypy.quickstart(Root())
>
> This way under http://localhost:8080/blog/ you have blog plugin and
> http://localhost:8080/forum/ you have forum plugin.
>

More generally speaking, applications mounted on a CherryPy engine using
cherrypy.tree.mount(app, script_name, config) do not leak on each other.

import cherrypy
from blog import Blog
from forum import Forum

class Root:
      @cherrypy.expose
      def index(self):
          return "I'am root"

cherrypy.tree.mount(Blog(), '/blog')
cherrypy.tree.mount(Forum(), '/forum')
cherrypy.quickstart(Root())

The main difference here is that each mounted application is independent
from the others.

- Sylvain

--
Sylvain Hellegouarch
http://www.defuze.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2
In reply to this post by Łukasz Michalski



On Jun 4, 11:10 am, Lukasz Michalski <[hidden email]> wrote:

> I am new too, but maybe this would help you:http://www.cherrypy.org/wiki/WSGIServeMulipleApplications
>
> You can also attach module to url with similar untested code:

Thanks for the response.  However, multiple applications seems like a
lot of unnecessary duplication.  Furthermore, I can easily have
upwards of 10 modules for any given application.  I don't think
multiple apps would work for me unless I am missing something.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Sylvain Hellegouarch


> On Jun 4, 11:10 am, Lukasz Michalski <[hidden email]> wrote:
>
>> I am new too, but maybe this would help
>> you:http://www.cherrypy.org/wiki/WSGIServeMulipleApplications
>>
>> You can also attach module to url with similar untested code:
>
> Thanks for the response.  However, multiple applications seems like a
> lot of unnecessary duplication.  Furthermore, I can easily have
> upwards of 10 modules for any given application.  I don't think
> multiple apps would work for me unless I am missing something.

Maybe should you explain more what you really want to do :)

- Sylvain

--
Sylvain Hellegouarch
http://www.defuze.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2
In reply to this post by Sylvain Hellegouarch



On Jun 4, 11:16 am, "Sylvain Hellegouarch" <[hidden email]> wrote:

> The main difference here is that each mounted application is independent
> from the others.

Right, but what I am looking for is "components" of an application
that are going to work together in the application.  Sometimes they
can even be dependent on each other.  I am coming from a PHP
background, so maybe I am just thinking about this wrong.  But if I
build a "users" module that has the DB definitions, templates, forms,
views, etc. all together I want to be able to re-use that in multiple
applications without a lot of hoop jumping.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2
In reply to this post by Sylvain Hellegouarch



On Jun 4, 11:20 am, "Sylvain Hellegouarch" <[hidden email]> wrote:

>
> Maybe should you explain more what you really want to do :)


Ok, good point.

Application Level:
 * define Cherrypy settings (DB connections, etc.)
 * have a main view that will be used throughout the site (i.e. a
decorator(s) that will wrap all output)
 * define application level custom settings (like administrators email
address, application name, etc.)

Users Module:
 * "plugs in" to the application
 * has forms / controller / views / model fully encapsulated in the
module
 * has login form / logout feature
 * has administrative backend for add/edit/delete of users

News Module
 * "plugs in" to the application
 * has forms / controller / views / model fully encapsulated in the
module
 * has controllers for displaying news headlines and articles
 * has administrative backend for add/edit/delete of news
 * Is dependent on the Users module for user authentication for its
administrative backend

Does that help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2
In reply to this post by Sylvain Hellegouarch



On Jun 4, 11:20 am, "Sylvain Hellegouarch" <[hidden email]> wrote:
> Maybe should you explain more what you really want to do :)

Here is a good way to conceptualize it:

Projects vs. apps/modules

What’s the difference between a project and an app/module? An app/
module is a Web application that does something — e.g., a weblog
system, a database of public records or a simple poll app/module. A
project is a collection of configuration and apps/modules for a
particular Web site. A project can contain multiple apps/modules. An
app/module can be in multiple projects.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Tim Roberts
In reply to this post by Randy Syring-2
rcs_comp wrote:
On Jun 4, 11:16 am, "Sylvain Hellegouarch" [hidden email] wrote:
  
The main difference here is that each mounted application is independent
from the others.
    

Right, but what I am looking for is "components" of an application
that are going to work together in the application.  Sometimes they
can even be dependent on each other.  I am coming from a PHP
background, so maybe I am just thinking about this wrong.

Maybe, but you may just be overthinking it.  The concepts aren't all that different.  In PHP, you would do this by something like this:
    include( "../modules/news.php" );
    include( "../modules/users.php" );
Then, all the classes in those files are available to your PHP code.

In Python, you would use something like:
    from modules.news import News
    from modules.users import Users

Same fundamental concept.

But if I
build a "users" module that has the DB definitions, templates, forms,
views, etc. all together I want to be able to re-use that in multiple
applications without a lot of hoop jumping.
  

Right.  There shouldn't have to be a lot of hoop jumping.  Module reuse is a key feature of Python.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Randy Syring-2

On Jun 4, 12:58 pm, Tim Roberts <[hidden email]> wrote:

>
> Maybe, but you may just be overthinking it.  The concepts aren't all
> that different.  In PHP, you would do this by something like this:
>     include( "../modules/news.php" );
>     include( "../modules/users.php" );
> Then, all the classes in those files are available to your PHP code.
>
> In Python, you would use something like:
>     from modules.news import News
>     from modules.users import Users
>
> Same fundamental concept.


Thank you for the response.  Would you happen to know of an example
project built with Cherrypy that would do something like this that I
could tear apart?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Cross-Project code sharing...modules/plugins in Cherrypy?

Tim Roberts
rcs_comp wrote:
On Jun 4, 12:58 pm, Tim Roberts [hidden email] wrote:

  
Maybe, but you may just be overthinking it.  The concepts aren't all
that different.  In PHP, you would do this by something like this:
    include( "../modules/news.php" );
    include( "../modules/users.php" );
Then, all the classes in those files are available to your PHP code.

In Python, you would use something like:
    from modules.news import News
    from modules.users import Users

Same fundamental concept.
    


Thank you for the response.  Would you happen to know of an example
project built with Cherrypy that would do something like this that I
could tear apart

I'm going to let others respond to that.  I have experience with Python CGI solutions that do this kind of thing (like the pyblosxom blog engine), but I just haven't seen enough CherryPy projects to have built up an inventory.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---