Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Refactor Hooks/Handlers into CementApp #311
Every time I instantiate a new cement application, it cleans
from cement.core.foundation import CementApp from cement.core.interface import Interface from cement.core import handler from cement.core import backend class MyInterface(Interface): class IMeta: label = 'myinterface' app1 = CementApp('app1') handler.define(MyInterface) app2 = CementApp('app2') print(MyInterface.IMeta.label in backend.__handlers__)
False will be printed. Quite unexpectedly.
This was an early design choice, but was intentional. It obviously did not account for a use case of running multiple unique Cement apps simultaneously.
The reasoning for putting this code in
Open to discussing alternative means of course, but the goal of extensions was to keep them application agnostic.
@derks thanks for the explanation, but as I can see from foundation.py#L961 and built-in extensions, they all use
You are completely right! What was I thinking.... haha. Passing
I will definitely put some time in to testing that out, if all works and no major test breakage should be able to make that into stable/2.8.
Actually, I'm working on refactoring these globals into the app object - I can create a PR if you want.
Won't know entirely until I really start digging unfortunately. Extensions/Plugins/Etc I think are easy as it would become
Long story short... depending on how much breakage there is, yeah it might end up in 3.0, but thankfully I plan on starting on that relatively soon-ish also.
changed the title from
cement.core.backend globals are useless
Refactor Hooks/Handlers into CementApp
Jun 23, 2015
added a commit
Feb 7, 2016
@malinoff I know I've been silent on this for a while, primarily because I felt these changes were too major for Cement 2.x.x. That said, I had an epiphony today on how to implement it quietly without any backward compatibility issues.
I've pushed a new branch at
from cement.core.foundation import CementApp from cement.core.interface import Interface class MyInterface(Interface): class IMeta: label = 'myinterface' # create first app and define handler/hooks app1 = CementApp('app1', use_backend_globals=False) app1.handler.define(MyInterface) app1.hook.define('my_test_hook') # create a second app app2 = CementApp('app2', use_backend_globals=False) # run app1 app1.setup() app1.run() app1.log.info("Running App1") app1.log.info("MyInterface Defined? %s" % app1.handler.defined('myinterface')) app2.setup() app2.run() app2.log.info("Running App2") app2.log.info("MyInterface Defined? %s" % app2.handler.defined('myinterface'))
Moving forward, I'll be updating all the documentation to reference using
Cement 3 will drop the deprecated bits and will no longer support the backend globals at all.