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

TOX / Travis build matrix #593

Merged
merged 2 commits into from
Jun 10, 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
39 changes: 23 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
addons:
apt:
sources:
- deadsnakes
packages:
- python3.5
cache:
directories:
- $HOME/.wheelhouse/
env:
global:
- TRAVIS_CACHE=$HOME/.travis_cache/
matrix:
#- TOX_ENV=py27-mysql
- TOX_ENV=py27-sqlite
#- TOX_ENV=py27-postgres
- TOX_ENV=py34-sqlite
- TOX_ENV=py34-mysql
- TOX_ENV=javascript
before_install:
- npm install -g npm@'>=2.7.1'
before_script:
- mysql -e 'drop database if exists caravel; create database caravel DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci' -u root
- psql -c 'create database caravel;' -U postgres
- export PATH=${PATH}:/tmp/hive/bin
install:
- pip wheel -w $HOME/.wheelhouse -f $HOME/.wheelhouse .
- pip install --find-links=$HOME/.wheelhouse --no-index .
- pip install -r dev-reqs.txt
- cd caravel/assets
- npm --version
- npm install
- npm run lint
- npm run prod
- cd $TRAVIS_BUILD_DIR
script: bash run_tests.sh
after_success:
- coveralls
- pip install --upgrade pip
- pip install tox tox-travis
script: tox -e $TOX_ENV
6 changes: 6 additions & 0 deletions caravel/assets/js_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd "$(dirname "$0")"
npm --version
npm install
npm run lint
npm run prod
174 changes: 87 additions & 87 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ function nvd3Vis(slice) {
var colorKey = 'key';

var render = function () {
$.getJSON(slice.jsonEndpoint(), function (payload) {
d3.json(slice.jsonEndpoint(), function (error, payload) {
slice.container.html('');
if (error) {
slice.error(error.responseText);
return '';
}
var fd = payload.form_data;
var viz_type = fd.viz_type;
var f = d3.format('.3s');
slice.container.html('');

nv.addGraph(function () {
switch (viz_type) {
case 'line':
if (fd.show_brush) {
chart = nv.models.lineWithFocusChart();
chart.lines2.xScale(d3.time.scale.utc());
chart
.x2Axis
chart.x2Axis
.showMaxMin(fd.x_axis_showminmax)
.staggerLabels(false);
} else {
Expand Down Expand Up @@ -133,103 +136,100 @@ function nvd3Vis(slice) {

default:
throw new Error("Unrecognized visualization for nvd3" + viz_type);
}
}

if ("showLegend" in chart && typeof fd.show_legend !== 'undefined') {
chart.showLegend(fd.show_legend);
}
if ("showLegend" in chart && typeof fd.show_legend !== 'undefined') {
chart.showLegend(fd.show_legend);
}

var height = slice.height();
height -= 15; // accounting for the staggered xAxis
var height = slice.height();
height -= 15; // accounting for the staggered xAxis

chart.height(height);
slice.container.css('height', height + 'px');
chart.height(height);
slice.container.css('height', height + 'px');

if ((viz_type === "line" || viz_type === "area") && fd.rich_tooltip) {
chart.useInteractiveGuideline(true);
}
if (fd.y_axis_zero) {
chart.forceY([0]);
} else if (fd.y_log_scale) {
chart.yScale(d3.scale.log());
}
if (fd.x_log_scale) {
chart.xScale(d3.scale.log());
}
var xAxisFormatter = null;
if (viz_type === 'bubble') {
xAxisFormatter = d3.format('.3s');
} else if (fd.x_axis_format === 'smart_date') {
xAxisFormatter = px.formatDate;
chart.xAxis.tickFormat(xAxisFormatter);
} else if (fd.x_axis_format !== undefined) {
xAxisFormatter = px.timeFormatFactory(fd.x_axis_format);
chart.xAxis.tickFormat(xAxisFormatter);
}
if ((viz_type === "line" || viz_type === "area") && fd.rich_tooltip) {
chart.useInteractiveGuideline(true);
}
if (fd.y_axis_zero) {
chart.forceY([0]);
} else if (fd.y_log_scale) {
chart.yScale(d3.scale.log());
}
if (fd.x_log_scale) {
chart.xScale(d3.scale.log());
}
var xAxisFormatter = null;
if (viz_type === 'bubble') {
xAxisFormatter = d3.format('.3s');
} else if (fd.x_axis_format === 'smart_date') {
xAxisFormatter = px.formatDate;
chart.xAxis.tickFormat(xAxisFormatter);
} else if (fd.x_axis_format !== undefined) {
xAxisFormatter = px.timeFormatFactory(fd.x_axis_format);
chart.xAxis.tickFormat(xAxisFormatter);
}

if (chart.hasOwnProperty("x2Axis")) {
chart.x2Axis.tickFormat(xAxisFormatter);
height += 30;
}
if (chart.hasOwnProperty("x2Axis")) {
chart.x2Axis.tickFormat(xAxisFormatter);
height += 30;
}

if (viz_type === 'bubble') {
chart.xAxis.tickFormat(d3.format('.3s'));
} else if (fd.x_axis_format === 'smart_date') {
chart.xAxis.tickFormat(px.formatDate);
} else if (fd.x_axis_format !== undefined) {
chart.xAxis.tickFormat(px.timeFormatFactory(fd.x_axis_format));
}
if (chart.yAxis !== undefined) {
chart.yAxis.tickFormat(d3.format('.3s'));
}
if (viz_type === 'bubble') {
chart.xAxis.tickFormat(d3.format('.3s'));
} else if (fd.x_axis_format === 'smart_date') {
chart.xAxis.tickFormat(px.formatDate);
} else if (fd.x_axis_format !== undefined) {
chart.xAxis.tickFormat(px.timeFormatFactory(fd.x_axis_format));
}
if (chart.yAxis !== undefined) {
chart.yAxis.tickFormat(d3.format('.3s'));
}

if (fd.contribution || fd.num_period_compare || viz_type === 'compare') {
chart.yAxis.tickFormat(d3.format('.3p'));
if (chart.y2Axis !== undefined) {
chart.y2Axis.tickFormat(d3.format('.3p'));
if (fd.contribution || fd.num_period_compare || viz_type === 'compare') {
chart.yAxis.tickFormat(d3.format('.3p'));
if (chart.y2Axis !== undefined) {
chart.y2Axis.tickFormat(d3.format('.3p'));
}
} else if (fd.y_axis_format) {
chart.yAxis.tickFormat(d3.format(fd.y_axis_format));

if (chart.y2Axis !== undefined) {
chart.y2Axis.tickFormat(d3.format(fd.y_axis_format));
}
}
} else if (fd.y_axis_format) {
chart.yAxis.tickFormat(d3.format(fd.y_axis_format));
chart.color(function (d, i) {
return px.color.category21(d[colorKey]);
});

if (chart.y2Axis !== undefined) {
chart.y2Axis.tickFormat(d3.format(fd.y_axis_format));
var svg = d3.select(slice.selector).select("svg");
if (svg.empty()) {
svg = d3.select(slice.selector).append("svg");
}
}
chart.color(function (d, i) {
return px.color.category21(d[colorKey]);
});

var svg = d3.select(slice.selector).select("svg");
if (svg.empty()) {
svg = d3.select(slice.selector).append("svg");
}
svg
.datum(payload.data)
.transition().duration(500)
.attr('height', height)
.call(chart);

svg
.datum(payload.data)
.transition().duration(500)
.attr('height', height)
.call(chart);
return chart;
});

return chart;
slice.done(payload);
});

slice.done(payload);
})
.fail(function (xhr) {
slice.error(xhr.responseText);
});
};

var update = function () {
if (chart && chart.update) {
chart.update();
}
};

return {
render: render,
resize: update
};
};

var update = function () {
if (chart && chart.update) {
chart.update();
}
};

return {
render: render,
resize: update
};
}

module.exports = nvd3Vis;
10 changes: 7 additions & 3 deletions caravel/bin/caravel
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ def init():
"""Inits the Caravel application"""
utils.init(caravel)

@manager.command
def version():
@manager.option(
'-v', '--verbose', action='store_true',
help="Show extra information")
def version(verbose):
"""Prints the current version number"""
s = (
"\n{boat}\n\n"
"-----------------------\n"
"Caravel {version}\n"
"-----------------------\n").format(
"-----------------------").format(
boat=ascii_art.boat, version=caravel.VERSION)
print(s)
if verbose:
print("[DB] : " + "{}".format(db.engine))

@manager.option(
'-t', '--load-test-data', action='store_true',
Expand Down
2 changes: 1 addition & 1 deletion caravel/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from logging.config import fileConfig

from alembic import context
from flask.ext.appbuilder import Base
from flask_appbuilder import Base
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,41 @@
down_revision = '956a063c52b3'

from alembic import op
import sqlalchemy as sa
from caravel import db, models
from caravel.utils import generic_find_constraint_name
import logging

naming_convention = {
"fk":
"fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
}


def find_constraint_name(upgrade=True):
cols = {'column_name'} if upgrade else {'datasource_name'}
return generic_find_constraint_name(table='columns', columns=cols, referenced='datasources')
return generic_find_constraint_name(
table='columns', columns=cols, referenced='datasources', db=db)


def upgrade():
constraint = find_constraint_name() or 'fk_columns_column_name_datasources'
with op.batch_alter_table("columns",
naming_convention=naming_convention) as batch_op:
batch_op.drop_constraint(constraint, type_="foreignkey")
batch_op.create_foreign_key('fk_columns_datasource_name_datasources', 'datasources', ['datasource_name'], ['datasource_name'])
try:
constraint = find_constraint_name() or 'fk_columns_column_name_datasources'
with op.batch_alter_table("columns",
naming_convention=naming_convention) as batch_op:
batch_op.drop_constraint(constraint, type_="foreignkey")
batch_op.create_foreign_key(
'fk_columns_datasource_name_datasources',
'datasources',
['datasource_name'], ['datasource_name'])
except:
logging.warning(
"Could not find or drop constraint on `columns`")

def downgrade():
constraint = find_constraint_name(False) or 'fk_columns_datasource_name_datasources'
with op.batch_alter_table("columns",
with op.batch_alter_table("columns",
naming_convention=naming_convention) as batch_op:
batch_op.drop_constraint(constraint, type_="foreignkey")
batch_op.create_foreign_key('fk_columns_column_name_datasources', 'datasources', ['column_name'], ['datasource_name'])
batch_op.create_foreign_key(
'fk_columns_column_name_datasources',
'datasources',
['column_name'], ['datasource_name'])
3 changes: 1 addition & 2 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ def query( # sqla
qry.compile(
engine, compile_kwargs={"literal_binds": True},),
)
print(sql)
df = pd.read_sql_query(
sql=sql,
con=engine
Expand Down Expand Up @@ -1040,7 +1039,7 @@ def generate_metrics(self):
@classmethod
def sync_to_db(cls, name, cluster):
"""Fetches metadata for that datasource and merges the Caravel db"""
print("Syncing Druid datasource [{}]".format(name))
logging.info("Syncing Druid datasource [{}]".format(name))
session = get_session()
datasource = session.query(cls).filter_by(datasource_name=name).first()
if not datasource:
Expand Down
Loading