@@ -366,9 +366,18 @@ fn create_settings(matches: &ArgMatches) -> Settings {
366366 . chain ( module. skip ( 1 ) . map ( ToOwned :: to_owned) )
367367 . collect ( )
368368 } else if let Some ( get_pip_args) = matches. values_of ( "install_pip" ) {
369- std:: iter:: once ( "get-pip.py" . to_owned ( ) )
370- . chain ( get_pip_args. map ( ToOwned :: to_owned) )
371- . collect ( )
369+ settings. isolated = true ;
370+ let mut args: Vec < _ > = get_pip_args. map ( ToOwned :: to_owned) . collect ( ) ;
371+ if args. is_empty ( ) {
372+ args. push ( "ensurepip" . to_owned ( ) ) ;
373+ args. push ( "--upgrade" . to_owned ( ) ) ;
374+ args. push ( "--default-pip" . to_owned ( ) ) ;
375+ }
376+ match args. first ( ) . map ( String :: as_str) {
377+ Some ( "ensurepip" ) | Some ( "get-pip" ) => ( ) ,
378+ _ => panic ! ( "--install-pip takes ensurepip or get-pip as first argument" ) ,
379+ }
380+ args
372381 } else if let Some ( cmd) = matches. values_of ( "c" ) {
373382 std:: iter:: once ( "-c" . to_owned ( ) )
374383 . chain ( cmd. skip ( 1 ) . map ( ToOwned :: to_owned) )
@@ -497,7 +506,7 @@ fn setup_main_module(vm: &VirtualMachine) -> PyResult<Scope> {
497506}
498507
499508#[ cfg( feature = "ssl" ) ]
500- fn install_pip ( scope : Scope , vm : & VirtualMachine ) -> PyResult {
509+ fn get_pip ( scope : Scope , vm : & VirtualMachine ) -> PyResult < ( ) > {
501510 let get_getpip = rustpython_vm:: py_compile!(
502511 source = r#"\
503512__import__("io").TextIOWrapper(
@@ -512,14 +521,29 @@ __import__("io").TextIOWrapper(
512521 . downcast ( )
513522 . expect ( "TextIOWrapper.read() should return str" ) ;
514523 eprintln ! ( "running get-pip.py..." ) ;
515- vm. run_code_string ( scope, getpip_code. as_str ( ) , "get-pip.py" . to_owned ( ) )
524+ vm. run_code_string ( scope, getpip_code. as_str ( ) , "get-pip.py" . to_owned ( ) ) ?;
525+ Ok ( ( ) )
516526}
517527
518- #[ cfg( not( feature = "ssl" ) ) ]
519- fn install_pip ( _: Scope , vm : & VirtualMachine ) -> PyResult {
528+ #[ cfg( feature = "ssl" ) ]
529+ fn ensurepip ( _: Scope , vm : & VirtualMachine ) -> PyResult < ( ) > {
530+ vm. run_module ( "ensurepip" )
531+ }
532+
533+ fn install_pip ( _scope : Scope , vm : & VirtualMachine ) -> PyResult < ( ) > {
534+ #[ cfg( feature = "ssl" ) ]
535+ {
536+ match vm. state . settings . argv [ 0 ] . as_str ( ) {
537+ "ensurepip" => ensurepip ( _scope, vm) ,
538+ "get-pip" => get_pip ( _scope, vm) ,
539+ _ => unreachable ! ( ) ,
540+ }
541+ }
542+
543+ #[ cfg( not( feature = "ssl" ) ) ]
520544 Err ( vm. new_exception_msg (
521545 vm. ctx . exceptions . system_error . to_owned ( ) ,
522- "install-pip requires rustpython be build with the ' ssl' feature enabled. " . to_owned ( ) ,
546+ "install-pip requires rustpython be build with '--features= ssl'" . to_owned ( ) ,
523547 ) )
524548}
525549
0 commit comments