diff --git a/.github/workflows/install_from_hub.yml b/.github/workflows/install_from_hub.yml new file mode 100644 index 000000000..c39cc8502 --- /dev/null +++ b/.github/workflows/install_from_hub.yml @@ -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 diff --git a/guardrails/cli/hub/install.py b/guardrails/cli/hub/install.py index 9bb3b45a3..cc7f2fbce 100644 --- a/guardrails/cli/hub/install.py +++ b/guardrails/cli/hub/install.py @@ -1,3 +1,4 @@ +import json import os import subprocess import sys @@ -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 diff --git a/tests/unit_tests/cli/hub/test_install.py b/tests/unit_tests/cli/hub/test_install.py index ede914b60..7590301b3 100644 --- a/tests/unit_tests/cli/hub/test_install.py +++ b/tests/unit_tests/cli/hub/test_install.py @@ -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)