|
17 | 17 |
|
18 | 18 | import pytest |
19 | 19 |
|
| 20 | +import isaaclab.cli.commands.install as install_cmd |
20 | 21 | from isaaclab.cli.commands.install import ( |
21 | 22 | _PREBUNDLE_REPOINT_PACKAGES, |
22 | 23 | _ensure_cuda_torch, |
@@ -68,6 +69,167 @@ def _make_site_packages( |
68 | 69 | return site_pkgs |
69 | 70 |
|
70 | 71 |
|
| 72 | +# --------------------------------------------------------------------------- |
| 73 | +# _install_isaaclab_submodules targeted dependency upgrades |
| 74 | +# --------------------------------------------------------------------------- |
| 75 | + |
| 76 | + |
| 77 | +class TestInstallSubmodulesTargetedDependencyUpgrades: |
| 78 | + """Tests for extension.toml-driven dependency upgrades.""" |
| 79 | + |
| 80 | + def _make_extension(self, tmp_path, extension_toml: str) -> Path: |
| 81 | + """Create a minimal installable extension fixture.""" |
| 82 | + source_dir = tmp_path / "source" |
| 83 | + extension_dir = source_dir / "isaaclab_teleop" |
| 84 | + config_dir = extension_dir / "config" |
| 85 | + config_dir.mkdir(parents=True) |
| 86 | + (extension_dir / "setup.py").write_text("# test fixture\n", encoding="utf-8") |
| 87 | + (config_dir / "extension.toml").write_text(extension_toml, encoding="utf-8") |
| 88 | + return extension_dir |
| 89 | + |
| 90 | + def test_installs_editable_then_upgrades_declared_dependency_from_metadata(self, tmp_path): |
| 91 | + """An opted-in dependency is upgraded using the requirement recorded in installed metadata.""" |
| 92 | + extension_dir = self._make_extension( |
| 93 | + tmp_path, |
| 94 | + '[isaac_lab_settings]\npip_upgrade_dependencies = ["isaacteleop"]\n', |
| 95 | + ) |
| 96 | + |
| 97 | + python_exe = str(tmp_path / "python") |
| 98 | + pip_cmd = [python_exe, "-m", "pip"] |
| 99 | + isaacteleop_req = 'isaacteleop[cloudxr,retargeters,ui] ~=1.2.0; platform_system == "Linux"' |
| 100 | + |
| 101 | + with ( |
| 102 | + mock.patch("isaaclab.cli.commands.install.ISAACLAB_ROOT", tmp_path), |
| 103 | + mock.patch("isaaclab.cli.commands.install.extract_python_exe", return_value=python_exe), |
| 104 | + mock.patch("isaaclab.cli.commands.install.get_pip_command", return_value=pip_cmd), |
| 105 | + mock.patch( |
| 106 | + "isaaclab.cli.commands.install._get_installed_distribution_requirements", |
| 107 | + return_value=[isaacteleop_req], |
| 108 | + ), |
| 109 | + mock.patch("isaaclab.cli.commands.install.run_command") as mock_run, |
| 110 | + ): |
| 111 | + install_cmd._install_isaaclab_submodules(["isaaclab_teleop"]) |
| 112 | + |
| 113 | + assert [call.args[0] for call in mock_run.call_args_list] == [ |
| 114 | + pip_cmd + ["install", "--editable", str(extension_dir)], |
| 115 | + pip_cmd + ["install", "--upgrade", isaacteleop_req], |
| 116 | + ] |
| 117 | + |
| 118 | + def test_uv_install_uses_upgrade_package_for_declared_dependency(self, tmp_path): |
| 119 | + """uv upgrades only the declared package rather than using a global upgrade.""" |
| 120 | + extension_dir = self._make_extension( |
| 121 | + tmp_path, |
| 122 | + '[isaac_lab_settings]\npip_upgrade_dependencies = ["isaacteleop"]\n', |
| 123 | + ) |
| 124 | + |
| 125 | + python_exe = str(tmp_path / "python") |
| 126 | + pip_cmd = ["uv", "pip"] |
| 127 | + isaacteleop_req = 'isaacteleop[cloudxr,retargeters,ui] ~=1.2.0; platform_system == "Linux"' |
| 128 | + |
| 129 | + with ( |
| 130 | + mock.patch("isaaclab.cli.commands.install.ISAACLAB_ROOT", tmp_path), |
| 131 | + mock.patch("isaaclab.cli.commands.install.extract_python_exe", return_value=python_exe), |
| 132 | + mock.patch("isaaclab.cli.commands.install.get_pip_command", return_value=pip_cmd), |
| 133 | + mock.patch( |
| 134 | + "isaaclab.cli.commands.install._get_installed_distribution_requirements", |
| 135 | + return_value=[isaacteleop_req], |
| 136 | + ), |
| 137 | + mock.patch("isaaclab.cli.commands.install.run_command") as mock_run, |
| 138 | + ): |
| 139 | + install_cmd._install_isaaclab_submodules(["isaaclab_teleop"]) |
| 140 | + |
| 141 | + assert [call.args[0] for call in mock_run.call_args_list] == [ |
| 142 | + pip_cmd + ["install", "--editable", str(extension_dir)], |
| 143 | + pip_cmd + ["install", "--upgrade-package", "isaacteleop", isaacteleop_req], |
| 144 | + ] |
| 145 | + |
| 146 | + def test_upgrades_all_matching_metadata_requirements(self, tmp_path): |
| 147 | + """Duplicate metadata entries are preserved instead of collapsing to one requirement.""" |
| 148 | + python_exe = str(tmp_path / "python") |
| 149 | + pip_cmd = [python_exe, "-m", "pip"] |
| 150 | + linux_req = 'example-package>=1.0; platform_system == "Linux"' |
| 151 | + windows_req = 'example_package>=2.0; platform_system == "Windows"' |
| 152 | + |
| 153 | + with ( |
| 154 | + mock.patch( |
| 155 | + "isaaclab.cli.commands.install._get_installed_distribution_requirements", |
| 156 | + return_value=[linux_req, windows_req], |
| 157 | + ), |
| 158 | + mock.patch("isaaclab.cli.commands.install.run_command") as mock_run, |
| 159 | + ): |
| 160 | + install_cmd._upgrade_extension_pip_dependencies( |
| 161 | + python_exe, |
| 162 | + pip_cmd, |
| 163 | + "isaaclab_teleop", |
| 164 | + ["example-package"], |
| 165 | + ) |
| 166 | + |
| 167 | + assert [call.args[0] for call in mock_run.call_args_list] == [ |
| 168 | + pip_cmd + ["install", "--upgrade", linux_req], |
| 169 | + pip_cmd + ["install", "--upgrade", windows_req], |
| 170 | + ] |
| 171 | + |
| 172 | + def test_skips_duplicate_declared_dependency_names(self, tmp_path): |
| 173 | + """Duplicate TOML dependency names do not trigger duplicate pip commands.""" |
| 174 | + python_exe = str(tmp_path / "python") |
| 175 | + pip_cmd = [python_exe, "-m", "pip"] |
| 176 | + req = "isaacteleop~=1.2.0" |
| 177 | + |
| 178 | + with ( |
| 179 | + mock.patch( |
| 180 | + "isaaclab.cli.commands.install._get_installed_distribution_requirements", |
| 181 | + return_value=[req], |
| 182 | + ), |
| 183 | + mock.patch("isaaclab.cli.commands.install.run_command") as mock_run, |
| 184 | + ): |
| 185 | + install_cmd._upgrade_extension_pip_dependencies( |
| 186 | + python_exe, |
| 187 | + pip_cmd, |
| 188 | + "isaaclab_teleop", |
| 189 | + ["isaacteleop", "IsaacTeleop"], |
| 190 | + ) |
| 191 | + |
| 192 | + mock_run.assert_called_once_with(pip_cmd + ["install", "--upgrade", req]) |
| 193 | + |
| 194 | + def test_skips_when_toml_has_no_upgrade_dependencies(self, tmp_path): |
| 195 | + """Extensions without pip upgrade opt-ins do not trigger metadata probes.""" |
| 196 | + extension_dir = self._make_extension(tmp_path, "[isaac_lab_settings]\n") |
| 197 | + |
| 198 | + assert install_cmd._get_extension_pip_upgrade_dependencies(extension_dir) == [] |
| 199 | + |
| 200 | + def test_warns_and_skips_invalid_upgrade_dependency_names(self, tmp_path): |
| 201 | + """Invalid TOML value types warn and disable targeted upgrades.""" |
| 202 | + extension_dir = self._make_extension( |
| 203 | + tmp_path, |
| 204 | + '[isaac_lab_settings]\npip_upgrade_dependencies = "isaacteleop"\n', |
| 205 | + ) |
| 206 | + |
| 207 | + with mock.patch("isaaclab.cli.commands.install.print_warning") as mock_warning: |
| 208 | + assert install_cmd._get_extension_pip_upgrade_dependencies(extension_dir) == [] |
| 209 | + |
| 210 | + mock_warning.assert_called_once() |
| 211 | + |
| 212 | + def test_warns_when_declared_dependency_missing_from_metadata(self, tmp_path): |
| 213 | + """A declared dependency name must exist in installed package metadata.""" |
| 214 | + with ( |
| 215 | + mock.patch( |
| 216 | + "isaaclab.cli.commands.install._get_installed_distribution_requirements", |
| 217 | + return_value=["dex-retargeting==0.5.0"], |
| 218 | + ), |
| 219 | + mock.patch("isaaclab.cli.commands.install.print_warning") as mock_warning, |
| 220 | + mock.patch("isaaclab.cli.commands.install.run_command") as mock_run, |
| 221 | + ): |
| 222 | + install_cmd._upgrade_extension_pip_dependencies( |
| 223 | + str(tmp_path / "python"), |
| 224 | + [str(tmp_path / "python"), "-m", "pip"], |
| 225 | + "isaaclab_teleop", |
| 226 | + ["isaacteleop"], |
| 227 | + ) |
| 228 | + |
| 229 | + mock_warning.assert_called_once() |
| 230 | + mock_run.assert_not_called() |
| 231 | + |
| 232 | + |
71 | 233 | # --------------------------------------------------------------------------- |
72 | 234 | # _torch_first_on_sys_path_is_prebundle |
73 | 235 | # --------------------------------------------------------------------------- |
|
0 commit comments