From b985c7302f387948f6d4ddd5ba7b02861c747885 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Mon, 18 Feb 2013 17:48:39 +0100 Subject: [PATCH] [FIX] openerp namespace: the import hook was still inserting modules in sys.moduls at their shortname. bzr revid: vmt@openerp.com-20130218164839-2qludhn3znpdftq5 --- openerp/modules/module.py | 56 --------------------------------------- openerp/service/cron.py | 6 +---- 2 files changed, 1 insertion(+), 61 deletions(-) diff --git a/openerp/modules/module.py b/openerp/modules/module.py index 9f716099b56..e71c1f1c519 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -62,23 +62,6 @@ class AddonsImportHook(object): backward compatibility, `import ` is still supported. Now they are living in `openerp.addons`. The good way to import such modules is thus `import openerp.addons.module`. - - For backward compatibility, loading an addons puts it in `sys.modules` - under both the legacy (short) name, and the new (longer) name. This - ensures that - import hr - import openerp.addons.hr - loads the hr addons only once. - - When an OpenERP addons name clashes with some other installed Python - module (for instance this is the case of the `resource` addons), - obtaining the OpenERP addons is only possible with the long name. The - short name will give the expected Python module. - - Instead of relying on some addons path, an alternative approach would be - to use pkg_resources entry points from already installed Python libraries - (and install our addons as such). Even when implemented, we would still - have to support the addons path approach for backward compatibility. """ def find_module(self, module_name, package_path): @@ -86,25 +69,6 @@ class AddonsImportHook(object): if len(module_parts) == 3 and module_name.startswith('openerp.addons.'): return self # We act as a loader too. - # TODO list of loadable modules can be cached instead of always - # calling get_module_path(). - if len(module_parts) == 1 and \ - get_module_path(module_parts[0], - display_warning=False): - try: - # Check if the bare module name clashes with another module. - f, path, descr = imp.find_module(module_parts[0]) - _logger.warning(""" -Ambiguous import: the OpenERP module `%s` is shadowed by another -module (available at %s). -To import it, use `import openerp.addons..`.""" % (module_name, path)) - return - except ImportError, e: - # Using `import ` instead of - # `import openerp.addons.` is ugly but not harmful - # and kept for backward compatibility. - return self # We act as a loader too. - def load_module(self, module_name): module_parts = module_name.split('.') @@ -113,29 +77,9 @@ To import it, use `import openerp.addons..`.""" % (module_name, path)) if module_name in sys.modules: return sys.modules[module_name] - if len(module_parts) == 1: - module_part = module_parts[0] - if module_part in sys.modules: - return sys.modules[module_part] - - try: - # Check if the bare module name shadows another module. - f, path, descr = imp.find_module(module_part) - is_shadowing = True - except ImportError, e: - # Using `import ` instead of - # `import openerp.addons.` is ugly but not harmful - # and kept for backward compatibility. - is_shadowing = False - # Note: we don't support circular import. f, path, descr = imp.find_module(module_part, ad_paths) mod = imp.load_module('openerp.addons.' + module_part, f, path, descr) - if not is_shadowing: - sys.modules[module_part] = mod - for k in sys.modules.keys(): - if k.startswith('openerp.addons.' + module_part): - sys.modules[k[len('openerp.addons.'):]] = sys.modules[k] sys.modules['openerp.addons.' + module_part] = mod return mod diff --git a/openerp/service/cron.py b/openerp/service/cron.py index f3c81fe785f..3155ed4259b 100644 --- a/openerp/service/cron.py +++ b/openerp/service/cron.py @@ -44,11 +44,7 @@ def cron_runner(number): _logger.debug('cron%d polling for jobs', number) for db_name, registry in registries.items(): while True and registry.ready: - # acquired = openerp.addons.base.ir.ir_cron.ir_cron._acquire_job(db_name) - # TODO why isnt openerp.addons.base defined ? - import sys - base = sys.modules['addons.base'] - acquired = base.ir.ir_cron.ir_cron._acquire_job(db_name) + acquired = openerp.addons.base.ir.ir_cron.ir_cron._acquire_job(db_name) if not acquired: break