From eff0beb195b85f831d14e147a6dbecceb02dbc4e Mon Sep 17 00:00:00 2001 From: Siddharth Gupta Date: Thu, 7 Apr 2016 23:01:40 -0700 Subject: [PATCH] Optimizing import statements for better readability and to avoid unused, excessive and duplicating imports in the project. (#294) --- caravel/__init__.py | 4 ++-- caravel/bin/caravel | 9 +++++---- caravel/config.py | 3 ++- caravel/forms.py | 7 +++++-- caravel/migrations/env.py | 8 +++++--- caravel/models.py | 21 ++++++++++----------- caravel/utils.py | 8 ++++---- caravel/views.py | 8 ++++---- caravel/viz.py | 11 +++++------ tests/core_tests.py | 2 +- 10 files changed, 43 insertions(+), 38 deletions(-) diff --git a/caravel/__init__.py b/caravel/__init__.py index e424499b741dd..26c2a45614736 100644 --- a/caravel/__init__.py +++ b/caravel/__init__.py @@ -6,12 +6,12 @@ import logging import os + from flask import Flask, redirect from flask.ext.appbuilder import SQLA, AppBuilder, IndexView from flask.ext.appbuilder.baseviews import expose -from flask.ext.migrate import Migrate from flask.ext.cache import Cache - +from flask.ext.migrate import Migrate APP_DIR = os.path.dirname(__file__) CONFIG_MODULE = os.environ.get('CARAVEL_CONFIG', 'caravel.config') diff --git a/caravel/bin/caravel b/caravel/bin/caravel index 5c59c08c7fbff..e22510f8ff647 100755 --- a/caravel/bin/caravel +++ b/caravel/bin/caravel @@ -4,16 +4,17 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -from datetime import datetime import logging +from datetime import datetime from subprocess import Popen -from flask.ext.script import Manager -from caravel import app from flask.ext.migrate import MigrateCommand +from flask.ext.script import Manager + import caravel -from caravel import db +from caravel import app from caravel import data, utils +from caravel import db config = app.config diff --git a/caravel/config.py b/caravel/config.py index 33d244a97cbed..1def66bf43286 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -10,8 +10,9 @@ from __future__ import unicode_literals import os -from flask_appbuilder.security.manager import AUTH_DB + from dateutil import tz +from flask_appbuilder.security.manager import AUTH_DB BASE_DIR = os.path.abspath(os.path.dirname(__file__)) diff --git a/caravel/forms.py b/caravel/forms.py index e69f04895cbf8..875395f95bb87 100644 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -4,13 +4,16 @@ from __future__ import print_function from __future__ import unicode_literals +from collections import OrderedDict +from copy import copy + from wtforms import ( Form, SelectMultipleField, SelectField, TextField, TextAreaField, BooleanField, IntegerField, HiddenField) from wtforms import validators, widgets -from copy import copy + from caravel import app -from collections import OrderedDict + config = app.config diff --git a/caravel/migrations/env.py b/caravel/migrations/env.py index e3713a3e49c36..22a5ea76c0ed4 100755 --- a/caravel/migrations/env.py +++ b/caravel/migrations/env.py @@ -1,9 +1,11 @@ from __future__ import with_statement -from alembic import context -from sqlalchemy import engine_from_config, pool -from logging.config import fileConfig + import logging +from logging.config import fileConfig + +from alembic import context from flask.ext.appbuilder import Base +from sqlalchemy import engine_from_config, pool # this is the Alembic Config object, which provides # access to the values within the .ini file in use. diff --git a/caravel/models.py b/caravel/models.py index a6063c6425ee5..96df0c6aaa962 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -4,31 +4,31 @@ from __future__ import print_function from __future__ import unicode_literals -from copy import deepcopy, copy -from collections import namedtuple -from datetime import timedelta, datetime, date import functools import json import logging -from six import string_types -import sqlparse -import requests import textwrap +from collections import namedtuple +from copy import deepcopy, copy +from datetime import timedelta, datetime, date +import humanize +import pandas as pd +import requests +import sqlalchemy as sqla +import sqlparse from dateutil.parser import parse from flask import flash, request, g from flask.ext.appbuilder import Model from flask.ext.appbuilder.models.mixins import AuditMixin -import pandas as pd -import humanize from pydruid import client from pydruid.utils.filters import Dimension, Filter - -import sqlalchemy as sqla +from six import string_types from sqlalchemy import ( Column, Integer, String, ForeignKey, Text, Boolean, DateTime, Date, Table, create_engine, MetaData, desc, select, and_, func) from sqlalchemy.engine import reflection +from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import relationship from sqlalchemy.sql import table, literal_column, text, column from sqlalchemy.sql.elements import ColumnClause @@ -36,7 +36,6 @@ from caravel import app, db, get_session, utils from caravel.viz import viz_types -from sqlalchemy.ext.declarative import declared_attr config = app.config diff --git a/caravel/utils.py b/caravel/utils.py index 05fb32528746a..891964e0d523f 100644 --- a/caravel/utils.py +++ b/caravel/utils.py @@ -4,17 +4,17 @@ from __future__ import print_function from __future__ import unicode_literals -from datetime import datetime import functools import json import logging +from datetime import datetime -from dateutil.parser import parse -from sqlalchemy.types import TypeDecorator, TEXT -from markdown import markdown as md import parsedatetime +from dateutil.parser import parse from flask import Markup from flask_appbuilder.security.sqla import models as ab_models +from markdown import markdown as md +from sqlalchemy.types import TypeDecorator, TEXT class memoized(object): # noqa diff --git a/caravel/views.py b/caravel/views.py index 8ab2fc8b292ce..738f80f9d50d3 100644 --- a/caravel/views.py +++ b/caravel/views.py @@ -4,13 +4,15 @@ from __future__ import print_function from __future__ import unicode_literals -from datetime import datetime import json import logging import re import time import traceback +from datetime import datetime +import pandas as pd +import sqlalchemy as sqla from flask import ( g, request, redirect, flash, Response, render_template, Markup) from flask.ext.appbuilder import ModelView, CompactCRUDMixin, BaseView, expose @@ -19,12 +21,10 @@ from flask.ext.appbuilder.security.decorators import has_access from pydruid.client import doublesum from sqlalchemy import create_engine -import sqlalchemy as sqla -from wtforms.validators import ValidationError -import pandas as pd from sqlalchemy import select, text from sqlalchemy.sql.expression import TextAsFrom from werkzeug.routing import BaseConverter +from wtforms.validators import ValidationError from caravel import appbuilder, db, models, viz, utils, app, sm, ascii_art diff --git a/caravel/viz.py b/caravel/viz.py index 7cfc68f480b12..24727c2ec88d2 100644 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -8,25 +8,24 @@ from __future__ import print_function from __future__ import unicode_literals -from collections import OrderedDict, defaultdict -from datetime import datetime, timedelta +import hashlib import json import logging import uuid -import hashlib +from collections import OrderedDict, defaultdict +from datetime import datetime, timedelta +import pandas as pd from flask import flash, request, Markup from markdown import markdown from pandas.io.json import dumps +from six import string_types from werkzeug.datastructures import ImmutableMultiDict from werkzeug.urls import Href -import pandas as pd from caravel import app, utils, cache from caravel.forms import FormFactory -from six import string_types - config = app.config diff --git a/tests/core_tests.py b/tests/core_tests.py index 01239949bca4d..430877b7e3538 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -1,5 +1,5 @@ -import imp import doctest +import imp import os import unittest