##// END OF EJS Templates
Fix importing execfile from toollib on Python 2
Thomas Kluyver -
Show More
@@ -1,66 +1,66 b''
1 """Various utilities common to IPython release and maintenance tools.
1 """Various utilities common to IPython release and maintenance tools.
2 """
2 """
3 from __future__ import print_function
3 from __future__ import print_function
4
4
5 # Library imports
5 # Library imports
6 import os
6 import os
7
7
8 # Useful shorthands
8 # Useful shorthands
9 pjoin = os.path.join
9 pjoin = os.path.join
10 cd = os.chdir
10 cd = os.chdir
11
11
12 # Constants
12 # Constants
13
13
14 # SSH root address of the archive site
14 # SSH root address of the archive site
15 archive_user = 'ipython@archive.ipython.org'
15 archive_user = 'ipython@archive.ipython.org'
16 archive_dir = 'archive.ipython.org'
16 archive_dir = 'archive.ipython.org'
17 archive = '%s:%s' % (archive_user, archive_dir)
17 archive = '%s:%s' % (archive_user, archive_dir)
18
18
19 # Build commands
19 # Build commands
20 # Source dists
20 # Source dists
21 sdists = './setup.py sdist --formats=gztar,zip'
21 sdists = './setup.py sdist --formats=gztar,zip'
22 # Binary dists
22 # Binary dists
23 def buildwheels():
23 def buildwheels():
24 for py in ('2', '3'):
24 for py in ('2', '3'):
25 sh('python%s setupegg.py bdist_wheel' % py)
25 sh('python%s setupegg.py bdist_wheel' % py)
26
26
27 # Utility functions
27 # Utility functions
28 def sh(cmd):
28 def sh(cmd):
29 """Run system command in shell, raise SystemExit if it returns an error."""
29 """Run system command in shell, raise SystemExit if it returns an error."""
30 print("$", cmd)
30 print("$", cmd)
31 stat = os.system(cmd)
31 stat = os.system(cmd)
32 #stat = 0 # Uncomment this and comment previous to run in debug mode
32 #stat = 0 # Uncomment this and comment previous to run in debug mode
33 if stat:
33 if stat:
34 raise SystemExit("Command %s failed with code: %s" % (cmd, stat))
34 raise SystemExit("Command %s failed with code: %s" % (cmd, stat))
35
35
36 # Backwards compatibility
36 # Backwards compatibility
37 c = sh
37 c = sh
38
38
39 def get_ipdir():
39 def get_ipdir():
40 """Get IPython directory from command line, or assume it's the one above."""
40 """Get IPython directory from command line, or assume it's the one above."""
41
41
42 # Initialize arguments and check location
42 # Initialize arguments and check location
43 ipdir = pjoin(os.path.dirname(__file__), os.pardir)
43 ipdir = pjoin(os.path.dirname(__file__), os.pardir)
44
44
45 ipdir = os.path.abspath(ipdir)
45 ipdir = os.path.abspath(ipdir)
46
46
47 cd(ipdir)
47 cd(ipdir)
48 if not os.path.isdir('IPython') and os.path.isfile('setup.py'):
48 if not os.path.isdir('IPython') and os.path.isfile('setup.py'):
49 raise SystemExit('Invalid ipython directory: %s' % ipdir)
49 raise SystemExit('Invalid ipython directory: %s' % ipdir)
50 return ipdir
50 return ipdir
51
51
52
52
53 def compile_tree(folder='.'):
53 def compile_tree(folder='.'):
54 """Compile all Python files below current directory."""
54 """Compile all Python files below current directory."""
55 stat = os.system('python -m compileall {}'.format(folder))
55 stat = os.system('python -m compileall {}'.format(folder))
56 if stat:
56 if stat:
57 msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n'
57 msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n'
58 msg += 'See messages above for the actual file that produced it.\n'
58 msg += 'See messages above for the actual file that produced it.\n'
59 raise SystemExit(msg)
59 raise SystemExit(msg)
60
60
61 try:
61 try:
62 execfile
62 execfile = execfile
63 except NameError:
63 except NameError:
64 def execfile(fname, globs, locs=None):
64 def execfile(fname, globs, locs=None):
65 locs = locs or globs
65 locs = locs or globs
66 exec(compile(open(fname).read(), fname, "exec"), globs, locs)
66 exec(compile(open(fname).read(), fname, "exec"), globs, locs)
General Comments 0
You need to be logged in to leave comments. Login now