Skip to content

Commit

Permalink
Merge pull request #103 from yanghua/CUBE-100
Browse files Browse the repository at this point in the history
[CUBE #100] Refactor code based on pyflakes check result
  • Loading branch information
data-infra authored Oct 12, 2022
2 parents fc52bf7 + 7ca5a87 commit bcca27a
Show file tree
Hide file tree
Showing 64 changed files with 359 additions and 1,052 deletions.
15 changes: 4 additions & 11 deletions myapp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# 避免多进程同时启动对系统cpu负载过高
import time,random
# time.sleep(random.randint(1,10))
from flask import g
from copy import deepcopy
import json
import logging
from logging.handlers import TimedRotatingFileHandler
from flask import redirect, g, flash, request, session, abort
from flask import g, abort
import os
from flask import render_template,redirect
from flask import render_template
from flask import Flask, redirect
from flask_appbuilder import AppBuilder, IndexView, SQLA
from flask_appbuilder.baseviews import expose
Expand All @@ -19,11 +17,9 @@
from werkzeug.middleware.proxy_fix import ProxyFix
import wtforms_json

from myapp import config
from myapp.security import MyappSecurityManager
from myapp.utils.core import pessimistic_connection_handling, setup_cache
from myapp.utils.log import DBEventLogger
import pysnooper
wtforms_json.init()

# 在这个文件里面只创建app,不要做view层面的事情。
Expand Down Expand Up @@ -273,7 +269,7 @@ def check_login():
return

if not g.user or not g.user.get_id():
redirect_url = appbuilder.get_url_for_login # +"?login_url="+request.url
appbuilder.get_url_for_login # +"?login_url="+request.url
# return redirect(redirect_url)
abort(401)

Expand All @@ -292,7 +288,7 @@ def myapp_after_request(resp):



except Exception as e:
except Exception:
# print(e)
resp.set_cookie('myapp_username', 'myapp')
# resp.delete_cookie('id')
Expand Down Expand Up @@ -327,9 +323,6 @@ def page_not_found(e):
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)

# 引入视图
from myapp import views


# def can_access(menuitem):
# print(menuitem.name,menuitem.label)
Expand Down
1 change: 0 additions & 1 deletion myapp/check_tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import os
import pysnooper
# @pysnooper.snoop()
def check_tables():
SQLALCHEMY_DATABASE_URI = os.getenv('MYSQL_SERVICE','')
Expand Down
12 changes: 0 additions & 12 deletions myapp/cli.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
#!/usr/bin/env python
from datetime import datetime
import logging
from subprocess import Popen
from sys import stdout

import click
from colorama import Fore, Style
from flask import g
import json
from myapp import app, appbuilder, db, security_manager
from myapp.models.model_notebook import Notebook
from myapp.models.model_team import Project,Project_User
from myapp.models.model_job import Repository,Images,Job_Template,Pipeline,Task
from myapp.models.model_dataset import Dataset
from myapp.models.model_serving import Service,InferenceService
from myapp.models.model_train_model import Training_Model
import csv
import uuid
conf = app.config
import requests

def create_app(script_info=None):
return app
Expand All @@ -27,8 +17,6 @@ def create_app(script_info=None):
def make_shell_context():
return dict(app=app, db=db)

import pysnooper

# https://dormousehole.readthedocs.io/en/latest/cli.html
@app.cli.command('init')
# @pysnooper.snoop()
Expand Down
1 change: 0 additions & 1 deletion myapp/create_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import os
import pysnooper
# @pysnooper.snoop()
def init_db():
SQLALCHEMY_DATABASE_URI = os.getenv('MYSQL_SERVICE','')
Expand Down
17 changes: 4 additions & 13 deletions myapp/forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Contains the logic to create cohesive forms on the explore view"""
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from wtforms import Field
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget,BS3PasswordFieldWidget,DatePickerWidget,DateTimePickerWidget,Select2ManyWidget,Select2Widget
from wtforms import widgets
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from myapp import app

conf = app.config


from wtforms.validators import DataRequired, Length, NumberRange, Optional,Regexp,ValidationError
from wtforms.validators import ValidationError
# from myapp.models.base import MyappModelBase
# model_base=MyappModelBase()
#
Expand Down Expand Up @@ -90,16 +88,9 @@ def filter_not_empty_values(value):



import pysnooper,datetime,time,json
import json
from wtforms.widgets.core import HTMLString,html_params

try:
from html import escape
except ImportError:
from cgi import escape
from wtforms.compat import text_type, iteritems


from wtforms.compat import text_type

class MyCodeArea(object):
def __init__(self, code=''):
Expand Down
2 changes: 1 addition & 1 deletion myapp/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import random
import time
from typing import Any, List, Optional, Tuple
from typing import Any, List, Optional
import uuid

from dateutil.relativedelta import relativedelta
Expand Down
3 changes: 0 additions & 3 deletions myapp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@

from . import log
from . import model_job
from . import user_attributes # noqa
1 change: 0 additions & 1 deletion myapp/models/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from flask_appbuilder import Model
from flask_babel import lazy_gettext as _
import re
from myapp.utils import core
Expand Down
1 change: 0 additions & 1 deletion myapp/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm.exc import MultipleResultsFound
import yaml
import pysnooper

from myapp.utils.core import QueryStatus

Expand Down
14 changes: 2 additions & 12 deletions myapp/models/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
from datetime import datetime
from flask_appbuilder import Model
from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
)

from sqlalchemy.orm import relationship, sessionmaker, subqueryload
from myapp import (
app,
appbuilder,
conf,
db
)
from sqlalchemy.orm import relationship
from myapp.models.base import MyappModelBase
from myapp import app, db, is_feature_enabled, security_manager
from myapp import app
from myapp.security import MyUser


Expand Down
20 changes: 3 additions & 17 deletions myapp/models/model_aihub.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
from flask_appbuilder import Model

from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
)
from sqlalchemy import Text

from myapp import app,db
from myapp import app
from myapp.models.helpers import ImportMixin
# from myapp.models.base import MyappModel
from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from sqlalchemy import Column, Integer, String

from flask import Markup
from myapp.models.base import MyappModelBase
import datetime
metadata = Model.metadata
conf = app.config

Expand Down
28 changes: 5 additions & 23 deletions myapp/models/model_dataset.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
from flask_appbuilder import Model

from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
)

from myapp.models.helpers import AuditMixinNullable, ImportMixin
from flask import escape, g, Markup, request
from .model_team import Project
from myapp import app,db
from myapp.models.helpers import ImportMixin
# from myapp.models.base import MyappModel
from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from flask_appbuilder.models.decorators import renders
from sqlalchemy import Text

from myapp.models.helpers import AuditMixinNullable
from myapp import app
from sqlalchemy import Column, Integer, String
from flask import Markup
from myapp.models.base import MyappModelBase
import datetime
metadata = Model.metadata
conf = app.config

Expand Down
31 changes: 6 additions & 25 deletions myapp/models/model_dimension.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, ForeignKey,Float
from sqlalchemy.orm import relationship
import datetime,time,json
from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
)
from sqlalchemy import String,Column,Integer,ForeignKey,UniqueConstraint,BigInteger,TIMESTAMP
from sqlalchemy import Text
from sqlalchemy import UniqueConstraint

from flask import escape, g, Markup, request
from .model_team import Project
from myapp import app,db
from flask import g
from myapp import app
from myapp.models.helpers import ImportMixin
# from myapp.models.base import MyappModel
from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from flask_appbuilder.models.decorators import renders
from sqlalchemy import Column, Integer, String
from flask import Markup
from myapp.models.base import MyappModelBase
import datetime
metadata = Model.metadata
conf = app.config

Expand Down Expand Up @@ -60,7 +41,7 @@ def table_html(self):

@property
def operate_html(self):
url=f'''
url='''
<a target=_blank href="/dimension_table_modelview/api/create_external_table/%s">创建远程表</a> | <a target=_blank href="/dimension_table_modelview/api/external/%s">建外表示例</a> | <a href="/dimension_table_modelview/api/clear/%s">清空表记录</a>
'''%(self.id,self.id,self.id)
return Markup(url)
Expand Down
22 changes: 4 additions & 18 deletions myapp/models/model_docker.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, ForeignKey,Float
from sqlalchemy.orm import relationship
import datetime,time,json
from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
Text
)
import pysnooper
from myapp.models.base import MyappModelBase
from myapp.models.helpers import AuditMixinNullable, ImportMixin
from flask import escape, g, Markup, request
from myapp import app,db
from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from myapp.models.helpers import AuditMixinNullable
from myapp import app
from sqlalchemy import Column, Integer, String, ForeignKey

from flask import Markup
import datetime
metadata = Model.metadata
conf = app.config
# from myapp.utils.py.py_k8s import K8s
Expand Down
28 changes: 6 additions & 22 deletions myapp/models/model_etl_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, ForeignKey,Float
from sqlalchemy.orm import relationship
import datetime,time,json
from sqlalchemy import (
Boolean,
Column,
create_engine,
DateTime,
ForeignKey,
Integer,
MetaData,
String,
Table,
Text,
Enum,
)

from myapp.models.helpers import AuditMixinNullable, ImportMixin

from myapp import app,db
from sqlalchemy import Text

from myapp.models.helpers import AuditMixinNullable

from myapp import app
from myapp.models.helpers import ImportMixin
# from myapp.models.base import MyappModel

from sqlalchemy import Column, Integer, String, ForeignKey ,Date,DateTime
from sqlalchemy import Column, Integer, String, ForeignKey
from flask_appbuilder.models.decorators import renders
from flask import Markup
from myapp.models.base import MyappModelBase
import datetime
metadata = Model.metadata
conf = app.config

Expand Down
Loading

0 comments on commit bcca27a

Please sign in to comment.