Skip to content

Commit d9c23d1

Browse files
committed
json load pip results, then aggregate if that fails
1 parent 24383b9 commit d9c23d1

File tree

3 files changed

+32
-1
lines changed

3 files changed

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

guardrails/cli/hub/install.py

Lines changed: 8 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,13 @@ 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 as e:
51+
logger.debug(
52+
f"json parse exception in decoding output from pip {action} {package}. Falling back to accumulating the byte stream", # noqa
53+
e,
54+
)
4755
accumulator = {}
4856
for key, value in parsed.items():
4957
accumulator[key] = value

tests/unit_tests/cli/hub/test_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ 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"),

0 commit comments

Comments
 (0)