Skip to content

Commit a46bae6

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Make oss_toplevel/setup.py work with uv-installed Python runtimes
Summary: Telling CMake where to find Python when it's not in a usual spot. Reviewed By: DinoV Differential Revision: D84075975 fbshipit-source-id: c97830f1380fcdad6f81eb4dcc2a78e14a807a00
1 parent 0e70ca7 commit a46bae6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os.path
1212
import shutil
1313
import sys
14+
import sysconfig
1415

1516
from typing import Callable
1617

@@ -130,6 +131,7 @@ def set_option(var: str, default: object) -> None:
130131
# Python version is always the same as what's running setuptools.
131132
py_version = compute_py_version()
132133
options["PY_VERSION"] = py_version
134+
options["Python_ROOT_DIR"] = self._find_python()
133135

134136
meta_python = "+meta" in sys.version
135137
linux = sys.platform == "linux"
@@ -174,6 +176,12 @@ def _find_binary(self, name: str) -> str:
174176
raise RuntimeError(f"Cannot find `{name}` binary")
175177
return result
176178

179+
def _find_python(self) -> str:
180+
# Normally this would use "data", but that goes to a temporary build directory
181+
# under uv. Work off of the include directory instead.
182+
include_dir = sysconfig.get_path("include")
183+
return os.path.join(include_dir, "..", "..")
184+
177185

178186
def main() -> None:
179187
# Native sources.

0 commit comments

Comments
 (0)