@@ -56,6 +56,18 @@ def setup_verbose(ctx, param, value):
56
56
return value
57
57
58
58
59
+ def validate_python_path (ctx , param , value ):
60
+ # Validating the Python path is complicated by accepting a number of
61
+ # friendly options: the default will be boolean False to enable
62
+ # autodetection but it may also be a value which will be searched in
63
+ # the path or an absolute path. To report errors as early as possible
64
+ # we'll report absolute paths which do not exist:
65
+ if isinstance (value , (str , bytes )):
66
+ if os .path .isabs (value ) and not os .path .isfile (value ):
67
+ raise click .BadParameter ('Expected Python at path %s does not exist' % value )
68
+ return value
69
+
70
+
59
71
@click .group (
60
72
cls = PipenvGroup ,
61
73
invoke_without_command = True ,
@@ -106,6 +118,7 @@ def setup_verbose(ctx, param, value):
106
118
'--python' ,
107
119
default = False ,
108
120
nargs = 1 ,
121
+ callback = validate_python_path ,
109
122
help = "Specify which version of Python virtualenv should use." ,
110
123
)
111
124
@click .option (
@@ -263,6 +276,7 @@ def cli(
263
276
'--python' ,
264
277
default = False ,
265
278
nargs = 1 ,
279
+ callback = validate_python_path ,
266
280
help = "Specify which version of Python virtualenv should use." ,
267
281
)
268
282
@click .option (
@@ -382,6 +396,7 @@ def install(
382
396
'--python' ,
383
397
default = False ,
384
398
nargs = 1 ,
399
+ callback = validate_python_path ,
385
400
help = "Specify which version of Python virtualenv should use." ,
386
401
)
387
402
@click .option (
@@ -453,6 +468,7 @@ def uninstall(
453
468
'--python' ,
454
469
default = False ,
455
470
nargs = 1 ,
471
+ callback = validate_python_path ,
456
472
help = "Specify which version of Python virtualenv should use." ,
457
473
)
458
474
@click .option (
@@ -527,6 +543,7 @@ def lock(
527
543
'--python' ,
528
544
default = False ,
529
545
nargs = 1 ,
546
+ callback = validate_python_path ,
530
547
help = "Specify which version of Python virtualenv should use." ,
531
548
)
532
549
@click .option (
@@ -594,6 +611,7 @@ def shell(
594
611
'--python' ,
595
612
default = False ,
596
613
nargs = 1 ,
614
+ callback = validate_python_path ,
597
615
help = "Specify which version of Python virtualenv should use." ,
598
616
)
599
617
def run (command , args , three = None , python = False ):
@@ -616,6 +634,7 @@ def run(command, args, three=None, python=False):
616
634
'--python' ,
617
635
default = False ,
618
636
nargs = 1 ,
637
+ callback = validate_python_path ,
619
638
help = "Specify which version of Python virtualenv should use." ,
620
639
)
621
640
@click .option (
@@ -655,6 +674,7 @@ def check(
655
674
'--python' ,
656
675
default = False ,
657
676
nargs = 1 ,
677
+ callback = validate_python_path ,
658
678
help = "Specify which version of Python virtualenv should use." ,
659
679
)
660
680
@click .option (
@@ -819,6 +839,7 @@ def graph(bare=False, json=False, reverse=False):
819
839
'--python' ,
820
840
default = False ,
821
841
nargs = 1 ,
842
+ callback = validate_python_path ,
822
843
help = "Specify which version of Python virtualenv should use." ,
823
844
)
824
845
@click .argument ('module' , nargs = 1 )
@@ -874,6 +895,7 @@ def run_open(module, three=None, python=None):
874
895
'--python' ,
875
896
default = False ,
876
897
nargs = 1 ,
898
+ callback = validate_python_path ,
877
899
help = "Specify which version of Python virtualenv should use." ,
878
900
)
879
901
@click .option ('--bare' , is_flag = True , default = False , help = "Minimal output." )
@@ -940,6 +962,7 @@ def sync(
940
962
'--python' ,
941
963
default = False ,
942
964
nargs = 1 ,
965
+ callback = validate_python_path ,
943
966
help = "Specify which version of Python virtualenv should use." ,
944
967
)
945
968
@click .option (
0 commit comments