fix: update LANGFLOW_COMPONENTS_PATH env variable behavior (#5700)

* Refactor directory_reader.py to simplify file filtering logic

* Refactor flowSidebarComponent to filter out bundles and custom components in CategoryGroup

* [autofix.ci] apply automated fixes

* refactor: Improve file filtering in DirectoryReader

This commit improves the file filtering logic in the DirectoryReader class. Previously, it only excluded files that started with "__" and included all files that were not in a "deactivated" directory. Now, it also considers the depth of the file relative to the safe path. Only files that are one or two levels deep are included in the file list.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
anovazzi1 2025-01-20 22:47:19 -03:00 committed by GitHub
commit dbd2bd9375
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 58 deletions

View file

@ -9,6 +9,8 @@ from loguru import logger
from langflow.custom import Component
MAX_DEPTH = 2
class CustomComponentPathValueError(ValueError):
pass
@ -135,12 +137,11 @@ class DirectoryReader:
if "deactivated" in file_path.parent.name:
continue
# The other condtion is that it should be
# in the safe_path/[folder]/[file].py format
# any folders below [folder] will be ignored
# basically the parent folder of the file should be a
# folder in the safe_path
if file_path.is_file() and file_path.parent.parent == safe_path_obj and not file_path.name.startswith("__"):
# Calculate the depth of the file relative to the safe path
relative_depth = len(file_path.relative_to(safe_path_obj).parts)
# Only include files that are one or two levels deep
if relative_depth <= MAX_DEPTH and file_path.is_file() and not file_path.name.startswith("__"):
file_list.append(str(file_path))
return file_list