-
Notifications
You must be signed in to change notification settings - Fork 130
Merge conflicts and PEP build fixed #565
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57bcf09
FEAT: Add prototype of dynamic routes in hydrus
sameshl 5cbe4ad
Fix PEP8 compliance
sameshl 735712d
PEP fix
Purvanshsingh bbf8b6d
PEP fix 2
Purvanshsingh 1b6b41f
Merge branch 'develop' into merge_conflict
Mec-iS 5396bfe
Merge branch 'develop' into merge_conflict
Mec-iS 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,36 @@ | ||
| """Main route for the application""" | ||
|
|
||
| import logging | ||
| import sys | ||
| from hydrus.socketio_factory import create_socket | ||
| from os.path import dirname, abspath | ||
|
|
||
| from sqlalchemy import create_engine | ||
| # insert the ./app.py file path in the PYTHONPATH variable for imports to work | ||
| sys.path.insert(0, dirname(dirname(abspath(__file__)))) | ||
|
|
||
| from gevent.pywsgi import WSGIServer | ||
| from sqlalchemy.orm import sessionmaker | ||
| # ignoring import error by flake 8 temporarily | ||
| # for setting PYTHONPATH before imports | ||
| from sqlalchemy import create_engine # noqa: E402 | ||
| from flask import request # noqa: E402 | ||
| from collections import defaultdict # noqa: E402 | ||
| from gevent.pywsgi import WSGIServer # noqa: E402 | ||
| from sqlalchemy.orm import sessionmaker # noqa: E402 | ||
|
|
||
| from hydrus.app_factory import app_factory | ||
| from hydrus.app_factory import app_factory # noqa: E402 | ||
| from hydrus.conf import ( | ||
| HYDRUS_SERVER_URL, API_NAME, DB_URL, APIDOC_OBJ, PORT, DEBUG) | ||
| from hydrus.data import doc_parse | ||
| from hydrus.data.db_models import Base, create_database_tables | ||
| from hydrus.data.exceptions import UserExists | ||
| from hydrus.data.user import add_user | ||
| from hydra_python_core import doc_maker | ||
| HYDRUS_SERVER_URL, API_NAME, | ||
| DB_URL, APIDOC_OBJ, PORT) # noqa: E402 | ||
| from hydrus.data import doc_parse # noqa: E402 | ||
| from hydrus.data.db_models import Base # noqa: E402 | ||
| from hydrus.data.exceptions import UserExists # noqa: E402 | ||
| from hydrus.data.user import add_user # noqa: E402 | ||
| from hydra_python_core import doc_maker # noqa: E402 | ||
| from hydrus.utils import ( | ||
| set_session, set_doc, set_hydrus_server_url, | ||
| set_token, set_api_name, set_authentication) | ||
| from hydrus.socketio_factory import create_socket | ||
| set_token, set_api_name, set_authentication) # noqa: E402 | ||
|
|
||
| logger = logging.getLogger(__file__) | ||
|
|
||
| # TODO: loading the engine and creating the tables should be handled better | ||
| engine = create_engine(DB_URL) | ||
| session = sessionmaker(bind=engine)() | ||
|
|
||
|
|
@@ -33,7 +41,6 @@ | |
| classes = doc_parse.get_classes(apidoc) | ||
| try: | ||
| Base.metadata.drop_all(engine) | ||
| create_database_tables(classes) | ||
| Base.metadata.create_all(engine) | ||
| except Exception: | ||
| pass | ||
|
|
@@ -50,6 +57,43 @@ | |
| # Create a Hydrus app | ||
| app = app_factory(API_NAME) | ||
| socketio = create_socket(app, session) | ||
|
|
||
| # global dict to store mapping of each function to be run before | ||
| # specified route. | ||
| # stores in the form {'path1': {'method1': function_before_path1_for_method1}} | ||
| before_request_funcs = defaultdict(dict) | ||
|
|
||
|
|
||
| @app.before_request | ||
| def before_request_callback(): | ||
| path = request.path | ||
| method = request.method | ||
| global before_request_funcs | ||
| func = before_request_funcs.get(path, {}).get(method, None) | ||
| if func: | ||
| func() | ||
|
|
||
|
|
||
| # decorator to define logic for custom before request methods | ||
| def custom_before_request(path, method): | ||
| def wrapper(f): | ||
| global before_request_funcs | ||
| before_request_funcs[path][method] = f | ||
| return f | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| @custom_before_request('/api/MessageCollection', 'PUT') | ||
| def do_this_before_put_on_drone_collections(): | ||
| print("Do something before PUT request on MessageCollection") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we cannot have |
||
|
|
||
|
|
||
| @custom_before_request('/api/MessageCollection', 'GET') | ||
| def do_this_before_get_on_drone_collections(): | ||
| print("Do something before GET request on MessageCollection") | ||
|
|
||
|
|
||
| # | ||
| # Nested context managers | ||
| # | ||
|
|
@@ -58,17 +102,17 @@ | |
| # Set HYDRUS_SERVER_URL | ||
| # Set the Database session | ||
| with set_authentication(app, AUTH), set_token(app, TOKEN), \ | ||
| set_api_name(app, API_NAME), set_doc(app, apidoc), \ | ||
| set_hydrus_server_url(app, HYDRUS_SERVER_URL), set_session(app, session): | ||
| if __name__ == "__main__": | ||
| # this is run only if development server is run | ||
| # Set the name of the API | ||
| socketio.run(app=app, debug=True, port=PORT) | ||
| else: | ||
| # Start the Hydrus app | ||
| http_server = WSGIServer(('', PORT), app) | ||
| logger.info(f'Running server at port {PORT}') | ||
| try: | ||
| http_server.serve_forever() | ||
| except KeyboardInterrupt: | ||
| pass | ||
| set_api_name(app, API_NAME), set_doc(app, apidoc), \ | ||
| set_hydrus_server_url(app, HYDRUS_SERVER_URL), set_session(app, session): | ||
| if __name__ == "__main__": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes will make the conditionals to run outside of the |
||
| # this is run only if development server is run | ||
| # Set the name of the API | ||
| socketio.run(app=app, debug=True, port=PORT) | ||
| else: | ||
| # Start the Hydrus app | ||
| http_server = WSGIServer(('', PORT), app) | ||
| logger.info(f'Running server at port {PORT}') | ||
| try: | ||
| http_server.serve_forever() | ||
| except KeyboardInterrupt: | ||
| pass | ||
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.
Docstrings go inside the function declaration using triple quotes
"""