Package: dirty-loader
dirty-loaderEasy to use loader library.ChangelogVersion 0.2.2Simplified code.Added BaseFactory methods to load items from list or dictionaries.Version 0.2.1Three types of instance definition allowed: string, structured and structure simplified.Version 0.2.0Custom factories for classes.Default factories for logging package.Version 0.1.0Some refactors.New functionimport_class.Instalation$pipinstalldirty-loaderDocumentationhttp://dirty-loader.readthedocs.ioMain loadersLoaderWith Loader you could register sorted python modules. When you ask for a class
it will try to load it for each module until it find one.Example:fromdirty_loaderimportLoaderloader=Loader()loader.register_module('tests.fake.namespace1')loader.register_module('tests.fake.namespace2')loader.register_module('tests.fake.namespace3')klass=loader.load_class('FakeClass1')fromtests.fake.namespace1importFakeClass1assertklass==FakeClass1# klass is tests.fake.namespace1.FakeClass1 because it exists in first module registered.# Also, you could get an instance of class using factoryobj=loader.factory('FakeClass1',var1='a',var2=2)# You could load classes from packages inside modules registeredklass=loader.load_class('subnamespace.FakeClass1')fromtests.fake.namespace3.subnamespaceimportFakeClass1asSubFakeClass1assertklass==SubFakeClass1# klass is tests.fake.namespace3.subnamespace.FakeClass1 because it exists in first module registered.LoaderReversedIt works in same way of Loader but it revers the sort when try to load a class.Example:fromdirty_loaderimportLoaderReversedloader=LoaderReversed()loader.register_module('tests.fake.namespace1')loader.register_module('tests.fake.namespace2')klass=loader.load_class('FakeClass1')fromtests.fake.namespace2importFakeClass1assertklass==FakeClass1# klass is tests.fake.namespace2.FakeClass1 because it exists in last module registered.LoaderNamespaceWith LoaderNamespace you could register sorted namespaces. When you ask for a class
it will try to load it for each namespace until it find one. Each namespace has a python
module associated. You could use the regular Loader way to load a class or you could
specify the namespace you would like to use.Example:fromdirty_loaderimportLoaderNamespaceloader=LoaderNamespace()loader.register_namespace('fake1','tests.fake.namespace1')loader.register_namespace('fake2','tests.fake.namespace2')fromtests.fake.namespace1importFakeClass1,FakeClass2,FakeClass3klass=loader.load_class('FakeClass1')fromtests.fake.namespace1importFakeClass1assertklass==FakeClass1# klass is tests.fake.namespace1.FakeClass1 because it exists in last module registered.# Also, you could get a class from specific namespaceklass=loader.load_class('FakeClass1',namespace='fake2)fromtests.fake.namespace2importFakeClass1assertklass==FakeClass1# klass is tests.fake.namespace2.FakeClass1 because you specified it.# Namespace could be specified in string class, tooklass=loader.load_class('fake2:FakeClass1')assertklass==FakeClass1# klass is tests.fake.namespace2.FakeClass1 because you specified it.LoaderNamespaceReversedIt works in same way of LoaderNamespace but it revers the sort when try to load a class.LoaderCachedA version of Loader with cache.LoaderReversedCachedA version of LoaderReversed with cache.LoaderNamespaceCachedA version of LoaderNamespace with cache.LoaderNamespaceReversedCachedA version of LoaderNamespaceReversed with cache.