|
15 | 15 | from guardrails.cli.server.hub_client import get_validator_manifest |
16 | 16 | from guardrails.cli.server.module_manifest import ModuleManifest |
17 | 17 |
|
| 18 | +from .console import console |
| 19 | + |
18 | 20 |
|
19 | 21 | def removesuffix(string: str, suffix: str) -> str: |
20 | 22 | if sys.version_info.minor >= 9: |
@@ -199,7 +201,7 @@ def install_hub_module(module_manifest: ModuleManifest, site_packages: str): |
199 | 201 |
|
200 | 202 | # Install validator module in namespaced directory under guardrails.hub |
201 | 203 | download_output = pip_process( |
202 | | - "install", install_url, [f"--target={install_directory}", "--no-deps"] |
| 204 | + "install", install_url, [f"--target={install_directory}", "--no-deps", "-q"] |
203 | 205 | ) |
204 | 206 | logger.info(download_output) |
205 | 207 |
|
@@ -240,28 +242,56 @@ def install( |
240 | 242 | if not package_uri.startswith("hub://"): |
241 | 243 | logger.error("Invalid URI!") |
242 | 244 | sys.exit(1) |
| 245 | + |
| 246 | + console.print(f"\nInstalling {package_uri}...\n") |
243 | 247 | logger.log( |
244 | | - level=LEVELS.get("NOTICE"), msg=f"Installing {package_uri}..." # type: ignore |
| 248 | + level=LEVELS.get("SPAM"), msg=f"Installing {package_uri}..." # type: ignore |
245 | 249 | ) |
| 250 | + |
246 | 251 | # Validation |
247 | 252 | module_name = package_uri.replace("hub://", "") |
248 | 253 |
|
249 | 254 | # Prep |
250 | | - module_manifest = get_validator_manifest(module_name) |
251 | | - site_packages = get_site_packages_location() |
| 255 | + with console.status("Fetching manifest", spinner="bouncingBar"): |
| 256 | + module_manifest = get_validator_manifest(module_name) |
| 257 | + site_packages = get_site_packages_location() |
252 | 258 |
|
253 | 259 | # Install |
254 | | - install_hub_module(module_manifest, site_packages) |
| 260 | + with console.status("Downloading dependencies", spinner="bouncingBar"): |
| 261 | + install_hub_module(module_manifest, site_packages) |
255 | 262 |
|
256 | 263 | # Post-install |
257 | | - run_post_install(module_manifest, site_packages) |
258 | | - add_to_hub_inits(module_manifest, site_packages) |
259 | | - success_message = Template( |
260 | | - """ |
261 | | -
|
262 | | - Successfully installed ${module_name}! |
263 | | -
|
264 | | - See how to use it here: https://hub.guardrailsai.com/validator/${id} |
265 | | - """ |
266 | | - ).safe_substitute(module_name=module_name, id=module_manifest.id) |
267 | | - logger.log(level=LEVELS.get("SUCCESS"), msg=success_message) # type: ignore |
| 264 | + with console.status("Running post-install setup", spinner="bouncingBar"): |
| 265 | + run_post_install(module_manifest, site_packages) |
| 266 | + add_to_hub_inits(module_manifest, site_packages) |
| 267 | + |
| 268 | + success_message_cli = Template( |
| 269 | + """✅Successfully installed ${module_name}! |
| 270 | +
|
| 271 | +[bold]Import validator:[/bold] |
| 272 | +from guardrails.hub import ${export} |
| 273 | +
|
| 274 | +[bold]Get more info:[/bold] |
| 275 | +https://hub.guardrailsai.com/validator/${id} |
| 276 | +""" |
| 277 | + ).safe_substitute( |
| 278 | + module_name=package_uri, |
| 279 | + id=module_manifest.id, |
| 280 | + export=module_manifest.exports[0], |
| 281 | + ) |
| 282 | + success_message_logger = Template( |
| 283 | + """✅Successfully installed ${module_name}! |
| 284 | +
|
| 285 | +Import validator: |
| 286 | +from guardrails.hub import ${export} |
| 287 | +
|
| 288 | +Get more info: |
| 289 | +https://hub.guardrailsai.com/validator/${id} |
| 290 | +""" |
| 291 | + ).safe_substitute( |
| 292 | + module_name=package_uri, |
| 293 | + id=module_manifest.id, |
| 294 | + export=module_manifest.exports[0], |
| 295 | + ) |
| 296 | + console.print(success_message_cli) # type: ignore |
| 297 | + logger.log(level=LEVELS.get("SPAM"), msg=success_message_logger) # type: ignore |
0 commit comments