~maddevelopers/mg5amcnlo/new_clustering

« back to all changes in this revision

Viewing changes to bin/mg5_aMC

  • Committer: Rikkert Frederix
  • Date: 2021-09-09 15:51:40 UTC
  • mfrom: (78.75.502 3.2.1)
  • Revision ID: frederix@physik.uzh.ch-20210909155140-rg6umfq68h6h47cf
merge with 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
 
1
#! /usr/bin/env python3
 
2
from __future__ import absolute_import
 
3
from __future__ import print_function
2
4
import time
3
5
start = time.time()
4
6
 
20
22
and call immediately the command line interface scripts"""
21
23
 
22
24
import sys
23
 
if not sys.version_info[0] == 2 or sys.version_info[1] < 6:
24
 
    sys.exit('MadGraph5_aMC@NLO works only with python 2.6 or later (but not python 3.X).\n\
25
 
               Please upgrate your version of python.')
 
25
if  sys.version_info[1] < 7:
 
26
    if sys.version_info[0] == 2:
 
27
        sys.exit("MadGraph5_aMC@NLO works only with python 2.7 or python 3.7 (and later).\n"+\
 
28
              "  You are currently using Python2.%s. Please use a more recent version of Python." % sys.version_info[1])
 
29
    if sys.version_info[0] == 3:
 
30
        sys.exit("MadGraph5_aMC@NLO works only with python 2.7 or python 3.7 (and later).\n"+\
 
31
              "  You are currently using Python 3.%i. So please upgrade your version of Python." % sys.version_info[1] +\
 
32
              "  If you have python2.7 installed you need to run the code as\n"+\
 
33
              "      python27 ./bin/mg5_aMC \n")
 
34
 
 
35
try:
 
36
    import six
 
37
except ImportError:
 
38
    message = 'madgraph requires the six module. The easiest way to install it is to run "pip%s install six --user"\n' % (sys.version_info[0] if sys.version_info[0]==3 else '')
 
39
    message += 'in case of problem with pip, you can download the file at https://pypi.org/project/six/ . It has a single python file that you just need to put inside a directory of your $PYTHONPATH environment variable.'
 
40
    sys.exit(message)
26
41
 
27
42
import os
28
43
import optparse
49
64
                 help='force to launch debug mode')
50
65
parser.add_option("-m", "--mode", dest="plugin",
51
66
                  help="Define some additional command provide by a PLUGIN")
52
 
                               
 
67
parser.add_option("-s", "--nocaffeinate", action="store_false", default=True, dest='nosleep',
 
68
                  help='For mac user, forbids to use caffeinate when running with a script')                               
53
69
(options, args) = parser.parse_args()
54
70
if len(args) == 0:
55
71
    args = ''
66
82
import logging.config
67
83
import madgraph.interface.coloring_logging
68
84
 
 
85
if sys.version_info[0] ==2:
 
86
    logging.warning("\033[91mpython2 support will be removed in last quarter 2021. If you use python2 due to issue with Python3, please report them on https://bugs.launchpad.net/mg5amcnlo\033[0m")
 
87
 
 
88
 
 
89
if ' ' in os.getcwd():
 
90
    logging.warning("\033[91mPath does contains spaces. We advise that you change your current path to avoid to have space in the path.\033[0m")
 
91
 
69
92
try: 
70
93
    import readline
71
94
except ImportError:
125
148
import madgraph.interface.master_interface as interface
126
149
 
127
150
if __debug__ and time.time() - start > 0.5:
128
 
    print( 'WARNING: loading of madgraph too slow!!!', time.time() - start)
 
151
    print(( 'WARNING: loading of madgraph too slow!!!', time.time() - start))
129
152
 
130
153
try:
131
154
    import madgraph.various.misc as misc
157
180
# Call the cmd interface main loop
158
181
try:
159
182
    if options.file or args:
 
183
        if sys.platform == "darwin" and options.nosleep:
 
184
            logging.getLogger('madgraph').warning("launching caffeinate to prevent idle sleep when MG5aMC is running. Run './bin/mg5_aMC -s' to prevent this.")
 
185
            pid = os.getpid()
 
186
            subprocess.Popen(['caffeinate', '-i', '-w', str(pid)])
160
187
        # They are an input file 
161
188
        if args:
162
189
            input_file = os.path.realpath(args[0])
176
203
    else:
177
204
        # Interactive mode
178
205
        if options.web:
179
 
            if not os.environ.has_key('MADGRAPH_DATA'):
 
206
            if 'MADGRAPH_DATA' not in os.environ:
180
207
                os.environ['MADGRAPH_DATA'] = root_path
181
208
                os.environ['MADGRAPH_BASE'] = os.path.join(root_path,'input')
182
209
                os.environ['REMOTE_USER'] = 'webmode'
184
211
        else:
185
212
            cmd_line.cmdloop()
186
213
except KeyboardInterrupt:
187
 
    print 'writting history and quit on KeyboardInterrupt' 
 
214
    print('writting history and quit on KeyboardInterrupt') 
188
215
    pass
189
216
 
190
217
try:
193
220
    if not os.path.exists(os.path.join(os.environ['HOME'], '.mg5')):
194
221
        os.mkdir(os.path.join(os.environ['HOME'], '.mg5'))
195
222
    readline.write_history_file(history_file)
196
 
except Exception, error:
 
223
except Exception as error:
197
224
    pass
198
225
 
199
226