Skip to content

Commit 6aa91c2

Browse files
Stephan SokolowStephan Sokolow
Stephan Sokolow
authored and
Stephan Sokolow
committed
apply.py: Do a sanity check for the presence of git and cargo
1 parent f84cbeb commit 6aa91c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

apply.py

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
__license__ = "Apache-2.0 OR MIT"
1313

1414
import json, logging, os, re, shutil, subprocess, sys, tempfile, time
15+
from distutils.spawn import find_executable
16+
1517
log = logging.getLogger(__name__)
1618

1719
try:
@@ -209,6 +211,12 @@ def new_project(dest_dir):
209211
shutil.rmtree(temp_dir)
210212
os.chdir(cur_wd)
211213

214+
def assert_command_in_path(command):
215+
"""Check for the required external commands and exit on failure"""
216+
if not find_executable(command):
217+
log.critical("Could not find %r in PATH. Exiting.", command)
218+
sys.exit(1)
219+
212220
def main():
213221
"""The main entry point, compatible with setuptools entry points."""
214222
from argparse import ArgumentParser, RawDescriptionHelpFormatter
@@ -234,6 +242,11 @@ def main():
234242
logging.basicConfig(level=log_levels[args.verbose],
235243
format='%(levelname)s: %(message)s')
236244

245+
# TODO: Rework things so ensure_terminal gets brought up first but only
246+
# if it is necessary
247+
assert_command_in_path('git')
248+
assert_command_in_path('cargo')
249+
237250
while not args.destdir:
238251
ensure_terminal()
239252
destdir = input("Path for new project: ")

0 commit comments

Comments
 (0)