scripts: sphinx-pre-install: fix a bug when using with venv
[linux-block.git] / scripts / sphinx-pre-install
index 938b65d40fc8f1971383c3de1b455d9daeb07fb6..987aebf7e3a0d858557a4688c01da151e3c1425f 100755 (executable)
@@ -148,6 +148,24 @@ sub findprog($)
        }
 }
 
+sub find_python_no_venv()
+{
+       my $prog = shift;
+
+       my $cur_dir = qx(pwd);
+       $cur_dir =~ s/\s+$//;
+
+       foreach my $dir (split(/:/, $ENV{PATH})) {
+               next if ($dir =~ m,($cur_dir)/sphinx,);
+               return "$dir/python3" if(-x "$dir/python3");
+       }
+       foreach my $dir (split(/:/, $ENV{PATH})) {
+               next if ($dir =~ m,($cur_dir)/sphinx,);
+               return "$dir/python" if(-x "$dir/python");
+       }
+       return "python";
+}
+
 sub check_program($$)
 {
        my $prog = shift;
@@ -814,6 +832,8 @@ sub check_needs()
 
                        print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade);
 
+                       $python_cmd = find_python_no_venv();
+
                        if ($need_venv) {
                                printf "\t$python_cmd -m venv $virtenv_dir\n";
                        } else {