From ab4550a90a86d09f38117a14a5450c271f31134a Mon Sep 17 00:00:00 2001 From: Joseph Catrambone Date: Wed, 25 Sep 2024 11:19:32 -0700 Subject: [PATCH 1/2] Fix for #1091. Make the install CLI function named install_cli (but keep the invocation as guardrails hub install) so people don't import it by mistake. Add warning for string passage. --- guardrails/cli/hub/install.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/guardrails/cli/hub/install.py b/guardrails/cli/hub/install.py index 1a0cb5e16..1e0ca4553 100644 --- a/guardrails/cli/hub/install.py +++ b/guardrails/cli/hub/install.py @@ -10,9 +10,14 @@ from guardrails.cli.version import version_warnings_if_applicable -@hub_command.command() +# Quick note: This is the command for `guardrails hub install`. We change the name of +# the function def to prevent confusion, lest people import it directly and calling it +# with a string for package_uris instead of a list, which behaves oddly. If you need to +# call install from a script, please consider importing install from guardrails.hub, +# not guardrails.cli.hub.install. +@hub_command.command(name="install") @trace(name="guardrails-cli/hub/install") -def install( +def install_cli( package_uris: List[str] = typer.Argument( ..., help="URIs to the packages to install. Example: hub://guardrails/regex_match hub://guardrails/toxic_language", @@ -33,6 +38,17 @@ def install( ), ): try: + if isinstance(package_uris, str): + logger.error( + f"`install` in {__file__} was called with a string instead of " + "a list! This can happen if it is invoked directly instead of " + "being run via the CLI. Did you mean to import `from " + "guardrails.hub import install` instead? Recovering..." + ) + package_uris = [ + package_uris, + ] + from guardrails.hub.install import install_multiple def confirm(): From 9837c4a1580bef40526094226fcc66f8ecede8d8 Mon Sep 17 00:00:00 2001 From: Joseph Catrambone Date: Wed, 25 Sep 2024 12:00:11 -0700 Subject: [PATCH 2/2] Fix typo in docs in install.py. Correct a reference. --- guardrails/cli/hub/install.py | 6 +++--- guardrails/hub/install.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/guardrails/cli/hub/install.py b/guardrails/cli/hub/install.py index 1e0ca4553..4c492e1f2 100644 --- a/guardrails/cli/hub/install.py +++ b/guardrails/cli/hub/install.py @@ -13,7 +13,7 @@ # Quick note: This is the command for `guardrails hub install`. We change the name of # the function def to prevent confusion, lest people import it directly and calling it # with a string for package_uris instead of a list, which behaves oddly. If you need to -# call install from a script, please consider importing install from guardrails.hub, +# call install from a script, please consider importing install from guardrails, # not guardrails.cli.hub.install. @hub_command.command(name="install") @trace(name="guardrails-cli/hub/install") @@ -42,8 +42,8 @@ def install_cli( logger.error( f"`install` in {__file__} was called with a string instead of " "a list! This can happen if it is invoked directly instead of " - "being run via the CLI. Did you mean to import `from " - "guardrails.hub import install` instead? Recovering..." + "being run via the CLI. Did you mean to import `from guardrails import " + "install` instead? Recovering..." ) package_uris = [ package_uris, diff --git a/guardrails/hub/install.py b/guardrails/hub/install.py index 046ee073f..677e7c392 100644 --- a/guardrails/hub/install.py +++ b/guardrails/hub/install.py @@ -53,7 +53,7 @@ def install( Examples: >>> RegexMatch = install("hub://guardrails/regex_match").RegexMatch - >>> install("hub://guardrails/regex_match); + >>> install("hub://guardrails/regex_match") >>> import guardrails.hub.regex_match as regex_match """