~maddevelopers/mg5amcnlo/2.6.3_rwgt

« back to all changes in this revision

Viewing changes to models/__init__.py

  • Committer: olivier-mattelaer
  • Date: 2018-04-29 08:10:16 UTC
  • mfrom: (275.1.80 2.6.2)
  • Revision ID: olivier-mattelaer-20180429081016-9nmfvn1er0zjb23o
pass to 2.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
import sys
 
19
import madgraph.various.misc as misc
19
20
 
20
21
def load_model(name, decay=False):
21
22
    
24
25
        name = name[:-1]
25
26
    
26
27
 
 
28
 
27
29
    path_split = name.split(os.sep)
28
30
    if len(path_split) == 1:
29
 
        model_pos = 'models.%s' % name
30
 
        __import__(model_pos)
31
 
        return sys.modules[model_pos]
 
31
        try:
 
32
            model_pos = 'models.%s' % name
 
33
            __import__(model_pos)
 
34
            return sys.modules[model_pos]
 
35
        except Exception:
 
36
            pass
 
37
        for p in os.environ['PYTHONPATH']:
 
38
            new_name = os.path.join(p, name)
 
39
            try:
 
40
                return load_model(new_name, decay)
 
41
            except Exception:
 
42
                pass
32
43
    elif path_split[-1] in sys.modules:
33
44
        model_path = os.path.realpath(os.sep.join(path_split))
34
45
        sys_path = os.path.realpath(os.path.dirname(sys.modules[path_split[-1]].__file__))
36
47
            raise Exception, 'name %s already consider as a python library cann\'t be reassigned(%s!=%s)' % \
37
48
                (path_split[-1], model_path, sys_path) 
38
49
 
39
 
    sys.path.insert(0, os.sep.join(path_split[:-1]))
40
 
    __import__(path_split[-1])
 
50
    with misc.TMP_variable(sys, 'path', [os.sep.join(path_split[:-1])]):
 
51
        __import__(path_split[-1])
41
52
    output = sys.modules[path_split[-1]]
42
53
    if decay:
43
54
        dec_name = '%s.decays' % path_split[-1]
47
58
            pass
48
59
        else:
49
60
            output.all_decays = sys.modules[dec_name].all_decays
50
 
    
51
 
    sys.path.pop(0)
52
 
    
53
 
    
54
 
    
 
61
        
55
62
    return sys.modules[path_split[-1]]