Repository: scikit-learn/scikit-learn
File: build_tools/update_environments_and_lock_files.py (Python)

Code before:
        "--platform",
        platform,
        "--file",
        str(environment_path),
        "--filename-template",
        str(lock_file_path),
    ]
    if virtual_package_spec is not None:
        cmd.extend(["--virtual-package-spec", str(virtual_package_spec)])
    execute_command(cmd)


def create_conda_lock_file(build_metadata):
    build_name = build_metadata["name"]
    folder_path = Path(build_metadata["folder"])
    environment_path = folder_path / f"{build_name}_environment.yml"
    platform = build_metadata["platform"]
    lock_file_basename = build_name
    if not lock_file_basename.endswith(platform):
        lock_file_basename = f"{lock_file_basename}_{platform}"

    lock_file_path = folder_path / f"{lock_file_basename}_conda.lock"

    # Use virtual package spec for CUDA builds so that conda-lock also works
    # on systems without CUDA.
    virtual_package_spec = None
    if build_metadata.get("tag") == "cuda":
        virtual_package_spec = folder_path / "virtual-packages-cuda.yml"

    conda_lock(environment_path, lock_file_path, platform, virtual_package_spec)


def write_all_conda_lock_files(build_metadata_list):
    for build_metadata in build_metadata_list:
        logger.info(f"# Locking dependencies for {build_metadata['name']}")
        create_conda_lock_file(build_metadata)


def get_pip_requirements_content(build_metadata):
    template = environment.from_string(
        """
# DO NOT EDIT: this file is generated from the specification found in the
# following script to centralize the configuration for CI builds:
# build_tools/update_environments_and_lock_files.py
{% for pip_dep in build_metadata['pip_dependencies'] %}
{{ pip_dep | get_package_with_constraint(build_metadata, uses_pip=True) }}
{% endfor %}""".strip()
    )
    return template.render(build_metadata=build_metadata)



Review comment (performance):
Maybe rather than special-casing like this, add a `virtual_package_spec_filename` (or a better name) key in the build dictionary i.e. something like this
```py
build_metadata_list = [
    {
        "name": "pylatest_conda_forge_cuda_array-api_linux-64",
        "type": "conda",
        "tag": "cuda",
        "folder": "build_tools/github",
        "platform": "linux-64",
        "channels": ["conda-forge"],
        "conda_dependencies": common_dependencies
        + [
            "ccache",
            "pytorch-gpu",
            "polars",
            "pyarrow",
            "cupy",
            "array-api-strict",
        ],
        "virtual_package_spec_filename": "build_tools/github/virtual-packages-cuda.yml"
    },
    ...
]


Code after:
        "lock",
        "--mamba",
        "--kind",
        "explicit",
        "--platform",
        platform,
        "--file",
        str(environment_path),
        "--filename-template",
        str(lock_file_path),
    ]
    if virtual_package_spec_path is not None:
        cmd.extend(["--virtual-package-spec", str(virtual_package_spec_path)])

    execute_command(cmd)


def create_conda_lock_file(build_metadata):
    build_name = build_metadata["name"]
    folder_path = Path(build_metadata["folder"])
    environment_path = folder_path / f"{build_name}_environment.yml"
    platform = build_metadata["platform"]
    lock_file_basename = build_name
    if not lock_file_basename.endswith(platform):
        lock_file_basename = f"{lock_file_basename}_{platform}"

    lock_file_path = folder_path / f"{lock_file_basename}_conda.lock"

    virtual_package_spec_path = None
    if build_metadata.get("virtual_package_spec"):
        virtual_package_spec_path = (
            folder_path / f"{lock_file_basename}_virtual_package_spec.yml"
        )

    conda_lock(environment_path, lock_file_path, platform, virtual_package_spec_path)


def write_all_conda_lock_files(build_metadata_list):
    for build_metadata in build_metadata_list:
        logger.info(f"# Locking dependencies for {build_metadata['name']}")
        create_conda_lock_file(build_metadata)


def get_pip_requirements_content(build_metadata):
    template = environment.from_string(
        """
# DO NOT EDIT: this file is generated from the specification found in the
# following script to centralize the configuration for CI builds:
# build_tools/update_environments_and_lock_files.py
{% for pip_dep in build_metadata['pip_dependencies'] %}
{{ pip_dep | get_package_with_constraint(build_metadata, uses_pip=True) }}