From f1774c5110445b68f6effc2304ab8e4c55af3b44 Mon Sep 17 00:00:00 2001 From: Scott Lessans <142930063+scott-oai@users.noreply.github.com> Date: Tue, 5 Aug 2025 17:44:04 -0700 Subject: [PATCH] fix ci/pypi (#30) --- README.md | 3 +- _build/gpt_oss_build_backend/backend.py | 140 ++++++++++++++++++++++++ pyproject.toml | 11 +- 3 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 _build/gpt_oss_build_backend/backend.py diff --git a/README.md b/README.md index 3f3f4de..7d4f279 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ If you want to modify the code or try the metal implementation set the project u ```shell git clone https://github.com/openai/gpt-oss.git -pip install -e ".[metal]" +GPTOSS_BUILD_METAL=1 pip install -e ".[metal]" ``` ## Download the model @@ -228,6 +228,7 @@ python gpt_oss/metal/scripts/create-local-model.py -s -d bool: + return str(os.environ.get("GPTOSS_BUILD_METAL", "")).strip() in TRUE_VALUES + + +def _setuptools_backend(): + from setuptools import build_meta as _bm # type: ignore + + return _bm + + +def _scikit_build_backend(): + return import_module("scikit_build_core.build") + + +def _backend(): + return _scikit_build_backend() if _use_metal_backend() else _setuptools_backend() + + +# Required PEP 517 hooks + +def build_wheel( + wheel_directory: str, + config_settings: Mapping[str, Any] | None = None, + metadata_directory: str | None = None, +) -> str: + return _backend().build_wheel(wheel_directory, config_settings, metadata_directory) + + +def build_sdist( + sdist_directory: str, config_settings: Mapping[str, Any] | None = None +) -> str: + return _backend().build_sdist(sdist_directory, config_settings) + + +def prepare_metadata_for_build_wheel( + metadata_directory: str, config_settings: Mapping[str, Any] | None = None +) -> str: + # Fallback if backend doesn't implement it + be = _backend() + fn = getattr(be, "prepare_metadata_for_build_wheel", None) + if fn is None: + # setuptools exposes it; scikit-build-core may not. Defer to building a wheel for metadata. + return _setuptools_backend().prepare_metadata_for_build_wheel( + metadata_directory, config_settings + ) + return fn(metadata_directory, config_settings) + + +# Optional hooks + +def build_editable( + editable_directory: str, config_settings: Mapping[str, Any] | None = None +) -> str: + be = _backend() + fn = getattr(be, "build_editable", None) + if fn is None: + # setuptools implements build_editable; if not available, raise the standard error + raise RuntimeError("Editable installs not supported by the selected backend") + return fn(editable_directory, config_settings) + + +def get_requires_for_build_wheel( + config_settings: Mapping[str, Any] | None = None, +) -> Sequence[str]: + if _use_metal_backend(): + # Add dynamic build requirements only when building the Metal backend + return [ + "scikit-build-core>=0.10", + "pybind11>=2.12", + "cmake>=3.26", + "ninja", + ] + # setuptools usually returns [] + return list(_setuptools_backend().get_requires_for_build_wheel(config_settings)) + + +def get_requires_for_build_sdist( + config_settings: Mapping[str, Any] | None = None, +) -> Sequence[str]: + # No special requirements for SDist + be = _backend() + fn = getattr(be, "get_requires_for_build_sdist", None) + if fn is None: + return [] + return list(fn(config_settings)) + + +def get_requires_for_build_editable( + config_settings: Mapping[str, Any] | None = None, +) -> Sequence[str]: + if _use_metal_backend(): + return [ + "scikit-build-core>=0.10", + "pybind11>=2.12", + "cmake>=3.26", + "ninja", + ] + be = _setuptools_backend() + fn = getattr(be, "get_requires_for_build_editable", None) + if fn is None: + return [] + return list(fn(config_settings)) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 38c4376..b40487a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,19 +23,16 @@ requires-python = ">=3.12,<3.13" version = "0.0.1" [project.optional-dependencies] -triton = [ - "triton", - "safetensors>=0.5.3", - "torch>=2.7.0", -] +triton = ["triton", "safetensors>=0.5.3", "torch>=2.7.0"] torch = ["safetensors>=0.5.3", "torch>=2.7.0"] metal = ["numpy", "tqdm", "safetensors", "torch"] test = ["pytest>=8.4.1", "httpx>=0.28.1"] eval = ["pandas", "numpy", "openai", "jinja2", "tqdm", "blobfile"] [build-system] -requires = ["scikit-build-core>=0.9", "pybind11>=2.12", "cmake>=3.26", "ninja"] -build-backend = "scikit_build_core.build" +requires = ["setuptools>=68"] +build-backend = "gpt_oss_build_backend.backend" +backend-path = ["_build"] [tool.setuptools] packages = ["gpt_oss"]