Skip to content

Commit 9b7cfc3

Browse files
[Fix] #1091. Prevent confusion between guardrails.cli.hub.install and guardrails.hub install. (#1093)
* 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. * Fix typo in docs in install.py. Correct a reference.
1 parent dc8613e commit 9b7cfc3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

guardrails/cli/hub/install.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
from guardrails.cli.version import version_warnings_if_applicable
1111

1212

13-
@hub_command.command()
13+
# Quick note: This is the command for `guardrails hub install`. We change the name of
14+
# the function def to prevent confusion, lest people import it directly and calling it
15+
# with a string for package_uris instead of a list, which behaves oddly. If you need to
16+
# call install from a script, please consider importing install from guardrails,
17+
# not guardrails.cli.hub.install.
18+
@hub_command.command(name="install")
1419
@trace(name="guardrails-cli/hub/install")
15-
def install(
20+
def install_cli(
1621
package_uris: List[str] = typer.Argument(
1722
...,
1823
help="URIs to the packages to install. Example: hub://guardrails/regex_match hub://guardrails/toxic_language",
@@ -33,6 +38,17 @@ def install(
3338
),
3439
):
3540
try:
41+
if isinstance(package_uris, str):
42+
logger.error(
43+
f"`install` in {__file__} was called with a string instead of "
44+
"a list! This can happen if it is invoked directly instead of "
45+
"being run via the CLI. Did you mean to import `from guardrails import "
46+
"install` instead? Recovering..."
47+
)
48+
package_uris = [
49+
package_uris,
50+
]
51+
3652
from guardrails.hub.install import install_multiple
3753

3854
def confirm():

guardrails/hub/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def install(
5353
Examples:
5454
>>> RegexMatch = install("hub://guardrails/regex_match").RegexMatch
5555
56-
>>> install("hub://guardrails/regex_match);
56+
>>> install("hub://guardrails/regex_match")
5757
>>> import guardrails.hub.regex_match as regex_match
5858
"""
5959

0 commit comments

Comments
 (0)