Skip to content

Commit fca5dd8

Browse files
committed
[BugFix] Add pybind11 check and Windows extension pattern fix
- Add early check for pybind11 dependency with clear error message - Fix extension file pattern for Windows (.pyd) vs Unix (.so) in stale build cleanup ghstack-source-id: 5f551cf Pull-Request: #3310
1 parent cc917ba commit fca5dd8

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

setup.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818
logger = logging.getLogger(__name__)
1919

2020
ROOT_DIR = Path(__file__).parent.resolve()
21+
22+
23+
def _check_pybind11():
24+
"""Check that pybind11 is installed and provide a clear error message if not."""
25+
if importlib.util.find_spec("pybind11") is None:
26+
raise RuntimeError(
27+
"pybind11 is required to build TorchRL's C++ extensions but was not found.\n"
28+
"Please install it with:\n"
29+
" pip install 'pybind11[global]'\n"
30+
"Then re-run the installation."
31+
)
32+
33+
34+
_check_pybind11()
2135
_RELEASE_BRANCH_RE = re.compile(r"^release/v(?P<release_id>.+)$")
2236
_BUILD_INFO_FILE = ROOT_DIR / "build" / ".torchrl_build_info.json"
2337

@@ -47,13 +61,14 @@ def _check_and_clean_stale_builds():
4761
f"Python {old_python} -> {current_python_version}. "
4862
f"Cleaning stale build artifacts..."
4963
)
50-
# Clean stale .so files for current Python version
51-
so_pattern = (
64+
# Clean stale extension files for current Python version
65+
ext = ".pyd" if sys.platform == "win32" else ".so"
66+
ext_pattern = (
5267
ROOT_DIR
5368
/ "torchrl"
54-
/ f"_torchrl.cpython-{sys.version_info.major}{sys.version_info.minor}*.so"
69+
/ f"_torchrl.cpython-{sys.version_info.major}{sys.version_info.minor}*{ext}"
5570
)
56-
for so_file in glob.glob(str(so_pattern)):
71+
for so_file in glob.glob(str(ext_pattern)):
5772
logger.warning(f"Removing stale: {so_file}")
5873
os.remove(so_file)
5974
# Clean build directory

0 commit comments

Comments
 (0)