bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.43k stars 1.47k forks source link

Adding "merge" method to the module level #645

Open mallochine opened 10 years ago

mallochine commented 10 years ago

Right now, "merge" exists only if you have an instance, e.g. "root = Bottle(); root.merge(...)"

Sometimes, you don't have a instance. Instead, you'd like to merge another module's app into the root module.

This is the case at the company I'm currently working for. The ideal solution would be to have "bottle.merge(...)", but we currently hvae the following workaround:

import some_module.webservices

# Add routes from some_module.webservices.
for r in some_module.webservices.app.routes:
  route(r.rule, r.method, r.callback)
mallochine commented 10 years ago

I could submit code for this issue, if someone would greenlight me to do so.

blakev commented 10 years ago

If you don't have an instance of the root application, wouldn't it make more sense to create an application and merge your root into that as the new root?

bottle.merge(...) doesn't make sense because you're not, technically, merging two applications together, you're bootstrapping them into the same space.

mallochine commented 10 years ago

Yes, bootstrapping them into the same space is exactly what's being attempted. And yes, it would make more sense to have a root instance, instead of a root app. On the other hand, the codebase I'm working with has a large root application, so appending "root." to everything is 1) tedious, and 2) hard to test.

It took just 2 lines of code to bootstrap another app into the same space. I think that would be the preferred way of bootstrapping two apps into the same space.

eric-wieser commented 9 years ago

What about the existing default_app().merge?