~maddevelopers/mg5amcnlo/2.6.6_py3

« back to all changes in this revision

Viewing changes to models/__init__.py

  • Committer: olivier-mattelaer
  • Date: 2019-07-27 21:18:13 UTC
  • Revision ID: olivier-mattelaer-20190727211813-58cdnat0ii160fx5
change in the way model are imported (looks like they are still some side effects)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import sys
20
20
import madgraph.various.misc as misc
 
21
from madgraph import MG5DIR
 
22
pjoin = os.path.join
21
23
 
22
24
def load_model(name, decay=False):
23
25
    
30
32
    path_split = name.split(os.sep)
31
33
    if len(path_split) == 1:
32
34
        try:
33
 
            model_pos = 'models.%s' % name
34
 
            __import__(model_pos)
 
35
            with misc.TMP_variable(sys, 'path', [pjoin(MG5DIR, 'models'), pjoin(MG5DIR, 'models', name)]):  
 
36
                model_pos = 'models.%s' % name
 
37
                __import__(model_pos)
35
38
            return sys.modules[model_pos]
36
 
        except Exception:
 
39
        except Exception as error:
37
40
            pass
38
41
        for p in os.environ['PYTHONPATH']:
39
42
            new_name = os.path.join(p, name)
41
44
                return load_model(new_name, decay)
42
45
            except Exception:
43
46
                pass
 
47
            except ImportError:
 
48
                pass
44
49
    elif path_split[-1] in sys.modules:
45
50
        model_path = os.path.realpath(os.sep.join(path_split))
46
51
        sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__))
49
54
                (path_split[-1], model_path, sys_path)) 
50
55
 
51
56
    # remove any link to previous model
52
 
    for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card']:
 
57
    for name in ['particles', 'object_library', 'couplings', 'function_library', 'lorentz', 'parameters', 'vertices', 'coupling_orders', 'write_param_card',
 
58
                 'CT_couplings', 'CT_vertices', 'CT_parameters']:
53
59
        try:
54
60
            del sys.modules[name]
55
61
        except Exception: