Debian Codegraph @

tools/toollib.py

raw
1 """Various utilities common to IPython release and maintenance tools.
2 """
3
4 # Library imports
5 import os
6 import sys
7
8 from pathlib import Path
9
10 # Useful shorthands
11 cd = os.chdir
12
13 # Constants
14
15 # SSH root address of the archive site
16 archive_user = '[email protected]'
17 archive_dir = 'archive.ipython.org'
18 archive = '%s:%s' % (archive_user, archive_dir)
19
20 # Build commands
21 # Source dists
22 build_command = "{python} -m build".format(python=sys.executable)
23
24
25 # Utility functions
26 def sh(cmd):
27 """Run system command in shell, raise SystemExit if it returns an error."""
28 print("$", cmd)
29 stat = os.system(cmd)
30 #stat = 0 # Uncomment this and comment previous to run in debug mode
31 if stat:
32 raise SystemExit("Command %s failed with code: %s" % (cmd, stat))
33
34 def get_ipdir():
35 """Get IPython directory from command line, or assume it's the one above."""
36
37 # Initialize arguments and check location
38 ipdir = Path(__file__).parent / os.pardir
39 ipdir = ipdir.resolve()
40
41 cd(ipdir)
42 if not Path("IPython").is_dir() and Path("setup.py").is_file():
43 raise SystemExit("Invalid ipython directory: %s" % ipdir)
44 return ipdir
45
46 def execfile(fname, globs, locs=None):
47 locs = locs or globs
48 exec(compile(open(fname, encoding="utf-8").read(), fname, "exec"), globs, locs)