Repository: astral-sh/uv
File: crates/uv-build-frontend/src/lib.rs (Rust)

Code before:
        // > backend hooks.
        formatdoc! {r#"
            import sys

            if sys.path[0] == "":
                sys.path.pop(0)

            sys.path = [{backend_path}] + sys.path

            {import}
        "#, backend_path = backend_path_encoded}
    }

    fn is_setuptools(&self) -> bool {
        // either `setuptools.build_meta` or `setuptools.build_meta:__legacy__`
        self.backend.split(':').next() == Some("setuptools.build_meta")
    }
}

/// Uses an [`Arc`] internally, clone freely.
#[derive(Debug, Clone)]
pub struct SourceBuildContext {
    /// An in-memory resolution of the default backend's requirements for PEP 517 builds.
    default_resolution: Arc<Mutex<Option<Resolution>>>,
    /// A shared semaphore to limit the number of concurrent builds.
    concurrency: Arc<Semaphore>,
}

impl SourceBuildContext {
    /// Create a [`SourceBuildContext`] with the given concurrent build limit.
    pub fn new(concurrent_builds: usize) -> Self {
        Self {
            default_resolution: Arc::default(),
            concurrency: Arc::new(Semaphore::new(concurrent_builds)),
        }
    }
}

/// Holds the state through a series of PEP 517 frontend to backend calls or a single `setup.py`
/// invocation.
///
/// This keeps both the temp dir and the result of a potential `prepare_metadata_for_build_wheel`
/// call which changes how we call `build_wheel`.
pub struct SourceBuild {
    temp_dir: TempDir,
    source_tree: PathBuf,
    config_settings: ConfigSettings,
    /// If performing a PEP 517 build, the backend to use.
    pep517_backend: Pep517Backend,
    /// The PEP 621 project metadata, if any.
    project: Option<Project>,

Review comment (suggestion):
Somewhat of a nitpick maybe: I think `concurrency` is a bit confusing for a name for this. There's `PythonRunner` where this is called `control`. While I'm not a fan of `control` either, it seems a bit less confusing. I'd maybe suggest something like `build_job_slots` or something. We use `concurrency` in a bunch of places to refer to `uv_configuration::Concurrency`.

Code after:
        // > backend hooks.
        formatdoc! {r#"
            import sys

            if sys.path[0] == "":
                sys.path.pop(0)

            sys.path = [{backend_path}] + sys.path

            {import}
        "#, backend_path = backend_path_encoded}
    }

    fn is_setuptools(&self) -> bool {
        // either `setuptools.build_meta` or `setuptools.build_meta:__legacy__`
        self.backend.split(':').next() == Some("setuptools.build_meta")
    }
}

/// Uses an [`Arc`] internally, clone freely.
#[derive(Debug, Clone)]
pub struct SourceBuildContext {
    /// An in-memory resolution of the default backend's requirements for PEP 517 builds.
    default_resolution: Arc<Mutex<Option<Resolution>>>,
    /// A shared semaphore to limit the number of concurrent builds.
    concurrent_build_slots: Arc<Semaphore>,
}

impl SourceBuildContext {
    /// Create a [`SourceBuildContext`] with the given concurrent build limit.
    pub fn new(concurrent_builds: usize) -> Self {
        Self {
            default_resolution: Arc::default(),
            concurrent_build_slots: Arc::new(Semaphore::new(concurrent_builds)),
        }
    }
}

/// Holds the state through a series of PEP 517 frontend to backend calls or a single `setup.py`
/// invocation.
///
/// This keeps both the temp dir and the result of a potential `prepare_metadata_for_build_wheel`
/// call which changes how we call `build_wheel`.
pub struct SourceBuild {
    temp_dir: TempDir,
    source_tree: PathBuf,
    config_settings: ConfigSettings,
    /// If performing a PEP 517 build, the backend to use.
    pep517_backend: Pep517Backend,
    /// The PEP 621 project metadata, if any.
    project: Option<Project>,