Skip to content

Commit 12e96e8

Browse files
authored
Merge pull request #689 from guardrails-ai/bug/pip-proc-json-installation
json load pip results, then aggregate if that fails
2 parents 06ca042 + 1569795 commit 12e96e8

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Notebook Execution and Error Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch: # This enables manual triggering
8+
9+
jobs:
10+
install_from_hub:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: 3.11.x
17+
- name: pip install from main
18+
run: pip install git+https://github.com/guardrails-ai/guardrails.git@main
19+
- name: Install PII validator
20+
run: guardrails hub install hub://guardrails/detect_pii
21+
- name: Verify PII validator is addressable
22+
run: echo 'from guardrails.hub import DetectPII' | python

guardrails/cli/hub/install.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import subprocess
34
import sys
@@ -44,6 +45,12 @@ def pip_process(
4445
logger.debug(f"decoding output from pip {action} {package}")
4546
if format == json_format:
4647
parsed = BytesHeaderParser().parsebytes(output)
48+
try:
49+
return json.loads(str(parsed))
50+
except Exception:
51+
logger.debug(
52+
f"json parse exception in decoding output from pip {action} {package}. Falling back to accumulating the byte stream", # noqa
53+
)
4754
accumulator = {}
4855
for key, value in parsed.items():
4956
accumulator[key] = value

tests/unit_tests/cli/hub/test_install.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ def parsebytes(self, *args):
134134

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

137-
assert mock_logger_debug.call_count == 2
137+
assert mock_logger_debug.call_count == 3
138138
debug_calls = [
139139
call("running pip show pip"),
140140
call("decoding output from pip show pip"),
141+
call(
142+
"json parse exception in decoding output from pip show pip. Falling back to accumulating the byte stream" # noqa
143+
),
141144
]
142145
mock_logger_debug.assert_has_calls(debug_calls)
143146

0 commit comments

Comments
 (0)