pub fn check_executable(
        executable: impl AsRef<Path>,
        target: &Target,
        bridge: &BridgeModel,
    ) -> Result<Option<PythonInterpreter>> {
        let output = Command::new(&executable.as_ref())
            .args(&["-c", GET_INTERPRETER_METADATA])
            .stderr(Stdio::inherit())
            .output();

        let err_msg = format!(
            "Trying to get metadata from the python interpreter '{}' failed",
            executable.as_ref().display()
        );
        let output = match output {
            Ok(output) => {
                if output.status.success() {
                    output
                } else {
                    bail!(err_msg);
                }
            }
            Err(err) => {
                if err.kind() == io::ErrorKind::NotFound {
                    return Ok(None);
                } else {
                    return Err(err).context(err_msg);
                }
            }
        };
        let message: IntepreterMetadataMessage = serde_json::from_slice(&output.stdout)
            .context(err_msg)
            .context(String::from_utf8_lossy(&output.stdout).trim().to_string())?;

        if (message.major == 2 && message.minor != 7) || (message.major == 3 && message.minor < 5) {
            return Ok(None);
        }

        let interpreter;
        match message.interpreter.as_str() {
            "cpython" => interpreter = InterpreterKind::CPython,
            "pypy" => interpreter = InterpreterKind::PyPy,
            _ => {
                bail!("Invalid interpreter");
            }
        };

        let abiflags = fun_with_abiflags(&message, &target, &bridge).context(format_err!(
            "Failed to get information from the python interpreter at {}",
            executable.as_ref().display()
        ))?;

        Ok(Some(PythonInterpreter {
            major: message.major,
            minor: message.minor,
            abiflags,
            target: target.clone(),
            executable: executable.as_ref().to_path_buf(),
            ext_suffix: message.ext_suffix,
            interpreter_kind: interpreter,
            abi_tag: message.abi_tag,
            libs_dir: PathBuf::from(message.base_prefix).join("libs"),
        }))
    }
/// Checks whether the given command is a python interpreter and returns a
/// [PythonInterpreter] if that is the case
Checks whether the given command is a python interpreter and returns a
[PythonInterpreter] if that is the case
Checks whether the given command is a python interpreter and returns a [ PythonInterpreter ] if that is the case
pub fn check_executable(
        executable: impl AsRef<Path>,
        target: &Target,
        bridge: &BridgeModel,
    ) -> Result<Option<PythonInterpreter>> {
        let output = Command::new(&executable.as_ref())
            .args(&["-c", GET_INTERPRETER_METADATA])
            .stderr(Stdio::inherit())
            .output();
        let err_msg = format!(
            "Trying to get metadata from the python interpreter '{}' failed",
            executable.as_ref().display()
        );
        let output = match output {
            Ok(output) => {
                if output.status.success() {
                    output
                } else {
                    bail!(err_msg);
                }
            }
            Err(err) => {
                if err.kind() == io::ErrorKind::NotFound {
                    return Ok(None);
                } else {
                    return Err(err).context(err_msg);
                }
            }
        };
        let message: IntepreterMetadataMessage = serde_json::from_slice(&output.stdout)
            .context(err_msg)
            .context(String::from_utf8_lossy(&output.stdout).trim().to_string())?;
        if (message.major == 2 && message.minor != 7) || (message.major == 3 && message.minor < 5) {
            return Ok(None);
        }
        let interpreter;
        match message.interpreter.as_str() {
            "cpython" => interpreter = InterpreterKind::CPython,
            "pypy" => interpreter = InterpreterKind::PyPy,
            _ => {
                bail!("Invalid interpreter");
            }
        };
        let abiflags = fun_with_abiflags(&message, &target, &bridge).context(format_err!(
            "Failed to get information from the python interpreter at {}",
            executable.as_ref().display()
        ))?;
        Ok(Some(PythonInterpreter {
            major: message.major,
            minor: message.minor,
            abiflags,
            target: target.clone(),
            executable: executable.as_ref().to_path_buf(),
            ext_suffix: message.ext_suffix,
            interpreter_kind: interpreter,
            abi_tag: message.abi_tag,
            libs_dir: PathBuf::from(message.base_prefix).join("libs"),
        }))
    }
pub fn check_executable ( executable : impl AsRef < Path > , target : & Target , bridge : & BridgeModel , ) -> Result < Option < PythonInterpreter > > { let output = Command :: new ( & executable . as_ref ( ) ) . args ( & [ " " , GET_INTERPRETER_METADATA ] ) . stderr ( Stdio :: inherit ( ) ) . output ( ) ; let err_msg = format ! ( " " executable as_ref ( ) display ( ) ) ; let output = match output { Ok ( output ) => { if output . status . success ( ) { output } else { bail ! ( err_msg ) ; } } Err ( err ) => { if err . kind ( ) == io :: ErrorKind :: NotFound { return Ok ( None ) ; } else { return Err ( err ) . context ( err_msg ) ; } } } ; let message : IntepreterMetadataMessage = serde_json :: from_slice ( & output . stdout ) . context ( err_msg ) . context ( String :: from_utf8_lossy ( & output . stdout ) . trim ( ) . to_string ( ) ) ? ; if ( message . major == 2 && message . minor != 7 ) || ( message . major == 3 && message . minor < 5 ) { return Ok ( None ) ; } let interpreter ; match message . interpreter . as_str ( ) { " " => interpreter = InterpreterKind :: CPython , " " => interpreter = InterpreterKind :: PyPy , _ => { bail ! ( " " ) ; } } ; let abiflags = fun_with_abiflags ( & message , & target , & bridge ) . context ( format_err ! ( " " executable as_ref ( ) display ( ) ) ) ? ; Ok ( Some ( PythonInterpreter { major : message . major , minor : message . minor , abiflags , target : target . clone ( ) , executable : executable . as_ref ( ) . to_path_buf ( ) , ext_suffix : message . ext_suffix , interpreter_kind : interpreter , abi_tag : message . abi_tag , libs_dir : PathBuf :: from ( message . base_prefix ) . join ( " " ) , } ) ) }
Checks whether the given command is a python interpreter and returns a
[PythonInterpreter] if that is the case
Checks whether the given command is a python interpreter and returns a [ PythonInterpreter ] if that is the case
executable
impl AsRef<Path>
target
&Target
bridge
&BridgeModel
executable
impl AsRef<Path>
target
&Target
bridge
&BridgeModel