From 4294c2854b60ca091ef7a35adbd4835594d18b92 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 27 Mar 2020 12:06:11 +0100 Subject: [PATCH] Make inner package imports relative --- CorpusAnalysisClient.js.md | 50 ----------------------------- app/admin/__init__.py | 2 +- app/admin/forms.py | 2 +- app/admin/views.py | 8 ++--- app/auth/__init__.py | 2 +- app/auth/forms.py | 2 +- app/auth/views.py | 6 ++-- app/corpora/__init__.py | 2 +- app/corpora/background_functions.py | 2 +- app/corpora/events.py | 10 +++--- app/corpora/views.py | 4 +-- app/decorators.py | 2 +- app/email.py | 2 +- app/jobs/__init__.py | 2 +- app/jobs/background_functions.py | 2 +- app/jobs/views.py | 2 +- app/main/__init__.py | 8 +---- app/main/views.py | 7 ++-- app/profile/__init__.py | 2 +- app/profile/background_functions.py | 2 +- app/profile/views.py | 2 +- app/services/__init__.py | 2 +- app/services/views.py | 7 ++-- app/test/__init__.py | 5 --- app/test/events.py | 23 ------------- app/test/forms.py | 12 ------- app/test/views.py | 12 ------- nopaque.py | 2 +- tests/test_client.py | 2 -- 29 files changed, 37 insertions(+), 149 deletions(-) delete mode 100644 CorpusAnalysisClient.js.md delete mode 100644 app/test/__init__.py delete mode 100644 app/test/events.py delete mode 100644 app/test/forms.py delete mode 100644 app/test/views.py diff --git a/CorpusAnalysisClient.js.md b/CorpusAnalysisClient.js.md deleted file mode 100644 index 6f19fc6e..00000000 --- a/CorpusAnalysisClient.js.md +++ /dev/null @@ -1,50 +0,0 @@ -# Corpus Analysis - -## Start einer Session - -```javascript -nopaque.socket.emit("corpus_analysis_init", ); - ~ number -// Show init loading modal - -nopaque.socket.on("corpus_analysis_init", ); - ~ {"code": , "msg": } - ~ number // HTTP status code - ~ string -// Hide init loading modal -``` - -## Ausführen einer Suchanfrage - -Ergebnisse werden Stückchenweise als "chunks" übertragen. - -```javascript -nopaque.socket.emit("corpus_analysis_query", ); - ~ string -// Clear result data store and list -result = {"query": }; -// Hide query result card -// Show query loading card -nopaque.socket.on("corpus_analysis_query", ); - : {"code": , "result": } - ~ number // Error, Success - ~ {"matches": [, ...], - "num_matches": , - "cpos_lookup": {: , ...}, - "text_lookup": {: , ...}} - ~ number - ~ number - ~ {"word": , "lemma": , "simple_pos": , "pos": , "ner": , "text": , "s": } - ~ string - ~ string - ~ string - ~ string - ~ string - ~ number - ~ number - ~ {"author": , "title": , ...} - ~ string -// Process response -// Hide query result card -// Show query loading card -``` diff --git a/app/admin/__init__.py b/app/admin/__init__.py index 9bb011f8..40fd29a4 100644 --- a/app/admin/__init__.py +++ b/app/admin/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint admin = Blueprint('admin', __name__) -from . import views +from . import views # noqa diff --git a/app/admin/forms.py b/app/admin/forms.py index 0eea3b94..fd41d016 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -1,8 +1,8 @@ -from app.models import Role, User from flask_wtf import FlaskForm from wtforms import (BooleanField, SelectField, StringField, SubmitField, ValidationError) from wtforms.validators import DataRequired, Email, Length, Regexp +from ..models import Role, User class EditUserForm(FlaskForm): diff --git a/app/admin/views.py b/app/admin/views.py index 1ab40620..5ca0b74b 100644 --- a/app/admin/views.py +++ b/app/admin/views.py @@ -1,13 +1,13 @@ -from app import db -from app.decorators import admin_required -from app.models import Role, User -from app.profile.background_functions import delete_user_ from flask import current_app, flash, redirect, render_template, url_for from flask_login import login_required from threading import Thread from . import admin from .forms import EditUserForm from .tables import AdminUserItem, AdminUserTable +from .. import db +from ..decorators import admin_required +from ..models import Role, User +from ..profile.background_functions import delete_user_ @admin.route('/') diff --git a/app/auth/__init__.py b/app/auth/__init__.py index a45dc3f3..893d7071 100644 --- a/app/auth/__init__.py +++ b/app/auth/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint auth = Blueprint('auth', __name__) -from . import views +from . import views # noqa diff --git a/app/auth/forms.py b/app/auth/forms.py index d361ee07..e3f5c276 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -1,4 +1,4 @@ -from app.models import User +from ..models import User from flask_wtf import FlaskForm from wtforms import (BooleanField, PasswordField, StringField, SubmitField, ValidationError) diff --git a/app/auth/views.py b/app/auth/views.py index e95370ad..7353ebf9 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -1,12 +1,12 @@ -from app import db, logger -from app.email import send_email -from app.models import User from flask import (current_app, flash, redirect, render_template, request, url_for) from flask_login import current_user, login_user, login_required, logout_user from . import auth from .forms import (LoginForm, ResetPasswordForm, ResetPasswordRequestForm, RegistrationForm) +from .. import db +from ..email import send_email +from ..models import User import os import shutil diff --git a/app/corpora/__init__.py b/app/corpora/__init__.py index 73084f46..cec49443 100644 --- a/app/corpora/__init__.py +++ b/app/corpora/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint corpora = Blueprint('corpora', __name__) -from . import events, views +from . import events, views # noqa diff --git a/app/corpora/background_functions.py b/app/corpora/background_functions.py index 442b9424..1b8f7fc0 100644 --- a/app/corpora/background_functions.py +++ b/app/corpora/background_functions.py @@ -1,4 +1,4 @@ -from app.models import Corpus, CorpusFile +from ..models import Corpus, CorpusFile def delete_corpus_(app, corpus_id): diff --git a/app/corpora/events.py b/app/corpora/events.py index 88af8fb7..ee7093c0 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -1,10 +1,10 @@ -from app import db, logger, socketio -from app.decorators import socketio_login_required -from app.events import connected_sessions -from app.models import Corpus, User -from .cqi import CQiClient from flask import current_app, request from flask_login import current_user +from .cqi import CQiClient +from .. import db, logger, socketio +from ..decorators import socketio_login_required +from ..events import connected_sessions +from ..models import Corpus, User import math diff --git a/app/corpora/views.py b/app/corpora/views.py index 6f4e1ed2..9907cf23 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,5 +1,3 @@ -from app import db, logger -from app.models import Corpus, CorpusFile from flask import (abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory) from flask_login import current_user, login_required @@ -10,6 +8,8 @@ from .background_functions import (delete_corpus_, delete_corpus_file_, edit_corpus_file_) from .forms import (AddCorpusFileForm, AddCorpusForm, EditCorpusFileForm, QueryDownloadForm, QueryForm) +from .. import db +from ..models import Corpus, CorpusFile import os diff --git a/app/decorators.py b/app/decorators.py index c45f6d29..c218e314 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -1,7 +1,7 @@ -from functools import wraps from flask import abort from flask_login import current_user from flask_socketio import disconnect +from functools import wraps from .models import Permission diff --git a/app/email.py b/app/email.py index a8bde7db..670167ae 100644 --- a/app/email.py +++ b/app/email.py @@ -1,6 +1,6 @@ -from threading import Thread from flask import current_app, render_template from flask_mail import Message +from threading import Thread from . import mail diff --git a/app/jobs/__init__.py b/app/jobs/__init__.py index 07e0e1bb..43e34614 100644 --- a/app/jobs/__init__.py +++ b/app/jobs/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint jobs = Blueprint('jobs', __name__) -from . import views +from . import views # noqa diff --git a/app/jobs/background_functions.py b/app/jobs/background_functions.py index f90c2daa..6808be49 100644 --- a/app/jobs/background_functions.py +++ b/app/jobs/background_functions.py @@ -1,4 +1,4 @@ -from app.models import Job +from ..models import Job def delete_job_(app, job_id): diff --git a/app/jobs/views.py b/app/jobs/views.py index a5bbe723..4afd2cb3 100644 --- a/app/jobs/views.py +++ b/app/jobs/views.py @@ -1,10 +1,10 @@ -from app.models import Job, JobInput, JobResult from flask import (abort, current_app, flash, redirect, render_template, send_from_directory, url_for) from flask_login import current_user, login_required from threading import Thread from . import jobs from .background_functions import delete_job_ +from ..models import Job, JobInput, JobResult import os diff --git a/app/main/__init__.py b/app/main/__init__.py index ed1e65e9..e58f63b5 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -2,10 +2,4 @@ from flask import Blueprint main = Blueprint('main', __name__) -from . import errors, views -from app.models import Permission - - -@main.app_context_processor -def inject_permissions(): - return dict(Permission=Permission) +from . import errors, views # noqa diff --git a/app/main/views.py b/app/main/views.py index 1552b99b..d93a51fb 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -1,11 +1,10 @@ -from app import logger -from app.auth.forms import LoginForm -from app.models import User from flask import flash, redirect, render_template, url_for from flask_login import login_required, login_user from . import main from .forms import FeedbackForm - +from .. import logger +from ..auth.forms import LoginForm +from ..models import User @main.route('/', methods=['GET', 'POST']) def index(): diff --git a/app/profile/__init__.py b/app/profile/__init__.py index 8283a75f..85b9f61c 100644 --- a/app/profile/__init__.py +++ b/app/profile/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint profile = Blueprint('profile', __name__) -from . import views +from . import views # noqa diff --git a/app/profile/background_functions.py b/app/profile/background_functions.py index 62be9b6f..e8e7f2af 100644 --- a/app/profile/background_functions.py +++ b/app/profile/background_functions.py @@ -1,4 +1,4 @@ -from app.models import User +from ..models import User def delete_user_(app, user_id): diff --git a/app/profile/views.py b/app/profile/views.py index be02cc5b..96f588f0 100644 --- a/app/profile/views.py +++ b/app/profile/views.py @@ -1,10 +1,10 @@ -from app import db from flask import current_app, flash, redirect, render_template, url_for from flask_login import current_user, login_required, logout_user from threading import Thread from . import profile from .background_functions import delete_user_ from .forms import EditEmailForm, EditGeneralSettingsForm, EditPasswordForm +from .. import db @profile.route('/settings', methods=['GET', 'POST']) diff --git a/app/services/__init__.py b/app/services/__init__.py index ea9a403f..0bc0cfb2 100644 --- a/app/services/__init__.py +++ b/app/services/__init__.py @@ -2,4 +2,4 @@ from flask import Blueprint services = Blueprint('services', __name__) -from . import views +from . import views # noqa diff --git a/app/services/views.py b/app/services/views.py index d8492544..2339260b 100644 --- a/app/services/views.py +++ b/app/services/views.py @@ -1,14 +1,13 @@ -from app import db -from app.jobs.forms import AddNLPJobForm, AddOCRJobForm, AddSetupFilesJobForm -from app.models import Job, JobInput from flask import (abort, current_app, flash, make_response, render_template, url_for) from flask_login import current_user, login_required from werkzeug.utils import secure_filename from . import services +from .. import db +from ..jobs.forms import AddNLPJobForm, AddOCRJobForm, AddSetupFilesJobForm +from ..models import Job, JobInput import json import os -from app import logger SERVICES = {'corpus_analysis': {'name': 'Corpus analysis'}, diff --git a/app/test/__init__.py b/app/test/__init__.py deleted file mode 100644 index e01f868c..00000000 --- a/app/test/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from flask import Blueprint - - -test = Blueprint('test', __name__) -from . import events, views diff --git a/app/test/events.py b/app/test/events.py deleted file mode 100644 index c57b57b2..00000000 --- a/app/test/events.py +++ /dev/null @@ -1,23 +0,0 @@ -from app import logger, socketio -from flask_login import login_required -from werkzeug.datastructures import FileStorage -from werkzeug.utils import secure_filename -from .forms import TestForm -import io - - -@socketio.on('submit-test-form') -@login_required -def recv_test_form(data): - logger.warning("data_received") - filename = secure_filename(data['file-wrapper']['name']) - stream = io.BytesIO(data['file-wrapper']['bytes']) - file = FileStorage(filename=filename, stream=stream) - data['file'] = file - test_form = TestForm(data=data) - if test_form.validate(): - socketio.emit('submit-test-form', {'msg': {}, - 'status': 201}) - else: - socketio.emit('submit-test-form', {'msg': test_form.errors, - 'status': 400}) diff --git a/app/test/forms.py b/app/test/forms.py deleted file mode 100644 index b7dd19d8..00000000 --- a/app/test/forms.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask_wtf import FlaskForm -from flask_wtf.file import FileAllowed, FileField, FileRequired -from wtforms import StringField, SubmitField -from wtforms.validators import DataRequired, Length - - -class TestForm(FlaskForm): - description = StringField('Description', - validators=[DataRequired(), Length(1, 255)]) - file = FileField('File', validators=[FileAllowed(['txt'], 'Plain text only!'), FileRequired()]) - submit = SubmitField() - title = StringField('Title', validators=[DataRequired(), Length(1, 32)]) diff --git a/app/test/views.py b/app/test/views.py deleted file mode 100644 index a0e76fc2..00000000 --- a/app/test/views.py +++ /dev/null @@ -1,12 +0,0 @@ -from flask import render_template -from flask_login import login_required -from . import test -from .forms import TestForm - - -@test.route('/') -@login_required -def index(): - test_form = TestForm() - return render_template('test/index.html.j2', title='Test', - test_form=test_form) diff --git a/nopaque.py b/nopaque.py index ce66e01f..66c39520 100644 --- a/nopaque.py +++ b/nopaque.py @@ -1,5 +1,5 @@ import eventlet -eventlet.monkey_patch() +eventlet.monkey_patch() # noqa: E261 from app import create_app, db, socketio from app.models import Corpus, Job, Role, User from flask_migrate import Migrate diff --git a/tests/test_client.py b/tests/test_client.py index 584d9691..e4c0738c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,7 +1,5 @@ -import re import unittest from app import create_app, db -from app.models import User, Role class FlaskClientTestCase(unittest.TestCase):