Skip to content

Commit ee4c4bc

Browse files
committed
black formatting
1 parent be5fab1 commit ee4c4bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+438
-312
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
55
[![CI-CD](https://github.com/openCONTRABASS/CONTRABASS-webservice/actions/workflows/main.yml/badge.svg)](https://github.com/openCONTRABASS/CONTRABASS-webservice/actions/workflows/main.yml)
6+
[![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)
7+
[![codecov](https://codecov.io/gh/openCONTRABASS/CONTRABASS-webservice/branch/main/graph/badge.svg?token=T1S7E99XJJ)](https://codecov.io/gh/openCONTRABASS/CONTRABASS-webservice)
8+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
9+
10+
```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).
611

712
## Table of Contents
813
- [License](#license)

src/restapi/app.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
"""
1818
import eventlet
19+
1920
eventlet.monkey_patch()
2021

2122
import os
@@ -45,21 +46,21 @@
4546
from .exception_handler import init_exception_handler
4647

4748
basedir = os.path.abspath(os.path.dirname(__file__))
48-
load_dotenv(os.path.join(basedir, '../../.env'))
49+
load_dotenv(os.path.join(basedir, "../../.env"))
4950

5051

5152
LOGGER = logging.getLogger(__name__)
5253

5354
app = Flask(__name__)
54-
app.config.from_object(os.environ['APP_SETTINGS'])
55+
app.config.from_object(os.environ["APP_SETTINGS"])
5556

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

5960
# Database config
6061

6162
# MONGODB
62-
'''
63+
"""
6364
from .database import db
6465
6566
app.config['MONGODB_SETTINGS'] = {
@@ -69,25 +70,22 @@
6970
'alias': ''
7071
}
7172
db.init_app(app)
72-
'''
73+
"""
7374
# MYSQL
7475
db.init_app(app)
7576

7677
LOGGER.info("Successfully init db connection")
7778

7879
# Swagger config
79-
app.config['SWAGGER'] = {
80-
'title': 'CONTRABASS API',
81-
'uiversion': 3
82-
}
83-
Swagger(app, template_file='swagger.yml')
80+
app.config["SWAGGER"] = {"title": "CONTRABASS API", "uiversion": 3}
81+
Swagger(app, template_file="swagger.yml")
8482
LOGGER.info("Successfully init Swagger")
8583

8684
# Register blueprints
87-
app.register_blueprint(submit_bp, url_prefix='/')
88-
app.register_blueprint(models_bp, url_prefix='/')
89-
app.register_blueprint(results_bp, url_prefix='/')
90-
app.register_blueprint(websockets_bp, url_prefix='/')
85+
app.register_blueprint(submit_bp, url_prefix="/")
86+
app.register_blueprint(models_bp, url_prefix="/")
87+
app.register_blueprint(results_bp, url_prefix="/")
88+
app.register_blueprint(websockets_bp, url_prefix="/")
9189
LOGGER.info("Successfully init blueprints")
9290

9391
# Register exception handlers
@@ -98,32 +96,38 @@
9896
CORS(app)
9997

10098
# Init websockets
101-
socketio = SocketIO(app, \
102-
cors_allowed_origins='*', \
103-
logger=True, \
104-
engineio_logger=True, \
105-
message_queue=app.config['REDIS_BROKER_URL'])
99+
socketio = SocketIO(
100+
app,
101+
cors_allowed_origins="*",
102+
logger=True,
103+
engineio_logger=True,
104+
message_queue=app.config["REDIS_BROKER_URL"],
105+
)
106106

107107

108108
@app.errorhandler(404)
109109
def page_not_found(e):
110-
#return render_template('404.html'), 404
111-
response = jsonify({'message': "Not found"})
110+
# return render_template('404.html'), 404
111+
response = jsonify({"message": "Not found"})
112112
response.status_code = 404
113113
return response
114114

115-
@app.route('/hola/<name>')
115+
116+
@app.route("/hola/<name>")
116117
def hello_name(name):
117118
return "Hello {}!".format(name)
118119

119-
@socketio.on('connect')
120+
121+
@socketio.on("connect")
120122
def test_connect():
121123
LOGGER.info("Client connected via websocket")
122124

123-
@socketio.on('join')
125+
126+
@socketio.on("join")
124127
def on_join(room_name):
125128
LOGGER.info(f"socket.io/join {room_name}")
126129
join_room(room_name)
127130

128-
if __name__ == '__main__':
131+
132+
if __name__ == "__main__":
129133
socketio.run(app)

src/restapi/beans/Chokepoint.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
31
class Chokepoint:
4-
52
def __init__(self, reaction, metabolite):
63
self.__reaction = reaction
74
self.__metabolite = metabolite

src/restapi/beans/ConfigChokepoints.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
class ConfigReactionsSets:
3-
42
def __init__(self):
53
self.__objective = None
64
self.__fraction_of_optimum = None

src/restapi/beans/ConfigReactionsSets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from .OptimizationEnum import *
22
from .MediumEnum import *
33

4-
class ConfigReactionsSets:
54

5+
class ConfigReactionsSets:
66
def __init__(self):
77
self.__objective = None
88
self.__fraction_of_optimum = None

src/restapi/beans/MediumEnum.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
34
class MediumEnum(Enum):
45
DEFAULT = 1
5-
COMPLETE = 2
6+
COMPLETE = 2

src/restapi/beans/ModelId.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
class ModelId:
3-
42
def __init__(self, model, metabolites, reactions, genes):
53
self.model_uuid = model
64
self.metabolites = metabolites

src/restapi/beans/OptimizationEnum.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
34
class OptimizationEnum(Enum):
45
FBA = 1
5-
pFBA = 2
6+
pFBA = 2

src/restapi/beans/ResponseChannel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class ResponseChannel:
5-
65
def __init__(self, channel=None):
76
self.channel = channel
87

@@ -14,6 +13,7 @@ def channel_attr(self):
1413
def channel_attr(self, channel):
1514
self.channel = channel
1615

16+
1717
class ResponseChannelEncoder(JSONEncoder):
1818
def default(self, o):
19-
return o.__dict__
19+
return o.__dict__

src/restapi/beans/ResponseChokepoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class ResponseChokepoints:
5-
65
def __init__(self, status=None, finished=None, result=None, pending_length=None):
76
self.__status = status
87
self.__finished = finished
@@ -41,6 +40,7 @@ def pending_length(self):
4140
def pending_length(self, pending_length):
4241
self.__pending_length = pending_length
4342

43+
4444
class ResponseChokepointsEncoder(JSONEncoder):
4545
def default(self, o):
46-
return o.__dict__
46+
return o.__dict__

src/restapi/beans/ResponseEndpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class ResponseEndpoint:
5-
65
def __init__(self, endpoint=None):
76
self.endpoint = endpoint
87

@@ -14,6 +13,7 @@ def endpoint_attr(self):
1413
def endpoint_attr(self, endpoint):
1514
self.endpoint = endpoint
1615

16+
1717
class ResponseEndpointEncoder(JSONEncoder):
1818
def default(self, o):
19-
return o.__dict__
19+
return o.__dict__

src/restapi/beans/ResponseReport.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33

44
class ResponseReport:
5-
6-
def __init__(self, status=None, finished=None, file_spreadsheet=None, file_html=None, pending_length=None):
5+
def __init__(
6+
self,
7+
status=None,
8+
finished=None,
9+
file_spreadsheet=None,
10+
file_html=None,
11+
pending_length=None,
12+
):
713
self.status = status
814
self.finished = finished
915
self.file_spreadsheet = file_spreadsheet
@@ -49,4 +55,3 @@ def pending_length_attr(self):
4955
@pending_length_attr.setter
5056
def pending_length_attr(self, pending_length):
5157
self.pending_length = pending_length
52-
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
from wtforms import Form, StringField, DecimalField, validators
22

3+
34
class TaskFormCriticalReactions(Form):
4-
objective = StringField('objective',
5-
[validators.optional(), validators.Length(min=1, max=256)])
6-
fraction_of_optimum = DecimalField('fraction_of_optimum',
7-
[validators.optional(),
8-
validators.NumberRange(min=0.0, max=1.0, message='Fraction of optimum must be in the range [0, 1]')])
5+
objective = StringField(
6+
"objective", [validators.optional(), validators.Length(min=1, max=256)]
7+
)
8+
fraction_of_optimum = DecimalField(
9+
"fraction_of_optimum",
10+
[
11+
validators.optional(),
12+
validators.NumberRange(
13+
min=0.0,
14+
max=1.0,
15+
message="Fraction of optimum must be in the range [0, 1]",
16+
),
17+
],
18+
)
Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
from wtforms import Form, StringField, DecimalField, SelectField, BooleanField, validators
1+
from wtforms import (
2+
Form,
3+
StringField,
4+
DecimalField,
5+
SelectField,
6+
BooleanField,
7+
validators,
8+
)
29
from .OptimizationEnum import *
310
from .MediumEnum import *
411

12+
513
class TaskFormReactionsSets(Form):
6-
objective = StringField('objective',
7-
[validators.optional(), validators.Length(min=1, max=256)])
8-
fraction_of_optimum = DecimalField('fraction_of_optimum',
9-
[validators.optional(),
10-
validators.NumberRange(min=0.0, max=1.0, message='Fraction of optimum must be in the range [0, 1]')])
11-
medium = SelectField(u'Growth medium',
12-
[validators.optional()],
13-
choices=[name for name, member in MediumEnum.__members__.items()])
14-
optimization = SelectField(u'Growth Optimization',
15-
[validators.optional()],
16-
choices=[name for name, member in OptimizationEnum.__members__.items()])
17-
skip_knockout = BooleanField(u'Skip knock-out computation',
18-
[validators.optional()],
19-
default=True)
14+
objective = StringField(
15+
"objective", [validators.optional(), validators.Length(min=1, max=256)]
16+
)
17+
fraction_of_optimum = DecimalField(
18+
"fraction_of_optimum",
19+
[
20+
validators.optional(),
21+
validators.NumberRange(
22+
min=0.0,
23+
max=1.0,
24+
message="Fraction of optimum must be in the range [0, 1]",
25+
),
26+
],
27+
)
28+
medium = SelectField(
29+
u"Growth medium",
30+
[validators.optional()],
31+
choices=[name for name, member in MediumEnum.__members__.items()],
32+
)
33+
optimization = SelectField(
34+
u"Growth Optimization",
35+
[validators.optional()],
36+
choices=[name for name, member in OptimizationEnum.__members__.items()],
37+
)
38+
skip_knockout = BooleanField(
39+
u"Skip knock-out computation", [validators.optional()], default=True
40+
)

src/restapi/beans/TaskInit.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
31
class TaskInit:
4-
52
def __init__(self, task_id, pending_length=None):
63
self.task_id = task_id
74
self.pending_length = pending_length
@@ -20,4 +17,4 @@ def pending_length_attr(self):
2017

2118
@pending_length_attr.setter
2219
def pending_length_attr(self, pending_length):
23-
self.pending_length = pending_length
20+
self.pending_length = pending_length

src/restapi/beans/WebsocketEvent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from json import JSONEncoder
22

3-
class WebsocketEvent:
43

4+
class WebsocketEvent:
55
def __init__(self, event, message):
66
self.event = event
77
self.message = message
@@ -22,6 +22,7 @@ def message_attr(self):
2222
def message_attr(self, message):
2323
self.message = message
2424

25+
2526
class ResponseWebsocketEventEncoder(JSONEncoder):
2627
def default(self, o):
27-
return o.__dict__
28+
return o.__dict__

0 commit comments

Comments
 (0)