Repository: astral-sh/ruff
File: crates/ty_site_packages/src/lib.rs (Rust)

Code before:
        let virtual_env_directory = project_root.join(".venv");

        match PythonEnvironment::new(
            &virtual_env_directory,
            SysPrefixPathOrigin::LocalVenv,
            system,
        ) {
            Ok(environment) => return Ok(Some(environment)),
            Err(err) => {
                if system.is_directory(&virtual_env_directory) {
                    tracing::debug!(
                        "Ignoring automatically detected virtual environment at `{}`: {}",
                        &virtual_env_directory,
                        err
                    );
                }
            }
        }

        if let Some(conda_env) = conda_environment_from_env(system, CondaEnvironmentKind::Base) {
            return resolve_environment(system, &conda_env, SysPrefixPathOrigin::CondaPrefixVar)
                .map(Some);
        }

        #[cfg(not(target_family = "wasm"))]
        if let Ok(python_path) = which::which("python3")
            && let Some(python_path) = python_path.to_str()
            && let Ok(env) =
                PythonEnvironment::new(python_path, SysPrefixPathOrigin::PythonBinary, system)
        {
            return Ok(Some(env));
        }

        Ok(None)
    }

    pub fn new(
        path: impl AsRef<SystemPath>,
        origin: SysPrefixPathOrigin,
        system: &dyn System,
    ) -> SitePackagesDiscoveryResult<Self> {
        let path = SysPrefixPath::new(path.as_ref(), origin, system)?;

        // Attempt to inspect as a virtual environment first
        match VirtualEnvironment::new(path, system) {
            Ok(venv) => Ok(Self::Virtual(venv)),
            // If there's not a `pyvenv.cfg` marker, attempt to inspect as a system environment
            Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(path, _, _))
                if !path.origin.must_be_virtual_env() =>
            {
                Ok(Self::System(SystemEnvironment::new(path)))

Review comment (suggestion):
the default executable on Windows is often `python` rather than `python3`, so we should check both

Code after:
        let virtual_env_directory = project_root.join(".venv");

        match PythonEnvironment::new(
            &virtual_env_directory,
            SysPrefixPathOrigin::LocalVenv,
            system,
        ) {
            Ok(environment) => return Ok(Some(environment)),
            Err(err) => {
                if system.is_directory(&virtual_env_directory) {
                    tracing::debug!(
                        "Ignoring automatically detected virtual environment at `{}`: {}",
                        &virtual_env_directory,
                        err
                    );
                }
            }
        }

        if let Some(conda_env) = conda_environment_from_env(system, CondaEnvironmentKind::Base) {
            return resolve_environment(system, &conda_env, SysPrefixPathOrigin::CondaPrefixVar)
                .map(Some);
        }

        if let Some(env) = environment_from_binary(system, "python3")
            .or_else(|| environment_from_binary(system, "python"))
        {
            return Ok(Some(env));
        }

        Ok(None)
    }

    pub fn new(
        path: impl AsRef<SystemPath>,
        origin: SysPrefixPathOrigin,
        system: &dyn System,
    ) -> SitePackagesDiscoveryResult<Self> {
        let path = SysPrefixPath::new(path.as_ref(), origin, system)?;

        // Attempt to inspect as a virtual environment first
        match VirtualEnvironment::new(path, system) {
            Ok(venv) => Ok(Self::Virtual(venv)),
            // If there's not a `pyvenv.cfg` marker, attempt to inspect as a system environment
            Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(path, _, _))
                if !path.origin.must_be_virtual_env() =>
            {
                Ok(Self::System(SystemEnvironment::new(path)))
            }
            Err(err) => Err(err),
        }