Skip to content

Commit 62f347a

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: 09e4bfd Pull-Request: #3310
1 parent 253b8dd commit 62f347a

File tree

9 files changed

+34
-19
lines changed

9 files changed

+34
-19
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

33
pip install --upgrade setuptools
4+
${CONDA_RUN} pip install "pybind11[global]"
5+
${CONDA_RUN} pip install git+https://github.com/pytorch/tensordict.git -U --no-deps
46

57
export TORCHRL_BUILD_VERSION=0.10.0

.github/scripts/td_script.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@
33
export TORCHRL_BUILD_VERSION=0.10.0
44
pip install --upgrade setuptools
55

6+
# Always install pybind11 - required for building C++ extensions
7+
${CONDA_RUN} pip install "pybind11[global]"
8+
69
# Check if ARCH is set to aarch64
710
ARCH=${ARCH:-} # This sets ARCH to an empty string if it's not defined
811

912
if pip list | grep -q torch; then
1013
echo "Torch is installed."
11-
12-
# ${CONDA_RUN} conda install 'anaconda::cmake>=3.22' -y
13-
14-
${CONDA_RUN} pip install "pybind11[global]"
15-
1614
${CONDA_RUN} pip install git+https://github.com/pytorch/tensordict.git -U --no-deps
1715
elif [[ -n "${SMOKE_TEST_SCRIPT:-}" ]]; then
1816
${CONDA_RUN} ${PIP_INSTALL_TORCH}
19-
# TODO: revert when nightlies of tensordict are fixed
20-
# if [[ "$ARCH" == "aarch64" ]]; then
21-
22-
23-
# ${CONDA_RUN} conda install 'anaconda::cmake>=3.22' -y
24-
25-
${CONDA_RUN} pip install "pybind11[global]"
26-
2717
${CONDA_RUN} pip install git+https://github.com/pytorch/tensordict.git -U --no-deps
2818
else
2919
echo "Torch is not installed - tensordict will be installed later."

.github/unittest/linux_olddeps/scripts_gym_0_13/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ dependencies:
2828
- av
2929
- h5py
3030
- numpy<2.0.0
31+
- pybind11[global]

build_nightly.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ echo "Installing build dependencies..."
5656
PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
5757
if python -c "import sys; exit(0 if sys.version_info < (3, 11) else 1)"; then
5858
echo "Using setuptools 65.3.0 for Python $PYTHON_VERSION (compatibility mode)"
59-
python -m pip install wheel setuptools==65.3.0
59+
python -m pip install wheel setuptools==65.3.0 "pybind11[global]"
6060
else
6161
echo "Using latest setuptools for Python $PYTHON_VERSION (modern mode)"
62-
python -m pip install wheel setuptools
62+
python -m pip install wheel setuptools "pybind11[global]"
6363
fi
6464

6565
python setup.py bdist_wheel

setup.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@
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+
26+
Only checks when actually building extensions, not for commands like 'clean'.
27+
"""
28+
# Commands that don't require building C++ extensions
29+
skip_commands = {"clean", "egg_info", "sdist", "--version", "--help", "-h"}
30+
if skip_commands.intersection(sys.argv):
31+
return
32+
if importlib.util.find_spec("pybind11") is None:
33+
raise RuntimeError(
34+
"pybind11 is required to build TorchRL's C++ extensions but was not found.\n"
35+
"Please install it with:\n"
36+
" pip install 'pybind11[global]'\n"
37+
"Then re-run the installation."
38+
)
39+
40+
41+
_check_pybind11()
2142
_RELEASE_BRANCH_RE = re.compile(r"^release/v(?P<release_id>.+)$")
2243
_BUILD_INFO_FILE = ROOT_DIR / "build" / ".torchrl_build_info.json"
2344

@@ -47,13 +68,14 @@ def _check_and_clean_stale_builds():
4768
f"Python {old_python} -> {current_python_version}. "
4869
f"Cleaning stale build artifacts..."
4970
)
50-
# Clean stale .so files for current Python version
51-
so_pattern = (
71+
# Clean stale extension files for current Python version
72+
ext = ".pyd" if sys.platform == "win32" else ".so"
73+
ext_pattern = (
5274
ROOT_DIR
5375
/ "torchrl"
54-
/ f"_torchrl.cpython-{sys.version_info.major}{sys.version_info.minor}*.so"
76+
/ f"_torchrl.cpython-{sys.version_info.major}{sys.version_info.minor}*{ext}"
5577
)
56-
for so_file in glob.glob(str(so_pattern)):
78+
for so_file in glob.glob(str(ext_pattern)):
5779
logger.warning(f"Removing stale: {so_file}")
5880
os.remove(so_file)
5981
# Clean build directory

0 commit comments

Comments
 (0)