@@ -659,7 +659,7 @@ pub(crate) async fn parse_script(
659
659
// Parse the input command.
660
660
let command = RunCommand :: from ( command) ;
661
661
662
- let RunCommand :: Python ( target, _) = & command else {
662
+ let RunCommand :: PythonScript ( target, _) = & command else {
663
663
return Ok ( None ) ;
664
664
} ;
665
665
@@ -716,8 +716,10 @@ fn can_skip_ephemeral(
716
716
717
717
#[ derive( Debug ) ]
718
718
enum RunCommand {
719
+ /// Execute `python`.
720
+ Python ( Vec < OsString > ) ,
719
721
/// Execute a `python` script.
720
- Python ( PathBuf , Vec < OsString > ) ,
722
+ PythonScript ( PathBuf , Vec < OsString > ) ,
721
723
/// Execute an external command.
722
724
External ( OsString , Vec < OsString > ) ,
723
725
/// Execute an empty command (in practice, `python` with no arguments).
@@ -728,15 +730,21 @@ impl RunCommand {
728
730
/// Return the name of the target executable, for display purposes.
729
731
fn display_executable ( & self ) -> Cow < ' _ , str > {
730
732
match self {
731
- Self :: Python ( _, _) | Self :: Empty => Cow :: Borrowed ( "python" ) ,
733
+ Self :: Python ( _) => Cow :: Borrowed ( "python" ) ,
734
+ Self :: PythonScript ( _, _) | Self :: Empty => Cow :: Borrowed ( "python" ) ,
732
735
Self :: External ( executable, _) => executable. to_string_lossy ( ) ,
733
736
}
734
737
}
735
738
736
739
/// Convert a [`RunCommand`] into a [`Command`].
737
740
fn as_command ( & self , interpreter : & Interpreter ) -> Command {
738
741
match self {
739
- Self :: Python ( target, args) => {
742
+ Self :: Python ( args) => {
743
+ let mut process = Command :: new ( interpreter. sys_executable ( ) ) ;
744
+ process. args ( args) ;
745
+ process
746
+ }
747
+ Self :: PythonScript ( target, args) => {
740
748
let mut process = Command :: new ( interpreter. sys_executable ( ) ) ;
741
749
process. arg ( target) ;
742
750
process. args ( args) ;
@@ -755,7 +763,14 @@ impl RunCommand {
755
763
impl std:: fmt:: Display for RunCommand {
756
764
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
757
765
match self {
758
- Self :: Python ( target, args) => {
766
+ Self :: Python ( args) => {
767
+ write ! ( f, "python" ) ?;
768
+ for arg in args {
769
+ write ! ( f, " {}" , arg. to_string_lossy( ) ) ?;
770
+ }
771
+ Ok ( ( ) )
772
+ }
773
+ Self :: PythonScript ( target, args) => {
759
774
write ! ( f, "python {}" , target. display( ) ) ?;
760
775
for arg in args {
761
776
write ! ( f, " {}" , arg. to_string_lossy( ) ) ?;
@@ -786,12 +801,14 @@ impl From<&ExternalCommand> for RunCommand {
786
801
} ;
787
802
788
803
let target_path = PathBuf :: from ( & target) ;
789
- if target_path
804
+ if target. eq_ignore_ascii_case ( "python" ) {
805
+ Self :: Python ( args. to_vec ( ) )
806
+ } else if target_path
790
807
. extension ( )
791
808
. is_some_and ( |ext| ext. eq_ignore_ascii_case ( "py" ) )
792
809
&& target_path. exists ( )
793
810
{
794
- Self :: Python ( target_path, args. to_vec ( ) )
811
+ Self :: PythonScript ( target_path, args. to_vec ( ) )
795
812
} else {
796
813
Self :: External (
797
814
target. clone ( ) ,
0 commit comments