Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding from __future__ imports #288

Merged
merged 5 commits into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ babel
.coverage
_build
_static
_images
caravel/bin/caravelc
env_py3
.eggs
Expand Down
4 changes: 4 additions & 0 deletions caravel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Package's main module!"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging
import os
Expand Down
5 changes: 5 additions & 0 deletions caravel/ascii_art.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

error = (
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"+
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"+
Expand Down
4 changes: 4 additions & 0 deletions caravel/bin/caravel
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime
import logging
Expand Down
5 changes: 5 additions & 0 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
in your PYTHONPATH as there is a ``from local_config import *``
at the end of this file.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os
from flask_appbuilder.security.manager import AUTH_DB
from dateutil import tz
Expand Down
4 changes: 4 additions & 0 deletions caravel/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Loads datasets, dashboards and slices in a new caravel instance"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import gzip
import json
Expand Down
4 changes: 4 additions & 0 deletions caravel/data/countries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""This module contains data related to countries and is used for geo mapping"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

countries = [
{
Expand Down
4 changes: 4 additions & 0 deletions caravel/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Contains the logic to create cohesive forms on the explore view"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from wtforms import (
Form, SelectMultipleField, SelectField, TextField, TextAreaField,
Expand Down
44 changes: 24 additions & 20 deletions caravel/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""A collection of ORM sqlalchemy models for Caravel"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from copy import deepcopy, copy
from collections import namedtuple
Expand Down Expand Up @@ -191,8 +195,8 @@ def slice_url(self):
slice_params['slice_name'] = self.slice_name
from werkzeug.urls import Href
href = Href(
"/caravel/explore/{self.datasource_type}/"
"{self.datasource_id}/".format(self=self))
"/caravel/explore/{obj.datasource_type}/"
"{obj.datasource_id}/".format(obj=self))
return href(slice_params)

@property
Expand All @@ -202,8 +206,8 @@ def edit_url(self):
@property
def slice_link(self):
url = self.slice_url
return '<a href="{url}">{self.slice_name}</a>'.format(
url=url, self=self)
return '<a href="{url}">{obj.slice_name}</a>'.format(
url=url, obj=self)


dashboard_slices = Table(
Expand Down Expand Up @@ -244,7 +248,7 @@ def metadata_dejson(self):
return {}

def dashboard_link(self):
return '<a href="{self.url}">{self.dashboard_title}</a>'.format(self=self)
return '<a href="{obj.url}">{obj.dashboard_title}</a>'.format(obj=self)

@property
def json_data(self):
Expand Down Expand Up @@ -432,12 +436,12 @@ def link(self):
@property
def perm(self):
return (
"[{self.database}].[{self.table_name}]"
"(id:{self.id})").format(self=self)
"[{obj.database}].[{obj.table_name}]"
"(id:{obj.id})").format(obj=self)

@property
def full_name(self):
return "[{self.database}].[{self.table_name}]".format(self=self)
return "[{obj.database}].[{obj.table_name}]".format(obj=self)

@property
def dttm_cols(self):
Expand Down Expand Up @@ -472,11 +476,11 @@ def explore_url(self):
if self.default_endpoint:
return self.default_endpoint
else:
return "/caravel/explore/{self.type}/{self.id}/".format(self=self)
return "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)

@property
def table_link(self):
return '<a href="{self.explore_url}">{self.table_name}</a>'.format(self=self)
return '<a href="{obj.explore_url}">{obj.table_name}</a>'.format(obj=self)

@property
def metrics_combo(self):
Expand Down Expand Up @@ -816,9 +820,9 @@ def get_pydruid_client(self):

def refresh_datasources(self):
endpoint = (
"http://{self.coordinator_host}:{self.coordinator_port}/"
"{self.coordinator_endpoint}/datasources"
).format(self=self)
"http://{obj.coordinator_host}:{obj.coordinator_port}/"
"{obj.coordinator_endpoint}/datasources"
).format(obj=self)

datasources = json.loads(requests.get(endpoint).text)
for datasource in datasources:
Expand Down Expand Up @@ -862,8 +866,8 @@ def name(self):
@property
def perm(self):
return (
"[{self.cluster_name}].[{self.datasource_name}]"
"(id:{self.id})").format(self=self)
"[{obj.cluster_name}].[{obj.datasource_name}]"
"(id:{obj.id})").format(obj=self)

@property
def url(self):
Expand All @@ -878,17 +882,17 @@ def link(self):
@property
def full_name(self):
return (
"[{self.cluster_name}]."
"[{self.datasource_name}]").format(self=self)
"[{obj.cluster_name}]."
"[{obj.datasource_name}]").format(obj=self)

def __repr__(self):
return self.datasource_name

@property
def datasource_link(self):
url = "/caravel/explore/{self.type}/{self.id}/".format(self=self)
return '<a href="{url}">{self.datasource_name}</a>'.format(
url=url, self=self)
url = "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)
return '<a href="{url}">{obj.datasource_name}</a>'.format(
url=url, obj=self)

def get_metric_obj(self, metric_name):
return [
Expand Down
42 changes: 4 additions & 38 deletions caravel/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Utility functions used across Caravel"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime
import hashlib
import functools
import json
import logging
Expand Down Expand Up @@ -133,43 +136,6 @@ def process_result_value(self, value, dialect):
return value


class ColorFactory(object):

"""Used to generated arrays of colors server side"""

BNB_COLORS = [
# rausch hackb kazan babu lima beach barol
'#ff5a5f', '#7b0051', '#007A87', '#00d1c1', '#8ce071', '#ffb400', '#b4a76c',
'#ff8083', '#cc0086', '#00a1b3', '#00ffeb', '#bbedab', '#ffd266', '#cbc29a',
'#ff3339', '#ff1ab1', '#005c66', '#00b3a5', '#55d12e', '#b37e00', '#988b4e',
]

def __init__(self, hash_based=False):
self.d = {}
self.hash_based = hash_based

def get(self, s):
"""Gets a color from a string and memoize the association

>>> cf = ColorFactory()
>>> cf.get('item_1')
'#ff5a5f'
>>> cf.get('item_2')
'#7b0051'
>>> cf.get('item_1')
'#ff5a5f'
"""
if self.hash_based:
s = s.encode('utf-8')
h = hashlib.md5(s)
i = int(h.hexdigest(), 16)
else:
if s not in self.d:
self.d[s] = len(self.d)
i = self.d[s]
return self.BNB_COLORS[i % len(self.BNB_COLORS)]


def init(caravel):
"""Inits the Caravel application with security roles and such"""
db = caravel.db
Expand Down
4 changes: 4 additions & 0 deletions caravel/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Flask web views for Caravel"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime
import json
Expand Down
6 changes: 5 additions & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
These objects represent the backend of all the visualizations that
Caravel can render.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta
Expand Down Expand Up @@ -409,7 +413,7 @@ def get_data(self):
na_rep='',
classes=(
"dataframe table table-striped table-bordered "
"table-condensed table-hover"))
"table-condensed table-hover").split(" "))


class MarkupViz(BaseViz):
Expand Down