forked from xonsh/xonsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xonsh-in-docker.py
executable file
·71 lines (60 loc) · 1.99 KB
/
xonsh-in-docker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import subprocess
import os
import argparse
program_description = """Build and run Xonsh in a fresh, controlled
environment using docker """
parser = argparse.ArgumentParser(description=program_description)
parser.add_argument("env", nargs="*", default=[], metavar="ENV=value")
parser.add_argument("--python", "-p", default="3.6", metavar="python_version")
parser.add_argument("--pypy", default=None, metavar="pypy_version")
parser.add_argument("--ptk", "-t", default="2.0.4", metavar="ptk_version")
parser.add_argument("--keep", action="store_true")
parser.add_argument("--build", action="store_true")
parser.add_argument("--command", "-c", default="xonsh", metavar="command")
parser.add_argument("--pytest", action="store_true")
args = parser.parse_args()
docker_script = """
from python:{python_version}
RUN pip install --upgrade pip && pip install \\
prompt-toolkit=={ptk_version} \\
{pytest} \\
pygments
RUN mkdir /xonsh
WORKDIR /xonsh
ADD ./ ./
RUN python setup.py install
""".format(
python_version=args.python, ptk_version=args.ptk, pytest="pytest" if args.pytest else ""
)
if args.pypy:
docker_script = """
from pypy:{python_version}
RUN pypy3 -m ensurepip
RUN pip install --upgrade pip && pip install \\
prompt-toolkit=={ptk_version} \\
{pytest} \\
pygments
RUN mkdir /xonsh
WORKDIR /xonsh
ADD ./ ./
RUN pypy3 setup.py install
""".format(
python_version=args.pypy, ptk_version=args.ptk, pytest="pytest" if args.pytest else ""
)
print("Building and running Xonsh")
print("Using python ", args.python)
print("Using prompt-toolkit ", args.ptk)
with open("./Dockerfile", "w+") as f:
f.write(docker_script)
env_string = " ".join(args.env)
subprocess.call(["docker", "build", "-t", "xonsh", "."])
os.remove("./Dockerfile")
if not args.build:
run_args = ["docker", "run", "-ti"]
for e in args.env:
run_args += ["-e", e]
if not args.keep:
run_args.append("--rm")
run_args += ["xonsh", args.command]
subprocess.call(run_args)