mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-25 12:25:33 +08:00
fix: Fix Ruff PERF403 and add cache_dir validator
- Convert dictionary comprehension in setup.py to fix PERF403 - Add cache_dir validator to normalize paths like config_dir - Follows CodeRabbit review feedback
This commit is contained in:
@ -62,10 +62,11 @@ from langflow.services.deps import (
|
||||
|
||||
def update_projects_components_with_latest_component_versions(project_data, all_types_dict):
|
||||
# Flatten the all_types_dict for easy access
|
||||
all_types_dict_flat = {}
|
||||
for category in all_types_dict.values():
|
||||
for key, component in category.items():
|
||||
all_types_dict_flat[key] = component
|
||||
all_types_dict_flat = {
|
||||
key: component
|
||||
for category in all_types_dict.values()
|
||||
for key, component in category.items()
|
||||
}
|
||||
|
||||
node_changes_log = defaultdict(list)
|
||||
project_data_copy = deepcopy(project_data)
|
||||
|
||||
@ -509,6 +509,26 @@ class Settings(BaseSettings):
|
||||
|
||||
return str(value)
|
||||
|
||||
@field_validator("cache_dir", mode="before")
|
||||
@classmethod
|
||||
def validate_cache_dir(cls, value):
|
||||
"""Validate and normalize cache_dir path.
|
||||
|
||||
If not set, returns None and the factory will fall back to config_dir.
|
||||
If set, resolves to an absolute path and creates the directory if needed.
|
||||
"""
|
||||
if not value:
|
||||
return None
|
||||
|
||||
if isinstance(value, str):
|
||||
value = Path(value)
|
||||
# Resolve to absolute path to handle relative paths correctly
|
||||
value = value.resolve()
|
||||
if not value.exists():
|
||||
value.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
return str(value)
|
||||
|
||||
@field_validator("database_url", mode="before")
|
||||
@classmethod
|
||||
def set_database_url(cls, value, info):
|
||||
|
||||
Reference in New Issue
Block a user