feat: Allow variables to be defined outside a Component (#4316)

* feat: Allow variables to be defined outside a Component

Fixes #4315

Modify `prepare_global_scope` function in `src/backend/base/langflow/utils/validate.py` to evaluate classes, functions, and variables defined outside the Component's class.

* **Function Changes:**
  - Add evaluation of external classes using `ast.ClassDef`.
  - Add evaluation of external functions using `ast.FunctionDef`.
  - Add evaluation of external variables using `ast.Assign`.

* **Unit Tests:**
  - Add tests in `src/backend/tests/unit/test_validate_code.py` to verify the evaluation of external classes, functions, and variables.
  - Include tests for multiple external classes and external variables and functions.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4315?shareId=XXXX-XXXX-XXXX-XXXX).

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-10-29 10:45:38 -03:00 committed by GitHub
commit ccba14bec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 84 additions and 1 deletions

View file

@ -34,6 +34,9 @@
"GitHub.vscode-pull-request-github"
]
}
},
"tasks": {
"test": "make unit_tests"
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.