Skip to content

Commit

Permalink
Merge pull request #689 from guardrails-ai/bug/pip-proc-json-installa…
Browse files Browse the repository at this point in the history
…tion

json load pip results, then aggregate if that fails
  • Loading branch information
CalebCourier authored Apr 4, 2024
2 parents 06ca042 + 1569795 commit 12e96e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/install_from_hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Notebook Execution and Error Check

on:
push:
branches:
- main
workflow_dispatch: # This enables manual triggering

jobs:
install_from_hub:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.x
- name: pip install from main
run: pip install git+https://github.com/guardrails-ai/guardrails.git@main
- name: Install PII validator
run: guardrails hub install hub://guardrails/detect_pii
- name: Verify PII validator is addressable
run: echo 'from guardrails.hub import DetectPII' | python
7 changes: 7 additions & 0 deletions guardrails/cli/hub/install.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import subprocess
import sys
Expand Down Expand Up @@ -44,6 +45,12 @@ def pip_process(
logger.debug(f"decoding output from pip {action} {package}")
if format == json_format:
parsed = BytesHeaderParser().parsebytes(output)
try:
return json.loads(str(parsed))
except Exception:
logger.debug(
f"json parse exception in decoding output from pip {action} {package}. Falling back to accumulating the byte stream", # noqa
)
accumulator = {}
for key, value in parsed.items():
accumulator[key] = value
Expand Down
5 changes: 4 additions & 1 deletion tests/unit_tests/cli/hub/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ def parsebytes(self, *args):

response = pip_process("show", "pip", format="json")

assert mock_logger_debug.call_count == 2
assert mock_logger_debug.call_count == 3
debug_calls = [
call("running pip show pip"),
call("decoding output from pip show pip"),
call(
"json parse exception in decoding output from pip show pip. Falling back to accumulating the byte stream" # noqa
),
]
mock_logger_debug.assert_has_calls(debug_calls)

Expand Down

0 comments on commit 12e96e8

Please sign in to comment.