Skip to content

Commit bea2e43

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 29f1b0c commit bea2e43

File tree

13 files changed

+180
-388
lines changed

13 files changed

+180
-388
lines changed

commands.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,9 @@ def set_database_configuration(
253253
if len(database_attrs) > 0:
254254
update_config_file(database_config, data_source=True)
255255
else:
256-
search_omero_app.logger.info(
257-
"At least one database attribute\
256+
search_omero_app.logger.info("At least one database attribute\
258257
(i.e. url, database name, username, username password)\
259-
should be provided"
260-
)
258+
should be provided")
261259

262260

263261
@search_omero_app.cli.command("set_default_datasource")

examples/return_studies.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
"Imaging Method"="light sheet fluorescence microscopy, spim"
3636
"""
3737

38-
logging.info(
39-
"Get a study list for: (Organism= mus musculus) and \
40-
(Imaging Method=light sheet fluorescence microscopy, spim)"
41-
)
38+
logging.info("Get a study list for: (Organism= mus musculus) and \
39+
(Imaging Method=light sheet fluorescence microscopy, spim)")
4240

4341
"""
4442
url="%s%s?key=Organism&value=Homo sapiens&return_containers=true"%(base_url,image_search) # noqa

examples/return_studies_using_container.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
and
3535
"Imaging Method"="spim"
3636
"""
37-
logging.info(
38-
"Get a study list for: (Organism= mus musculus) and \
39-
(Imaging Method=spim)"
40-
)
37+
logging.info("Get a study list for: (Organism= mus musculus) and \
38+
(Imaging Method=spim)")
4139

4240
"""
4341
url="%s%s?key=Organism&value=Homo sapiens&return_containers=true"%(base_url,image_search) # noqa

examples/search-using_and_or_clauses.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import sys
2424
from utils import base_url
2525

26-
2726
# url to send the query
2827
image_ext = "/resources/image/searchannotation/"
2928
# url to get the next page for a query, bookmark is needed

examples/submit_query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import sys
2121
from utils import query_the_search_ending, logging
2222

23-
2423
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
2524

2625
query_1 = {

omero_search_engine/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
from configurations.configuration import app_config as config_
4343

44-
4544
template = {
4645
"swaggerUiPrefix": LazyString(
4746
lambda: request.environ.get("SCRIPT_NAME", "")
@@ -128,12 +127,8 @@ def create_app(config_name=None):
128127
maxBytes=100240,
129128
backupCount=10,
130129
)
131-
file_handler.setFormatter(
132-
logging.Formatter(
133-
"%(asctime)s %(levelname)s:\
134-
%(message)s [in %(pathname)s:%(lineno)d]"
135-
)
136-
)
130+
file_handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s:\
131+
%(message)s [in %(pathname)s:%(lineno)d]"))
137132
file_handler.setLevel(logging.INFO)
138133
search_omero_app.logger.addHandler(file_handler)
139134

@@ -187,11 +182,8 @@ def after_request(response):
187182
@search_omero_app.errorhandler(404)
188183
def page_not_found(error):
189184
search_omero_app.logger.info("Error: %s" % error)
190-
resp_message = (
191-
"%s, You may use '/searchengine/api/v1/resources/' to test\
192-
the deployment and '/searchengine/apidocs/' for the Swagger documents."
193-
% error
194-
)
185+
resp_message = "%s, You may use '/searchengine/api/v1/resources/' to test\
186+
the deployment and '/searchengine/apidocs/' for the Swagger documents." % error
195187
response = make_response(resp_message, 404)
196188
response.mimetype = "text/plain"
197189
return response

omero_search_engine/api/v1/resources/query_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,9 @@ def search_query(
597597
return ress
598598
except Exception as ex:
599599
search_omero_app.logger.info("Error: " + str(ex))
600-
return {
601-
"Error": "Something went wrong, please try later.\
600+
return {"Error": "Something went wrong, please try later.\
602601
If you have this error again, please contact the\
603-
system administrator."
604-
}
602+
system administrator."}
605603

606604

607605
def combine_conditions(curnt_cond, new_cond, resource):

omero_search_engine/api/v1/resources/resource_analyser.py

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -30,80 +30,64 @@
3030
import math
3131
from flask import jsonify, Response
3232

33-
key_number_search_template_ = Template(
34-
"""
33+
key_number_search_template_ = Template("""
3534
{"size":0,"aggs":{"value_search":{"nested":{"path":"key_values"},
3635
"aggs":{"value_filter":{"filter":{"terms":
3736
{"key_values.name.keyword":["$key"]}},
3837
"aggs":{"required_values":{"cardinality":
3938
{"field":"key_values.value.keyvalue","precision_threshold":4000
40-
}}}}}}}}"""
41-
)
39+
}}}}}}}}""")
4240

43-
key_number_search_template = Template(
44-
"""
41+
key_number_search_template = Template("""
4542
{"size":0,"query":{ "bool": {"must": {"match":
4643
{"data_source.keyvalue":"$data_source"}}}},
4744
"aggs":{"value_search":{"nested":{"path":"key_values"},"aggs":{"value_filter":{"filter":{"terms":{
4845
"key_values.name.keyword":["$key"]}},"aggs":{"required_values":{"cardinality":{
49-
"field":"key_values.value.keyvalue","precision_threshold":4000}}}}}}}}"""
50-
)
46+
"field":"key_values.value.keyvalue","precision_threshold":4000}}}}}}}}""")
5147

52-
search_by_value_only = Template(
53-
"""
48+
search_by_value_only = Template("""
5449
{"query":{"bool":{"must":[{"nested":
5550
{"path":"key_values","query":{"bool":{"must":[{"wildcard":
56-
{"key_values.value.keyvaluenormalize":"*eLa*"}}]}}}}]}}}"""
57-
)
51+
{"key_values.value.keyvaluenormalize":"*eLa*"}}]}}}}]}}}""")
5852

59-
value_number_search_template = Template(
60-
"""
53+
value_number_search_template = Template("""
6154
{"size": 0,"aggs": {"name_search": {"nested":
6255
{"path": "key_values"},"aggs": {"value_filter": {"filter": {
6356
"terms": {"key_values.value.keyvaluenormalize":
6457
["$value"]}},"aggs": {"required_name": {"cardinality": {
65-
"field": "key_values.name.keyword","precision_threshold": 4000}}}}}}}}"""
66-
)
58+
"field": "key_values.name.keyword","precision_threshold": 4000}}}}}}}}""")
6759

68-
value_search_template = Template(
69-
"""
60+
value_search_template = Template("""
7061
{"size": 0,"aggs": {"name_search":
7162
{"nested": {"path": "key_values"},"aggs": {"value_filter": {
7263
"filter": {"terms": {"key_values.value.keyvaluenormalize":
7364
["$value"]}},"aggs": {"required_name": {
74-
"terms": {"field": "key_values.name.keyword","size": 9999}}}}}}}}"""
75-
)
65+
"terms": {"field": "key_values.name.keyword","size": 9999}}}}}}}}""")
7666

77-
value_search_contain_template = Template(
78-
"""
67+
value_search_contain_template = Template("""
7968
{"size": 0,"aggs": {"name_search": {"nested": {"path": "key_values"},
8069
"aggs": {"value_filter": {"terms":
8170
{"field":"key_values.value.keyvaluenormalize","include": ".*$value.*"},
8271
"aggs": {"required_name": {"terms":
83-
{"field": "key_values.name.keyword","size": 9999}}}}}}}}"""
84-
)
72+
{"field": "key_values.name.keyword","size": 9999}}}}}}}}""")
8573

86-
key_search_template = Template(
87-
"""
74+
key_search_template = Template("""
8875
{"size": 0,"aggs": {"name_search": {"nested": {"path": "key_values"},
8976
"aggs": {"value_filter": {
9077
"filter": {"terms": {"key_values.name.keyword": ["$key"]}},
9178
"aggs": {"required_values": {
9279
"terms": {"field": "key_values.value.keyvaluenormalize",
93-
"size": 9999}}}}}}}}"""
94-
)
80+
"size": 9999}}}}}}}}""")
9581

96-
values_for_key_template = Template(
97-
"""
82+
values_for_key_template = Template("""
9883
{"size":0, "query":{ "bool" : {"must": {"match":{
9984
"data_source.keyvalue":"$data_source"}}}},
10085
"aggs":{"name_search":{"nested":{ "path":"key_values"},
10186
"aggs":{"value_filter":{"filter":{
10287
"terms":{"key_values.name.keyword":["$key"]}},"aggs":{"required_values":{
10388
"terms":{"field":"key_values.value.keyvaluenormalize",
10489
"include": {"partition": "$cur","num_partitions": "$total"},
105-
"size":10000 }}}}}}}}"""
106-
)
90+
"size":10000 }}}}}}}}""")
10791

10892

10993
def search_index_for_value(e_index, query, get_size=False):
@@ -160,11 +144,8 @@ def search_index_for_values_get_all_buckets(e_index, query):
160144
returened_results.append(res)
161145
co += page_size
162146
if len(res["hits"]["hits"]) == 0:
163-
search_omero_app.logger.info(
164-
"No result is found in the final\
165-
loop: %s for size %s"
166-
% (co, size)
167-
)
147+
search_omero_app.logger.info("No result is found in the final\
148+
loop: %s for size %s" % (co, size))
168149
return returened_results
169150
bookmark = [
170151
int(res["hits"]["hits"][-1]["sort"][0]),
@@ -580,16 +561,14 @@ def search_value_for_resource(
580561
"""
581562
Search using key and resource
582563
"""
583-
key_values_buckets_template = Template(
584-
"""
564+
key_values_buckets_template = Template("""
585565
{
586566
"query":{"bool":{"must":[{"bool":{
587567
"must":{"match":{"Attribute.keynamenormalize":"$name"}}}},{"bool":{"must":{
588568
"match":{"resource.keyresource":"$resource"}}}
589569
},{"bool":{"must":{"terms":{"data_source.keyvalue":$data_source}
590570
}}}]}}}
591-
"""
592-
)
571+
""")
593572

594573
"""
595574
Search using key, part of the value and resource
@@ -607,42 +586,34 @@ def search_value_for_resource(
607586
# "fields": ["Attribute","Value","items_in_the_bucket",
608587
# "total_items_in_saved_buckets","total_buckets","total_items"],
609588
# "_source": false,
610-
ss = Template(
611-
"""
589+
ss = Template("""
612590
{"query":{"bool":{"must":[{"bool":{
613591
"must":{"match":{"Attribute.keyname":"$name"}}}},{"bool": {
614592
"must": {"match": {"resource.keyresource": "$resource"}}}}]}}
615-
"size": 9999}"""
616-
)
593+
"size": 9999}""")
617594

618595
"""
619596
Search using value and resource
620597
"""
621-
key_values_search_buckets_template = Template(
622-
"""
598+
key_values_search_buckets_template = Template("""
623599
{"query":{"bool":{"must":[{"bool":{
624600
"must":{"match":{"Value.keyvalue":"$value"}}}},{
625-
"bool": {"must": {"match":{"resource.keyresource": "$resource"}}}}]}},"size": 9999}"""
626-
)
601+
"bool": {"must": {"match":{"resource.keyresource": "$resource"}}}}]}},"size": 9999}""")
627602

628603
"""
629604
Search using value or part of value and return all the posible mathes
630605
"""
631606

632-
value_all_buckets_template = Template(
633-
"""
607+
value_all_buckets_template = Template("""
634608
{"query":{"bool":{"must":[{"bool":{
635609
"must":{"wildcard":
636-
{"Value.keyvaluenormalize":"*$value*"}}}}]}},"size": 9999}"""
637-
)
610+
{"Value.keyvaluenormalize":"*$value*"}}}}]}},"size": 9999}""")
638611

639-
resource_key_values_buckets_size_template = Template(
640-
"""
612+
resource_key_values_buckets_size_template = Template("""
641613
{"query":{"bool":{"must":[{"bool":{
642614
"must":{"wildcard":{"Value.keyvaluenormalize":"*$value*"}}}},{"bool":{
643615
"must":{"terms":{"data_source.keyvalue":$data_source}}}},{
644-
"bool": {"must": {"match":{"resource.keyresource": "$resource"}}}}]}}}"""
645-
)
616+
"bool": {"must": {"match":{"resource.keyresource": "$resource"}}}}]}}}""")
646617

647618
resource_key_values_buckets_template = Template( # noqa
648619
"""
@@ -697,11 +668,9 @@ def get_resource_attributes(
697668
return the available attributes for one or all resources
698669
"""
699670
if mode and mode != "searchterms":
700-
return build_error_message(
701-
"The mode parameter supports only 'searchterms'\
671+
return build_error_message("The mode parameter supports only 'searchterms'\
702672
to return the common search terms,\
703-
you may remove it to return all the keys."
704-
)
673+
you may remove it to return all the keys.")
705674
returned_results = []
706675
if data_source and data_source.lower() != "all":
707676
data_source = [itm.strip().lower() for itm in data_source.split(",")]
@@ -757,13 +726,11 @@ def get_resource_attributes(
757726
return returned_results
758727

759728

760-
attribute_search_values_template = Template(
761-
"""
729+
attribute_search_values_template = Template("""
762730
{"query":{"bool":{"must":[
763731
{"bool":{"must":{"match":{"resource.keyresource":"$resource"}}}},
764732
{"bool": {"must":
765-
{"match": {"Attribute.keyname":"$name"}}}}]}},"size":9999}"""
766-
)
733+
{"match": {"Attribute.keyname":"$name"}}}}]}},"size":9999}""")
767734

768735

769736
def get_resource_attribute_search_values(
@@ -1087,17 +1054,15 @@ def process_container_query(
10871054
}},"uniquesTerms": {"terms": {"field":
10881055
"key_values.name.keynamenormalize", "size": 10000}}}}}"""
10891056

1090-
resource_keys_template = Template(
1091-
"""
1057+
resource_keys_template = Template("""
10921058
{"size":0,"query":{ "bool" : {"must": {"match":{
10931059
"data_source.keyvalue":"$data_source"}}}},
10941060
"aggs":{"value_search":{"nested":{"path":"key_values"},
10951061
"aggs":{"required_values":{"cardinality":{
10961062
"field":"key_values.name.keyword","precision_threshold":4000}}},
10971063
"aggs": {"required_name": {
10981064
"terms": {"field": "key_values.name.keyword","size": 9999}}}}}}
1099-
"""
1100-
)
1065+
""")
11011066

11021067

11031068
def get_resource_keys(resource, data_source):
@@ -1112,8 +1077,7 @@ def get_resource_keys(resource, data_source):
11121077
# Return sub container using a container attribute
11131078
# for example get the number of sub-containers e.g. datasets names,
11141079
# inside a container, e.g. project using name.
1115-
container_returned_sub_container_template = Template(
1116-
"""
1080+
container_returned_sub_container_template = Template("""
11171081
{
11181082
"values":{
11191083
"filter":{
@@ -1139,8 +1103,7 @@ def get_resource_keys(resource, data_source):
11391103
}
11401104
}
11411105
}
1142-
"""
1143-
)
1106+
""")
11441107

11451108

11461109
def get_containers_no_images(

0 commit comments

Comments
 (0)