-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Enterprise Flask Migration Toolkit #7264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
BorisQuanLi
wants to merge
20
commits into
OpenBB-finance:develop
Choose a base branch
from
BorisQuanLi:feature/flask-to-openbb-converter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+494
−4
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f0eaf3e
feat: Add Flask-to-OpenBB enterprise migration toolkit
BorisQuanLi 90d3398
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone 0e51587
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone e405dc4
chore: Resolve .gitignore conflict and add common ignores
BorisQuanLi b1b09ed
refactor: implement Phase 1 Flask integration architecture- Move Flas…
BorisQuanLi 6aa6d07
docs: add Flask direct entry point demos- demo_direct_flask_entry_poi…
BorisQuanLi 3c4f7be
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone 8ee2b33
Implement Phase 1 Flask adapter per code review feedback
BorisQuanLi 475afab
Merge branch 'feature/flask-to-openbb-converter' of https://github.co…
deeleeramone 9a55fa7
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone a31dc76
Fix Flask integration: Replace missing FlaskToOpenBBAdapter with WSGI…
BorisQuanLi 45898d1
Merge branch 'feature/flask-to-openbb-converter' of https://github.co…
deeleeramone 501572d
fix merge conflict
deeleeramone fce6a7f
Address PR review feedback: fix Flask imports and remove unused files
BorisQuanLi 97d133c
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone ab30f3d
Force APIRouter.include_router to propagate Mount paths instead of dr…
deeleeramone 36cfd27
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone 8163d90
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone 1ab2c9d
Merge branch 'develop' into feature/flask-to-openbb-converter
deeleeramone 5ceedad
feat(flask): Add metadata layer for OpenAPI documentation
BorisQuanLi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
openbb_platform/core/openbb_core/app/utils/flask/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Flask integration utilities for OpenBB Core. | ||
| This module provides Flask app integration capabilities. | ||
| All imports are lazy to avoid ImportError when Flask is not installed. | ||
| """ | ||
|
|
||
|
|
||
| def __getattr__(name: str): | ||
| """Lazy import to avoid ImportError when Flask is not installed.""" | ||
| if name == "FlaskExtensionLoader": | ||
| from .loader import FlaskExtensionLoader | ||
|
|
||
| return FlaskExtensionLoader | ||
| if name == "FlaskIntrospector": | ||
| from .introspection import FlaskIntrospector | ||
|
|
||
| return FlaskIntrospector | ||
| if name == "_check_flask_available": | ||
| from .introspection import _check_flask_available | ||
|
|
||
| return _check_flask_available | ||
| raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | ||
|
|
||
|
|
||
| __all__ = ["FlaskIntrospector", "FlaskExtensionLoader", "_check_flask_available"] |
47 changes: 47 additions & 0 deletions
47
openbb_platform/core/openbb_core/app/utils/flask/adapter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Flask-to-OpenBB conversion logic.""" | ||
|
|
||
| from typing import Any | ||
| from openbb_core.app.router import Router | ||
| from openbb_core.app.model.obbject import OBBject | ||
| from .introspection import FlaskIntrospector | ||
|
|
||
| def is_flask_available() -> bool: | ||
| """Check if Flask is available.""" | ||
| try: | ||
| import flask | ||
| return True | ||
| except ImportError: | ||
| return False | ||
|
|
||
| def create_flask_router(flask_app: Any, prefix: str = "/flask") -> Router: | ||
| """Create OpenBB router from Flask app with metadata layer.""" | ||
| if not is_flask_available(): | ||
| raise ImportError("Flask is not available") | ||
|
|
||
| router = Router(prefix=prefix) | ||
| introspector = FlaskIntrospector(flask_app) | ||
| routes = introspector.analyze_routes() | ||
|
|
||
| for route_info in routes: | ||
| _add_flask_route_to_router(router, route_info, flask_app) | ||
|
|
||
| return router | ||
|
|
||
| def _add_flask_route_to_router(router: Router, route_info: dict, flask_app: Any) -> None: | ||
| """Add a Flask route to OpenBB router with metadata.""" | ||
| docstring_info = route_info.get('docstring_info', {}) | ||
|
|
||
| def flask_wrapper(**kwargs) -> OBBject: | ||
| with flask_app.test_client() as client: | ||
| response = client.get(route_info['rule'], query_string=kwargs) | ||
| return OBBject(results=response.get_json()) | ||
|
|
||
| flask_wrapper.__name__ = route_info['openbb_command_name'] | ||
| flask_wrapper.__doc__ = route_info.get('docstring', '') | ||
|
|
||
| router.command( | ||
| flask_wrapper, | ||
| methods=['GET'], | ||
| summary=docstring_info.get('summary'), | ||
| description=docstring_info.get('description'), | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually want to do this. We have the mounted WSGI application, we don't want to create a new object and replace it, the wrapper already exists as the Middleware.