Merge lp:~openerp-dev/openobject-server/7.0-import-non-local-warning-mat into lp:openobject-server/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-import-non-local-warning-mat
Merge into: lp:openobject-server/7.0
Diff against target: 45 lines (+11/-2)
2 files modified
openerp/service/workers.py (+2/-1)
openerp/tools/misc.py (+9/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-import-non-local-warning-mat
Reviewer Review Type Date Requested Status
Lionel Sausin - Initiatives/Numérigraphe (community) Needs Information
OpenERP Core Team Pending
Review via email: mp+210399@code.launchpad.net

Description of the change

Avoiding to get the warning message when importing the python module 'resource'.

Way to reproduce:
- launch openerp with --workers=1
-> get WARNING ? openerp.modules.module:
Ambiguous import: the OpenERP module `resource` is shadowed by another
module (available at /usr/lib/python2.7/lib-dynload/resource.so).
To import it, use `import openerp.addons.<module>.`.

Probably a bit overkill, not sure we should merge that...

Another way would be to simply reduce the log level to 'debug'

To post a comment you must log in.
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Why would import openerp.addons.resource not work ?

review: Needs Information
Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

What do you mean by "not work". As far as I know, it currently works fine, just displaying a non-harmful message. My patch gives you a way to remove this warning in the workers.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Yes sorry, I mean would it not remove the warning too?

Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

This would mean than, when importing resource, meaning <the python resource module>, you can use the code:

import openerp.tools.misc as misc
resource = misc.import_non_local('resource')

And it will have the same effect without showing warning message.
When you want to import the openerp module, you still need to use the `import openerp.addons.resource` syntax

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Ok I get it now, thanks.

Unmerged revisions

5257. By Martin Trigaux (OpenERP)

[IMP] import resource (python module) in a way we avoid triggering the warning (name clash with module resource)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/service/workers.py'
2--- openerp/service/workers.py 2013-07-24 08:34:54 +0000
3+++ openerp/service/workers.py 2014-03-11 13:26:39 +0000
4@@ -8,7 +8,6 @@
5 import os
6 import psutil
7 import random
8-import resource
9 import select
10 import signal
11 import socket
12@@ -23,6 +22,8 @@
13
14 import openerp
15 import openerp.tools.config as config
16+import openerp.tools.misc as misc
17+resource = misc.import_non_local('resource')
18
19 _logger = logging.getLogger(__name__)
20
21
22=== modified file 'openerp/tools/misc.py'
23--- openerp/tools/misc.py 2013-11-25 08:42:15 +0000
24+++ openerp/tools/misc.py 2014-03-11 13:26:39 +0000
25@@ -30,6 +30,7 @@
26 import cProfile
27 import subprocess
28 import logging
29+import imp
30 import os
31 import socket
32 import sys
33@@ -1095,4 +1096,11 @@
34
35 return [x for i, x in enumerate(args) if not strip(args, i)]
36
37-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
38+def import_non_local(name, custom_name=None):
39+ custom_name = custom_name or name
40+
41+ f, pathname, desc = imp.find_module(name, sys.path[1:])
42+ module = imp.load_module(custom_name, f, pathname, desc)
43+ f.close()
44+
45+ return module