File tree Expand file tree Collapse file tree 5 files changed +7
-15
lines changed
Expand file tree Collapse file tree 5 files changed +7
-15
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,6 @@ def list():
1010 """List all installed validators."""
1111 registry = get_registry ()
1212
13- if not registry :
14- console .print ("No validators installed." )
15- return
16-
1713 validators = registry .validators
1814 if not validators :
1915 console .print ("No validators installed." )
Original file line number Diff line number Diff line change @@ -19,8 +19,6 @@ def _build_export_map() -> dict:
1919 module import paths (e.g. "guardrails_grhub_detect_pii").
2020 """
2121 registry = get_registry ()
22- if not registry :
23- return {}
2422 export_map = {}
2523 for entry in registry .validators .values ():
2624 import_path = entry .import_path
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def get_registry_path() -> Path:
1111 return Path (os .getcwd ()) / ".guardrails" / "hub_registry.json"
1212
1313
14- def get_registry () -> ValidatorRegistry | None :
14+ def get_registry () -> ValidatorRegistry :
1515 registry_file = get_registry_path ()
1616 try :
1717 registry_str = registry_file .read_text ()
@@ -20,4 +20,4 @@ def get_registry() -> ValidatorRegistry | None:
2020 return registry
2121 except (json .JSONDecodeError , OSError ):
2222 logger .warning ("Failed to read hub registry at %s" , registry_file )
23- return None
23+ return ValidatorRegistry ()
Original file line number Diff line number Diff line change @@ -11,5 +11,5 @@ class ValidatorRegistryEntry(BaseModel):
1111
1212
1313class ValidatorRegistry (BaseModel ):
14- version : int
15- validators : dict [str , ValidatorRegistryEntry ]
14+ version : int = Field ( default = 1 )
15+ validators : dict [str , ValidatorRegistryEntry ] = Field ( default_factory = dict )
Original file line number Diff line number Diff line change @@ -572,11 +572,9 @@ def decorator(
572572def try_to_import_from_hub (validator_key : str ):
573573 try :
574574 hub_registry = get_registry ()
575- if not hub_registry :
576- return
577- import_path = hub_registry .validators [validator_key ].import_path
578- if import_path :
579- importlib .import_module (import_path )
575+ validator_entry = hub_registry .validators .get (validator_key )
576+ if validator_entry and validator_entry .import_path :
577+ importlib .import_module (validator_entry .import_path )
580578 except (ImportError , KeyError ):
581579 logger .error ("Could not import from hub. Validators may not work properly." )
582580
You can’t perform that action at this time.
0 commit comments