Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexOarga committed Nov 15, 2021
1 parent be5fab1 commit ee4c4bc
Show file tree
Hide file tree
Showing 41 changed files with 438 additions and 312 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![CI-CD](https://github.com/openCONTRABASS/CONTRABASS-webservice/actions/workflows/main.yml/badge.svg)](https://github.com/openCONTRABASS/CONTRABASS-webservice/actions/workflows/main.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=openCONTRABASS_CONTRABASS-webservice&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=openCONTRABASS_CONTRABASS-webservice)
[![codecov](https://codecov.io/gh/openCONTRABASS/CONTRABASS-webservice/branch/main/graph/badge.svg?token=T1S7E99XJJ)](https://codecov.io/gh/openCONTRABASS/CONTRABASS-webservice)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

```CONTRABASS RESTful API``` is a python-based asynchronous-tasks RESTful API intended for the computation and analysis of vulnerabilities in genome-scale metabolic models. These webservices are just a backed for [CONTRABASS python tool](https://github.com/openCONTRABASS/CONTRABASS).

## Table of Contents
- [License](#license)
Expand Down
52 changes: 28 additions & 24 deletions src/restapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import eventlet

eventlet.monkey_patch()

import os
Expand Down Expand Up @@ -45,21 +46,21 @@
from .exception_handler import init_exception_handler

basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(basedir, '../../.env'))
load_dotenv(os.path.join(basedir, "../../.env"))


LOGGER = logging.getLogger(__name__)

app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
app.config.from_object(os.environ["APP_SETTINGS"])

# Logger config
logging.config.dictConfig(app.config["DICT_LOGGER"])

# Database config

# MONGODB
'''
"""
from .database import db
app.config['MONGODB_SETTINGS'] = {
Expand All @@ -69,25 +70,22 @@
'alias': ''
}
db.init_app(app)
'''
"""
# MYSQL
db.init_app(app)

LOGGER.info("Successfully init db connection")

# Swagger config
app.config['SWAGGER'] = {
'title': 'CONTRABASS API',
'uiversion': 3
}
Swagger(app, template_file='swagger.yml')
app.config["SWAGGER"] = {"title": "CONTRABASS API", "uiversion": 3}
Swagger(app, template_file="swagger.yml")
LOGGER.info("Successfully init Swagger")

# Register blueprints
app.register_blueprint(submit_bp, url_prefix='/')
app.register_blueprint(models_bp, url_prefix='/')
app.register_blueprint(results_bp, url_prefix='/')
app.register_blueprint(websockets_bp, url_prefix='/')
app.register_blueprint(submit_bp, url_prefix="/")
app.register_blueprint(models_bp, url_prefix="/")
app.register_blueprint(results_bp, url_prefix="/")
app.register_blueprint(websockets_bp, url_prefix="/")
LOGGER.info("Successfully init blueprints")

# Register exception handlers
Expand All @@ -98,32 +96,38 @@
CORS(app)

# Init websockets
socketio = SocketIO(app, \
cors_allowed_origins='*', \
logger=True, \
engineio_logger=True, \
message_queue=app.config['REDIS_BROKER_URL'])
socketio = SocketIO(
app,
cors_allowed_origins="*",
logger=True,
engineio_logger=True,
message_queue=app.config["REDIS_BROKER_URL"],
)


@app.errorhandler(404)
def page_not_found(e):
#return render_template('404.html'), 404
response = jsonify({'message': "Not found"})
# return render_template('404.html'), 404
response = jsonify({"message": "Not found"})
response.status_code = 404
return response

@app.route('/hola/<name>')

@app.route("/hola/<name>")
def hello_name(name):
return "Hello {}!".format(name)

@socketio.on('connect')

@socketio.on("connect")
def test_connect():
LOGGER.info("Client connected via websocket")

@socketio.on('join')

@socketio.on("join")
def on_join(room_name):
LOGGER.info(f"socket.io/join {room_name}")
join_room(room_name)

if __name__ == '__main__':

if __name__ == "__main__":
socketio.run(app)
3 changes: 0 additions & 3 deletions src/restapi/beans/Chokepoint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@


class Chokepoint:

def __init__(self, reaction, metabolite):
self.__reaction = reaction
self.__metabolite = metabolite
Expand Down
2 changes: 0 additions & 2 deletions src/restapi/beans/ConfigChokepoints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

class ConfigReactionsSets:

def __init__(self):
self.__objective = None
self.__fraction_of_optimum = None
Expand Down
2 changes: 1 addition & 1 deletion src/restapi/beans/ConfigReactionsSets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .OptimizationEnum import *
from .MediumEnum import *

class ConfigReactionsSets:

class ConfigReactionsSets:
def __init__(self):
self.__objective = None
self.__fraction_of_optimum = None
Expand Down
3 changes: 2 additions & 1 deletion src/restapi/beans/MediumEnum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class MediumEnum(Enum):
DEFAULT = 1
COMPLETE = 2
COMPLETE = 2
2 changes: 0 additions & 2 deletions src/restapi/beans/ModelId.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

class ModelId:

def __init__(self, model, metabolites, reactions, genes):
self.model_uuid = model
self.metabolites = metabolites
Expand Down
3 changes: 2 additions & 1 deletion src/restapi/beans/OptimizationEnum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class OptimizationEnum(Enum):
FBA = 1
pFBA = 2
pFBA = 2
4 changes: 2 additions & 2 deletions src/restapi/beans/ResponseChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ResponseChannel:

def __init__(self, channel=None):
self.channel = channel

Expand All @@ -14,6 +13,7 @@ def channel_attr(self):
def channel_attr(self, channel):
self.channel = channel


class ResponseChannelEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
return o.__dict__
4 changes: 2 additions & 2 deletions src/restapi/beans/ResponseChokepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ResponseChokepoints:

def __init__(self, status=None, finished=None, result=None, pending_length=None):
self.__status = status
self.__finished = finished
Expand Down Expand Up @@ -41,6 +40,7 @@ def pending_length(self):
def pending_length(self, pending_length):
self.__pending_length = pending_length


class ResponseChokepointsEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
return o.__dict__
4 changes: 2 additions & 2 deletions src/restapi/beans/ResponseEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ResponseEndpoint:

def __init__(self, endpoint=None):
self.endpoint = endpoint

Expand All @@ -14,6 +13,7 @@ def endpoint_attr(self):
def endpoint_attr(self, endpoint):
self.endpoint = endpoint


class ResponseEndpointEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
return o.__dict__
11 changes: 8 additions & 3 deletions src/restapi/beans/ResponseReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@


class ResponseReport:

def __init__(self, status=None, finished=None, file_spreadsheet=None, file_html=None, pending_length=None):
def __init__(
self,
status=None,
finished=None,
file_spreadsheet=None,
file_html=None,
pending_length=None,
):
self.status = status
self.finished = finished
self.file_spreadsheet = file_spreadsheet
Expand Down Expand Up @@ -49,4 +55,3 @@ def pending_length_attr(self):
@pending_length_attr.setter
def pending_length_attr(self, pending_length):
self.pending_length = pending_length

20 changes: 15 additions & 5 deletions src/restapi/beans/TaskFormCriticalReactions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from wtforms import Form, StringField, DecimalField, validators


class TaskFormCriticalReactions(Form):
objective = StringField('objective',
[validators.optional(), validators.Length(min=1, max=256)])
fraction_of_optimum = DecimalField('fraction_of_optimum',
[validators.optional(),
validators.NumberRange(min=0.0, max=1.0, message='Fraction of optimum must be in the range [0, 1]')])
objective = StringField(
"objective", [validators.optional(), validators.Length(min=1, max=256)]
)
fraction_of_optimum = DecimalField(
"fraction_of_optimum",
[
validators.optional(),
validators.NumberRange(
min=0.0,
max=1.0,
message="Fraction of optimum must be in the range [0, 1]",
),
],
)
51 changes: 36 additions & 15 deletions src/restapi/beans/TaskFormReactionsSets.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
from wtforms import Form, StringField, DecimalField, SelectField, BooleanField, validators
from wtforms import (
Form,
StringField,
DecimalField,
SelectField,
BooleanField,
validators,
)
from .OptimizationEnum import *
from .MediumEnum import *


class TaskFormReactionsSets(Form):
objective = StringField('objective',
[validators.optional(), validators.Length(min=1, max=256)])
fraction_of_optimum = DecimalField('fraction_of_optimum',
[validators.optional(),
validators.NumberRange(min=0.0, max=1.0, message='Fraction of optimum must be in the range [0, 1]')])
medium = SelectField(u'Growth medium',
[validators.optional()],
choices=[name for name, member in MediumEnum.__members__.items()])
optimization = SelectField(u'Growth Optimization',
[validators.optional()],
choices=[name for name, member in OptimizationEnum.__members__.items()])
skip_knockout = BooleanField(u'Skip knock-out computation',
[validators.optional()],
default=True)
objective = StringField(
"objective", [validators.optional(), validators.Length(min=1, max=256)]
)
fraction_of_optimum = DecimalField(
"fraction_of_optimum",
[
validators.optional(),
validators.NumberRange(
min=0.0,
max=1.0,
message="Fraction of optimum must be in the range [0, 1]",
),
],
)
medium = SelectField(
u"Growth medium",
[validators.optional()],
choices=[name for name, member in MediumEnum.__members__.items()],
)
optimization = SelectField(
u"Growth Optimization",
[validators.optional()],
choices=[name for name, member in OptimizationEnum.__members__.items()],
)
skip_knockout = BooleanField(
u"Skip knock-out computation", [validators.optional()], default=True
)
5 changes: 1 addition & 4 deletions src/restapi/beans/TaskInit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@


class TaskInit:

def __init__(self, task_id, pending_length=None):
self.task_id = task_id
self.pending_length = pending_length
Expand All @@ -20,4 +17,4 @@ def pending_length_attr(self):

@pending_length_attr.setter
def pending_length_attr(self, pending_length):
self.pending_length = pending_length
self.pending_length = pending_length
5 changes: 3 additions & 2 deletions src/restapi/beans/WebsocketEvent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from json import JSONEncoder

class WebsocketEvent:

class WebsocketEvent:
def __init__(self, event, message):
self.event = event
self.message = message
Expand All @@ -22,6 +22,7 @@ def message_attr(self):
def message_attr(self, message):
self.message = message


class ResponseWebsocketEventEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
return o.__dict__
Loading

0 comments on commit ee4c4bc

Please sign in to comment.