File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,12 +22,14 @@ if [[ ${SPIN_PYTHONPATH} == "\$PYTHONPATH" ]]; then
2222 echo " Expected Python path, but got $SPIN_PYTHONPATH instead"
2323 exit 1
2424fi
25+
2526echo -e " ${MAGENTA} Does \$ PYTHONPATH contains site-packages?${NORMAL} "
2627if [[ ${SPIN_PYTHONPATH} == * " site-packages" ]]; then
2728 echo " Yes"
2829else
2930 echo " No; it is $SPIN_PYTHONPATH "
3031fi
32+
3133echo -e " ${MAGENTA} Does \` spin run\` redirect only command output to stdout?${NORMAL} "
3234# Once we're on Python >3.11, can replace syspath manipulation below with -P flag to Python
3335VERSION=$( spin run python -c ' import sys; del sys.path[0]; import example_pkg; print(example_pkg.__version__)' )
3840 exit 1
3941fi
4042
43+ if [[ $PLATFORM == linux || $PLATFORM == darwin ]]; then
44+ # Detecting whether a file is executable is not that easy on Windows,
45+ # as it seems to take into consideration whether that file is associated as an executable.
46+ echo -e " ${MAGENTA} Does \` spin run foo.py\` warn that \` spin run python foo.py\` is correct?${NORMAL} "
47+ OUT=$( touch __foo.py && spin run __foo.py || true )
48+ rm __foo.py
49+ if [[ $OUT == * " Did you mean to call" * ]]; then
50+ echo " Yes"
51+ else
52+ echo " No, output is: $OUT "
53+ exit 1
54+ fi
55+ fi
56+
4157prun spin test
4258echo -e " ${MAGENTA} Running \` spin test\` , but with PYTHONPATH set${NORMAL} "
4359PYTHONPATH=./tmp spin test
Original file line number Diff line number Diff line change 11import contextlib
2+ import copy
23import json
34import os
45import shutil
@@ -496,15 +497,28 @@ def run(ctx, args):
496497
497498 is_posix = sys .platform in ("linux" , "darwin" )
498499 shell = len (args ) == 1
500+ cmd_args = copy .copy (args )
499501 if shell :
500- args = args [0 ]
501-
502- if shell and not is_posix :
503- # On Windows, we're going to try to use bash
504- args = ["bash" , "-c" , args ]
502+ cmd_args = args [0 ]
503+ if not is_posix :
504+ # On Windows, we're going to try to use bash
505+ cmd_args = ["bash" , "-c" , cmd_args ]
505506
506507 _set_pythonpath (quiet = True )
507- _run (args , echo = False , shell = shell )
508+ p = _run (cmd_args , echo = False , shell = shell , sys_exit = False )
509+
510+ # Is the user trying to run a Python script, without calling the Python interpreter?
511+ executable = args [0 ]
512+ if (
513+ (p .returncode != 0 )
514+ and args [0 ].endswith (".py" )
515+ and os .path .exists (executable )
516+ and (not os .access (executable , os .X_OK ))
517+ ):
518+ click .secho (
519+ f"Did you mean to call `spin run python { ' ' .join (args )} `?" , fg = "bright_red"
520+ )
521+ sys .exit (p .returncode )
508522
509523
510524@click .command ()
You can’t perform that action at this time.
0 commit comments