Skip to content

Commit

Permalink
Merge pull request plotly#204 from plotly/circle-pyenv
Browse files Browse the repository at this point in the history
Circle pyenv
  • Loading branch information
theengineear committed Mar 13, 2015
2 parents c4a38a4 + bf8591d commit 7d27874
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 92 deletions.
18 changes: 12 additions & 6 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ machine:
PLOTLY_OPTIONAL_REQUIREMENTS_FILE: ${PLOTLY_PACKAGE_ROOT}/optional-requirements.txt
PLOTLY_OPTIONAL_REQUIREMENTS_FILE_2_6: ${PLOTLY_PACKAGE_ROOT}/optional-requirements-2-6.txt
dependencies:
pre:
override:

# run all the pre-written installers (this will take a *while*)
- bash circle/setup.sh

# install testing tools for circle's version of things
- PYENV_VERSION=2.7 && pip install nose coverage
override:
- PYENV_VERSION=2.7 && pip install -I .
- PYENV_VERSION=2.7 && cd ~ && python -c "import plotly"
- pip install nose coverage
- pip install -I .

# we need to cd out of the project root to ensure the install worked
- cd ~ && python -c "import plotly"

cache_directories:
- "~/.pyenv/versions" # attempt to just cache installed pyenv things
test:
override:

Expand All @@ -28,6 +34,6 @@ test:
# - sudo chmod 600 ${PLOTLY_CONFIG_DIR} && python -c "import plotly"

# test core things in the general 2.7 version that circle has
- PYENV_VERSION=2.7 && nosetests -xv plotly/tests --with-coverage --cover-package=plotly
- nosetests -xv plotly/tests --with-coverage --cover-package=plotly
- mkdir "${CIRCLE_ARTIFACTS}/2.7" || true
- coverage html -d "${CIRCLE_ARTIFACTS}/2.7" --title=2.7
9 changes: 9 additions & 0 deletions circle/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function error_exit
exit 1
}

# PYENV shims need to be infront of the rest of the path to work!
echo "adding pyenv shims to the beginning of the path in this shell"
export PATH="/home/ubuntu/.pyenv/shims:$PATH"

# for each version we want, setup a functional virtual environment
for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
echo Setting up Python ${version}
Expand All @@ -20,6 +24,11 @@ for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
export PYENV_VERSION=${version}
echo "Using pyenv version $(pyenv version)"

# this was a major issue previously, sanity check that we're using the
# version we *think* we're using (that pyenv is pointing to)
echo "python -c 'import sys; print(sys.version)'"
python -c 'import sys; print(sys.version)'

# install core requirements all versions need
pip install -r ${PLOTLY_CORE_REQUIREMENTS_FILE} ||
error_exit "${LINENO}: can't install core reqs for Python ${version}"
Expand Down
10 changes: 10 additions & 0 deletions circle/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function error_exit
exit 1
}

# PYENV shims need to be infront of the rest of the path to work!
echo "adding pyenv shims to the beginning of the path in this shell"
export PATH="/home/ubuntu/.pyenv/shims:$PATH"

# for each version we want, setup a functional virtual environment
for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
echo Testing Python ${version}
Expand All @@ -20,6 +24,12 @@ for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
export PYENV_VERSION=${version}
echo "Using pyenv version $(pyenv version)"

# this was a major issue previously, sanity check that we're using the
# version we *think* we're using (that pyenv is pointing to)
echo "python -c 'import sys; print(sys.version)'"
python -c 'import sys; print(sys.version)'


echo "install plotly (ignoring possibly cached versions)"
pip install -I ${PLOTLY_PACKAGE_ROOT} ||
error_exit "${LINENO}: can't install plotly package from project root"
Expand Down
12 changes: 10 additions & 2 deletions plotly/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
"""
import json
import sys
import six

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json

## Base Plotly Error ##

class PlotlyError(Exception):
Expand Down Expand Up @@ -49,7 +54,10 @@ def __init__(self, requests_exception):
elif content_type == 'text/plain':
self.message = requests_exception.response.content
else:
self.message = requests_exception.message
try:
self.message = requests_exception.message
except AttributeError:
self.message = 'unknown error'

def __str__(self):
return self.message
Expand Down
8 changes: 6 additions & 2 deletions plotly/grid_objs/grid_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
"""
from __future__ import absolute_import


import json
import sys
from collections import MutableSequence
from plotly import exceptions
from plotly import utils

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json

__all__ = None


Expand Down
6 changes: 5 additions & 1 deletion plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import absolute_import

import sys
import json
import warnings
import copy
import os
Expand All @@ -30,6 +29,11 @@
else:
from urllib.parse import urlparse

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json

from plotly.plotly import chunked_requests
from plotly import utils
from plotly import tools
Expand Down
28 changes: 17 additions & 11 deletions plotly/tests/test_core/test_get_figure/test_get_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from plotly import exceptions
from nose.tools import raises
import six
import json

from unittest import TestCase
from unittest import skipIf

version = six.sys.version_info[:2] # need this for conditional testing


# username for tests: 'plotlyimagetest'
Expand Down Expand Up @@ -198,12 +198,18 @@ def test_all():

class TestBytesVStrings(TestCase):

@skipIf(not six.PY3, 'Decoding and missing escapes is only seen in PY3')
def test_proper_escaping(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/91/"
py.sign_in(un, ak)
print("getting: https://plot.ly/~PlotlyImageTest/91/")
print("###########################################\n\n")
fig = py.get_figure(url)
# unittest `skipIf` not supported in 2.6
if version < (2, 7) or (2, 7) < version < (3, 3):
pass
else:
from unittest import skipIf

@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
def test_proper_escaping(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/91/"
py.sign_in(un, ak)
print("getting: https://plot.ly/~PlotlyImageTest/91/")
print("###########################################\n\n")
fig = py.get_figure(url)
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

import requests
import copy
import json
import six
import sys

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json

default_headers = {'plotly-username': '',
'plotly-apikey': '',
Expand Down
7 changes: 6 additions & 1 deletion plotly/tests/test_core/test_utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import json
import sys
from unittest import TestCase

from plotly.utils import PlotlyJSONEncoder

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json


class TestJSONEncoder(TestCase):

Expand Down
3 changes: 2 additions & 1 deletion plotly/tests/test_optional/test_ipython/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import threading
import six
import unittest
from unittest import skip
version = six.sys.version_info[:2] # need this for conditional testing

# unittest `skipIf` not supported in 2.6 and IPython not supported in 2.6/3.2
if version < (2, 7) or (2, 7) < version < (3, 3):
pass
else:
from unittest import skip

@skip
class TestPlotlyDisplay(unittest.TestCase):

Expand Down
15 changes: 11 additions & 4 deletions plotly/tests/test_optional/test_ipython/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import six
from unittest import TestCase

from plotly.widgets import GraphWidget
version = six.sys.version_info[:2] # need this for conditional testing

# unittest `skip` not supported in 2.6 and IPython not supported in 2.6/3.2
if version < (2, 7) or (2, 7) < version < (3, 3):
pass
else:
from plotly.widgets import GraphWidget

class TestWidgets(TestCase):

def test_instantiate_graph_widget(self):
widget = GraphWidget
class TestWidgets(TestCase):

def test_instantiate_graph_widget(self):
widget = GraphWidget
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_pandas_time_series_date_formatter(self):

x0 = fig.axes[0].lines[0].get_xydata()[0][0]
self.assertEqual(x0, expected_x0)
self.assertListEqual(pfig['data'][0]['x'], expected_x)
self.assertEqual(pfig['data'][0]['x'], expected_x)
17 changes: 9 additions & 8 deletions plotly/tests/test_optional/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import json
import pandas as pd
import sys
from pandas.util.testing import assert_series_equal
import matplotlib.pyplot as plt

Expand All @@ -27,7 +28,7 @@ def test_encode_as_plotly(self):

# should *fail* when object doesn't have `to_plotly_json` attribute
objs_without_attr = [
1, 'one', {'a', 'set'}, {'a': 'dict'}, ['a', 'list']
1, 'one', set(['a', 'set']), {'a': 'dict'}, ['a', 'list']
]
for obj in objs_without_attr:
self.assertRaises(utils.NotEncodable,
Expand All @@ -48,7 +49,7 @@ def test_encode_as_list(self):

# should *fail* when object doesn't have `tolist` method
objs_without_attr = [
1, 'one', {'a', 'set'}, {'a': 'dict'}, ['a', 'list']
1, 'one', set(['a', 'set']), {'a': 'dict'}, ['a', 'list']
]
for obj in objs_without_attr:
self.assertRaises(utils.NotEncodable,
Expand All @@ -75,7 +76,7 @@ def test_encode_as_pandas(self):

# should succeed when we've got specific pandas thingies
res = utils.PlotlyJSONEncoder.encode_as_pandas(pd.NaT)
self.assertIs(res, None)
self.assertTrue(res is None)

def test_encode_as_numpy(self):

Expand Down Expand Up @@ -132,7 +133,7 @@ def test_encode_as_date(self):
utils.PlotlyJSONEncoder.encode_as_date, obj)

# should work with a date
a_date = datetime.date(2013, 10, 01)
a_date = datetime.date(2013, 10, 1)
res = utils.PlotlyJSONEncoder.encode_as_date(a_date)
self.assertEqual(res, '2013-10-01')

Expand Down Expand Up @@ -248,9 +249,8 @@ def test_pandas_json_encoding():
def test_numpy_masked_json_encoding():
l = [1, 2, np.ma.core.masked]
j1 = json.dumps(l, cls=utils.PlotlyJSONEncoder)
print j1
print(j1)
assert(j1 == '[1, 2, null]')
assert(set(l) == set([1, 2, np.ma.core.masked]))


def test_masked_constants_example():
Expand All @@ -275,8 +275,9 @@ def test_masked_constants_example():

jy = json.dumps(renderer.plotly_fig['data'][1]['y'],
cls=utils.PlotlyJSONEncoder)
assert(jy == '[-398.11793026999999, -398.11792966000002, '
'-398.11786308000001, null]')
print(jy)
array = json.loads(jy)
assert(array == [-398.11793027, -398.11792966, -398.11786308, None])


def test_numpy_dates():
Expand Down
Loading

0 comments on commit 7d27874

Please sign in to comment.