Add uv package manager support and project-level validator registry#1416
Add uv package manager support and project-level validator registry#1416debu-sinha wants to merge 1 commit intoguardrails-ai:v0.9.1from
Conversation
- replace pip import with sysconfig for site-packages discovery - auto-detect uv when available, with GUARDRAILS_INSTALLER env override - add installer_process() that routes to uv pip or pip based on detection - add project-level JSON registry at .guardrails/hub_registry.json - add hub migrate command to convert barrel imports to registry format - update install flow to write registry entries alongside __init__.py Signed-off-by: debu-sinha <debusinha2009@gmail.com>
|
@debu-sinha is attempting to deploy a commit to the Guardrails AI Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey @CalebCourier -- this implements the approach we discussed in #1412. Quick summary of what's here:
This is the "Release A" half -- dual-writes to both barrel and registry, nothing breaks for existing users. Happy to walk through any of it or adjust the approach. |
|
Thanks @debu-sinha! I repointed this from main to a version branch so that I can run our full regression test suite on it after merging [edit] before going to main.[edit] Reviewing in full now. Will keep you updated on the release cycle for this feature. |
There was a problem hiding this comment.
I'm not sure this is worth including for the following reason: In order for a user to run this they would have to update the guardrails-ai package. Upon update, there will not be any entries in their hub/__init__.py. In order to repopulate it, they would need to perform the hub installs again which would automatically populate the new json registry as well.
If there's a scenario I'm not seeing where this would work please let me know but otherwise I think it's worth dropping this from the feature set.
Closes #1412
What changed
This PR adds uv package manager support to Guardrails Hub and introduces a project-level JSON registry as a step toward removing the barrel
__init__.pymutation pattern.Changes
Phase 1 -- uv compatibility (this PR):
importlib.import_module('pip')withsysconfig.get_paths()['purelib']for site-packages discovery -- eliminates the hard dependency on pip being importableshutil.which('uv'), withGUARDRAILS_INSTALLERenv var for explicit override (uvorpip)installer_process()that routes install commands through eitheruv pip installorpython -m pip installinstall_hub_module()to use the detected installerPhase 2a -- project-level registry (this PR):
register_validator()that writes validator metadata to.guardrails/hub_registry.jsonin the project root__init__.py(backward compat) and the new JSON registryguardrails hub migrateCLI command that reads existing barrel imports fromhub/__init__.pyin site-packages and converts them to registry entriesInstaller detection precedence
GUARDRAILS_INSTALLER=uv|pipenv var (explicit override)shutil.which('uv')(auto-detect)Registry format
{ "version": 1, "validators": { "guardrails/detect_pii": { "import_path": "guardrails_grhub_detect_pii", "exports": ["DetectPII"], "installed_at": "2025-01-01T00:00:00+00:00", "package_name": "guardrails-grhub-detect-pii" } } }How is this tested
test_validator_package_service.py(all passing) -- updated existing tests to useinstaller_processmock, added new tests fordetect_installer,get_site_packages_location,register_validator,get_registry_pathtest_installer_process.py(new) -- pip/uv command construction, error handling,NO_COLORenv var, empty package guardtest_migrate.py(new) -- no hub init, empty init, single/multiple validator migration, multi-export lines, comment/blank line handlingMigration path
This is "Release A" of a two-release migration sequence:
hub migrate+ dual-write (registry + barrel). Users can opt in to the registry while barrel stays fully functional.