Browse Source

Enables more verbose messages for module overwriting

Yann Weber 8 years ago
parent
commit
0f6efd899a
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      lodel/context.py

+ 13
- 4
lodel/context.py View File

70
     
70
     
71
     def find_spec(fullname, path, target = None):
71
     def find_spec(fullname, path, target = None):
72
         if fullname.startswith(CTX_PKG):
72
         if fullname.startswith(CTX_PKG):
73
-            #print("find_spec called : fullname=%s path=%s target=%s" % (
74
-            #    fullname, path, target))
75
             spl = fullname.split('.')
73
             spl = fullname.split('.')
76
             site_identifier = spl[1]
74
             site_identifier = spl[1]
77
             #creating a symlink to represent the lodel site package
75
             #creating a symlink to represent the lodel site package
332
     #@note designed to implements warning messages or stuff like that
330
     #@note designed to implements warning messages or stuff like that
333
     #when doing nasty stuff
331
     #when doing nasty stuff
334
     #
332
     #
333
+    #@warning Logging stuffs may lead in a performance issue
334
+    #
335
     #@todo try to use the logger module instead of warnings
335
     #@todo try to use the logger module instead of warnings
336
     #@param globs globals : the globals where we want to expose our
336
     #@param globs globals : the globals where we want to expose our
337
     #module alias
337
     #module alias
340
     @staticmethod
340
     @staticmethod
341
     def safe_exposure(globs, obj, alias):
341
     def safe_exposure(globs, obj, alias):
342
         if alias in globs:
342
         if alias in globs:
343
-            warnings.warn("A module exposure leads in globals overwriting for \
344
-key '%s'" % alias)
343
+            if globs[alias] != obj:
344
+                print("Context '%s' : A module exposure leads in globals overwriting for \
345
+key '%s' with a different value : %s != %s" % (LodelContext.get_name(), alias, globs[alias], obj))
346
+                """#Uncomment this bloc to display a stack trace for dangerous modules overwriting
347
+                print("DEBUG INFOS : ")
348
+                import traceback
349
+                traceback.print_stack()
350
+                """
351
+            else:
352
+                print("Context '%s' : A module exposure leads in a useless replacement for \
353
+key '%s'" % (LodelContext.get_name(),alias))
345
         globs[alias] = obj
354
         globs[alias] = obj
346
         
355
         
347
     ##@brief Create a context from a path and returns the context name
356
     ##@brief Create a context from a path and returns the context name

Loading…
Cancel
Save