@@ -67,6 +67,18 @@ def setup_verbose(ctx, param, value):
67
67
return value
68
68
69
69
70
+ def validate_python_path (ctx , param , value ):
71
+ # Validating the Python path is complicated by accepting a number of
72
+ # friendly options: the default will be boolean False to enable
73
+ # autodetection but it may also be a value which will be searched in
74
+ # the path or an absolute path. To report errors as early as possible
75
+ # we'll report absolute paths which do not exist:
76
+ if isinstance (value , (str , bytes )):
77
+ if os .path .isabs (value ) and not os .path .isfile (value ):
78
+ raise click .BadParameter ('Expected Python at path %s does not exist' % value )
79
+ return value
80
+
81
+
70
82
@group (
71
83
cls = PipenvGroup ,
72
84
invoke_without_command = True ,
@@ -117,6 +129,7 @@ def setup_verbose(ctx, param, value):
117
129
'--python' ,
118
130
default = False ,
119
131
nargs = 1 ,
132
+ callback = validate_python_path ,
120
133
help = "Specify which version of Python virtualenv should use." ,
121
134
)
122
135
@option (
@@ -285,6 +298,7 @@ def cli(
285
298
'--python' ,
286
299
default = False ,
287
300
nargs = 1 ,
301
+ callback = validate_python_path ,
288
302
help = "Specify which version of Python virtualenv should use." ,
289
303
)
290
304
@option (
@@ -404,6 +418,7 @@ def install(
404
418
'--python' ,
405
419
default = False ,
406
420
nargs = 1 ,
421
+ callback = validate_python_path ,
407
422
help = "Specify which version of Python virtualenv should use." ,
408
423
)
409
424
@option (
@@ -475,6 +490,7 @@ def uninstall(
475
490
'--python' ,
476
491
default = False ,
477
492
nargs = 1 ,
493
+ callback = validate_python_path ,
478
494
help = "Specify which version of Python virtualenv should use." ,
479
495
)
480
496
@option (
@@ -546,6 +562,7 @@ def lock(
546
562
'--python' ,
547
563
default = False ,
548
564
nargs = 1 ,
565
+ callback = validate_python_path ,
549
566
help = "Specify which version of Python virtualenv should use." ,
550
567
)
551
568
@option (
@@ -612,6 +629,7 @@ def shell(
612
629
'--python' ,
613
630
default = False ,
614
631
nargs = 1 ,
632
+ callback = validate_python_path ,
615
633
help = "Specify which version of Python virtualenv should use." ,
616
634
)
617
635
def run (command , args , three = None , python = False ):
@@ -633,6 +651,7 @@ def run(command, args, three=None, python=False):
633
651
'--python' ,
634
652
default = False ,
635
653
nargs = 1 ,
654
+ callback = validate_python_path ,
636
655
help = "Specify which version of Python virtualenv should use." ,
637
656
)
638
657
@option (
@@ -672,6 +691,7 @@ def check(
672
691
'--python' ,
673
692
default = False ,
674
693
nargs = 1 ,
694
+ callback = validate_python_path ,
675
695
help = "Specify which version of Python virtualenv should use." ,
676
696
)
677
697
@option (
@@ -841,6 +861,7 @@ def graph(bare=False, json=False, reverse=False):
841
861
'--python' ,
842
862
default = False ,
843
863
nargs = 1 ,
864
+ callback = validate_python_path ,
844
865
help = "Specify which version of Python virtualenv should use." ,
845
866
)
846
867
@argument ('module' , nargs = 1 )
@@ -896,6 +917,7 @@ def run_open(module, three=None, python=None):
896
917
'--python' ,
897
918
default = False ,
898
919
nargs = 1 ,
920
+ callback = validate_python_path ,
899
921
help = "Specify which version of Python virtualenv should use." ,
900
922
)
901
923
@option ('--bare' , is_flag = True , default = False , help = "Minimal output." )
@@ -962,6 +984,7 @@ def sync(
962
984
'--python' ,
963
985
default = False ,
964
986
nargs = 1 ,
987
+ callback = validate_python_path ,
965
988
help = "Specify which version of Python virtualenv should use." ,
966
989
)
967
990
@option (
0 commit comments