From ec9225b8812a468aea13219d0b4441c1ab29d43a Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Fri, 2 Sep 2022 13:02:04 +0200
Subject: [PATCH] Restructure imports (3rd party imports first)
---
app/cli.py | 2 +-
app/contributions/routes.py | 15 +++------------
app/corpora/cqi_over_socketio/__init__.py | 6 +++---
app/corpora/cqi_over_socketio/cqi.py | 4 ++--
app/corpora/cqi_over_socketio/cqi_corpora.py | 2 +-
.../cqi_over_socketio/cqi_corpora_corpus.py | 6 +++---
.../cqi_corpora_corpus_alignment_attributes.py | 2 +-
.../cqi_corpora_corpus_positional_attributes.py | 2 +-
.../cqi_corpora_corpus_structural_attributes.py | 2 +-
.../cqi_corpora_corpus_subcorpora.py | 10 +++++-----
app/decorators.py | 2 +-
app/email.py | 16 +++++++---------
12 files changed, 29 insertions(+), 40 deletions(-)
diff --git a/app/cli.py b/app/cli.py
index 2692996d..d9b4fdf0 100644
--- a/app/cli.py
+++ b/app/cli.py
@@ -1,8 +1,8 @@
-from app.models import Role, User, TesseractOCRModel, TranskribusHTRModel
from flask import current_app
from flask_migrate import upgrade
import click
import os
+from app.models import Role, User, TesseractOCRModel, TranskribusHTRModel
def _make_default_dirs():
diff --git a/app/contributions/routes.py b/app/contributions/routes.py
index 94462a83..80c6a82d 100644
--- a/app/contributions/routes.py
+++ b/app/contributions/routes.py
@@ -1,10 +1,6 @@
-from ast import Pass
-from app import db
-from app.decorators import permission_required
-from app.models import Permission, Role, User
-from app.settings import tasks as settings_tasks
-from flask import flash, redirect, render_template, url_for
from flask_login import login_required
+from app.decorators import permission_required
+from app.models import Permission
from . import bp
@@ -16,10 +12,5 @@ def before_request():
@bp.route('')
-def index():
- pass
-
-
-@bp.route('/tesseract_ocr_model', methods=['GET', 'POST'])
-def tesseract_ocr_model():
+def contributions():
pass
diff --git a/app/corpora/cqi_over_socketio/__init__.py b/app/corpora/cqi_over_socketio/__init__.py
index f1f5f826..c122e12e 100644
--- a/app/corpora/cqi_over_socketio/__init__.py
+++ b/app/corpora/cqi_over_socketio/__init__.py
@@ -1,11 +1,11 @@
-from app import db, hashids, socketio
-from app.decorators import socketio_login_required
-from app.models import Corpus, CorpusStatus
from flask import session
from flask_login import current_user
from flask_socketio import ConnectionRefusedError
from threading import Lock
import cqi
+from app import db, hashids, socketio
+from app.decorators import socketio_login_required
+from app.models import Corpus, CorpusStatus
'''
diff --git a/app/corpora/cqi_over_socketio/cqi.py b/app/corpora/cqi_over_socketio/cqi.py
index f6edb5fe..9d0fbfd6 100644
--- a/app/corpora/cqi_over_socketio/cqi.py
+++ b/app/corpora/cqi_over_socketio/cqi.py
@@ -1,9 +1,9 @@
+from socket import gaierror
+import cqi
from app import socketio
from app.decorators import socketio_login_required
-from socket import gaierror
from . import NAMESPACE as ns
from .utils import cqi_over_socketio
-import cqi
@socketio.on('cqi.connect', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora.py b/app/corpora/cqi_over_socketio/cqi_corpora.py
index d0f82e96..7b73429a 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora.py
@@ -1,8 +1,8 @@
+import cqi
from app import socketio
from app.decorators import socketio_login_required
from . import NAMESPACE as ns
from .utils import cqi_over_socketio
-import cqi
@socketio.on('cqi.corpora.get', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py
index bfe8437c..5332aade 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py
@@ -1,11 +1,11 @@
+from flask import session
+import cqi
+import math
from app import db, socketio
from app.decorators import socketio_login_required
from app.models import Corpus
-from flask import session
from . import NAMESPACE as ns
from .utils import cqi_over_socketio, lookups_by_cpos
-import cqi
-import math
@socketio.on('cqi.corpora.corpus.drop', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_alignment_attributes.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_alignment_attributes.py
index 95be6771..d6382eaa 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_alignment_attributes.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_alignment_attributes.py
@@ -1,8 +1,8 @@
+import cqi
from app import socketio
from app.decorators import socketio_login_required
from . import NAMESPACE as ns
from .utils import cqi_over_socketio
-import cqi
@socketio.on('cqi.corpora.corpus.alignment_attributes.get', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_positional_attributes.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_positional_attributes.py
index e8c11677..41d55bb3 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_positional_attributes.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_positional_attributes.py
@@ -1,8 +1,8 @@
+import cqi
from app import socketio
from app.decorators import socketio_login_required
from . import NAMESPACE as ns
from .utils import cqi_over_socketio
-import cqi
@socketio.on('cqi.corpora.corpus.positional_attributes.get', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_structural_attributes.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_structural_attributes.py
index 2b1559f6..11178906 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_structural_attributes.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_structural_attributes.py
@@ -1,8 +1,8 @@
+import cqi
from app import socketio
from app.decorators import socketio_login_required
from . import NAMESPACE as ns
from .utils import cqi_over_socketio
-import cqi
@socketio.on('cqi.corpora.corpus.structural_attributes.get', namespace=ns)
diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_subcorpora.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_subcorpora.py
index 419be16b..3c8cbdd4 100644
--- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus_subcorpora.py
+++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus_subcorpora.py
@@ -1,13 +1,13 @@
-from app import socketio
-from app.decorators import socketio_login_required
-from app.models import Corpus
from flask import session
-from . import NAMESPACE as ns
-from .utils import cqi_over_socketio, export_subcorpus
import cqi
import json
import math
import os
+from app import socketio
+from app.decorators import socketio_login_required
+from app.models import Corpus
+from . import NAMESPACE as ns
+from .utils import cqi_over_socketio, export_subcorpus
@socketio.on('cqi.corpora.corpus.subcorpora.get', namespace=ns)
diff --git a/app/decorators.py b/app/decorators.py
index c4767e80..47e6d749 100644
--- a/app/decorators.py
+++ b/app/decorators.py
@@ -1,8 +1,8 @@
-from app.models import Permission
from flask import abort, current_app
from flask_login import current_user
from functools import wraps
from threading import Thread
+from app.models import Permission
def permission_required(permission):
diff --git a/app/email.py b/app/email.py
index b002defa..a853e1d7 100644
--- a/app/email.py
+++ b/app/email.py
@@ -1,11 +1,10 @@
-from app import mail
-from flask import current_app, Flask, render_template
+from flask import current_app, render_template
from flask_mail import Message
from threading import Thread
-from typing import Any
+from app import mail
-def create_message(recipient: str, subject: str, template: str, **kwargs: Any) -> Message:
+def create_message(recipient, subject, template, **kwargs):
subject_prefix: str = current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
msg: Message = Message(
body=render_template(f'{template}.txt.j2', **kwargs),
@@ -16,12 +15,11 @@ def create_message(recipient: str, subject: str, template: str, **kwargs: Any) -
return msg
-def _send(app: Flask, msg):
- with app.app_context():
- mail.send(msg)
+def send(msg, *args, **kwargs):
+ def _send(app, msg):
+ with app.app_context():
+ mail.send(msg)
-
-def send(msg: Message, *args, **kwargs):
thread = Thread(target=_send, args=[current_app._get_current_object(), msg])
thread.start()
return thread