toollib.py
48 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
/ tools / toollib.py
Fernando Perez
|
r2118 | """Various utilities common to IPython release and maintenance tools. | ||
""" | ||||
Fernando Perez
|
r4450 | |||
Fernando Perez
|
r2118 | # Library imports | ||
import os | ||||
Matthias Bussonnier
|
r24558 | import sys | ||
Fernando Perez
|
r2118 | |||
Martin Matějek
|
r28472 | from pathlib import Path | ||
Fernando Perez
|
r2118 | # Useful shorthands | ||
cd = os.chdir | ||||
Fernando Perez
|
r4452 | # Constants | ||
# SSH root address of the archive site | ||||
Fernando Perez
|
r5731 | archive_user = 'ipython@archive.ipython.org' | ||
archive_dir = 'archive.ipython.org' | ||||
archive = '%s:%s' % (archive_user, archive_dir) | ||||
Fernando Perez
|
r4452 | |||
Fernando Perez
|
r6605 | # Build commands | ||
# Source dists | ||||
Matthias Bussonnier
|
r27319 | build_command = "{python} -m build".format(python=sys.executable) | ||
Matthias Bussonnier
|
r27315 | |||
Fernando Perez
|
r6604 | |||
Fernando Perez
|
r2118 | # Utility functions | ||
Fernando Perez
|
r3197 | def sh(cmd): | ||
"""Run system command in shell, raise SystemExit if it returns an error.""" | ||||
Fernando Perez
|
r4450 | print("$", cmd) | ||
Fernando Perez
|
r2119 | stat = os.system(cmd) | ||
#stat = 0 # Uncomment this and comment previous to run in debug mode | ||||
Fernando Perez
|
r2118 | if stat: | ||
raise SystemExit("Command %s failed with code: %s" % (cmd, stat)) | ||||
def get_ipdir(): | ||||
"""Get IPython directory from command line, or assume it's the one above.""" | ||||
# Initialize arguments and check location | ||||
Martin Matějek
|
r28472 | ipdir = Path(__file__).parent / os.pardir | ||
ipdir = ipdir.resolve() | ||||
Fernando Perez
|
r2118 | |||
cd(ipdir) | ||||
Martin Matějek
|
r28472 | if not Path("IPython").is_dir() and Path("setup.py").is_file(): | ||
raise SystemExit("Invalid ipython directory: %s" % ipdir) | ||||
Fernando Perez
|
r2118 | return ipdir | ||
Matthias Bussonnier
|
r24558 | def execfile(fname, globs, locs=None): | ||
locs = locs or globs | ||||
gousaiyang
|
r27495 | exec(compile(open(fname, encoding="utf-8").read(), fname, "exec"), globs, locs) | ||