Skip to content

Commit 7d27874

Browse files
committed
Merge pull request #204 from plotly/circle-pyenv
Circle pyenv
2 parents c4a38a4 + bf8591d commit 7d27874

File tree

16 files changed

+147
-92
lines changed

16 files changed

+147
-92
lines changed

circle.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ machine:
77
PLOTLY_OPTIONAL_REQUIREMENTS_FILE: ${PLOTLY_PACKAGE_ROOT}/optional-requirements.txt
88
PLOTLY_OPTIONAL_REQUIREMENTS_FILE_2_6: ${PLOTLY_PACKAGE_ROOT}/optional-requirements-2-6.txt
99
dependencies:
10-
pre:
10+
override:
11+
1112
# run all the pre-written installers (this will take a *while*)
1213
- bash circle/setup.sh
14+
1315
# install testing tools for circle's version of things
14-
- PYENV_VERSION=2.7 && pip install nose coverage
15-
override:
16-
- PYENV_VERSION=2.7 && pip install -I .
17-
- PYENV_VERSION=2.7 && cd ~ && python -c "import plotly"
16+
- pip install nose coverage
17+
- pip install -I .
18+
19+
# we need to cd out of the project root to ensure the install worked
20+
- cd ~ && python -c "import plotly"
21+
22+
cache_directories:
23+
- "~/.pyenv/versions" # attempt to just cache installed pyenv things
1824
test:
1925
override:
2026

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

3036
# test core things in the general 2.7 version that circle has
31-
- PYENV_VERSION=2.7 && nosetests -xv plotly/tests --with-coverage --cover-package=plotly
37+
- nosetests -xv plotly/tests --with-coverage --cover-package=plotly
3238
- mkdir "${CIRCLE_ARTIFACTS}/2.7" || true
3339
- coverage html -d "${CIRCLE_ARTIFACTS}/2.7" --title=2.7

circle/setup.sh

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function error_exit
1212
exit 1
1313
}
1414

15+
# PYENV shims need to be infront of the rest of the path to work!
16+
echo "adding pyenv shims to the beginning of the path in this shell"
17+
export PATH="/home/ubuntu/.pyenv/shims:$PATH"
18+
1519
# for each version we want, setup a functional virtual environment
1620
for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
1721
echo Setting up Python ${version}
@@ -20,6 +24,11 @@ for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
2024
export PYENV_VERSION=${version}
2125
echo "Using pyenv version $(pyenv version)"
2226

27+
# this was a major issue previously, sanity check that we're using the
28+
# version we *think* we're using (that pyenv is pointing to)
29+
echo "python -c 'import sys; print(sys.version)'"
30+
python -c 'import sys; print(sys.version)'
31+
2332
# install core requirements all versions need
2433
pip install -r ${PLOTLY_CORE_REQUIREMENTS_FILE} ||
2534
error_exit "${LINENO}: can't install core reqs for Python ${version}"

circle/test.sh

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function error_exit
1212
exit 1
1313
}
1414

15+
# PYENV shims need to be infront of the rest of the path to work!
16+
echo "adding pyenv shims to the beginning of the path in this shell"
17+
export PATH="/home/ubuntu/.pyenv/shims:$PATH"
18+
1519
# for each version we want, setup a functional virtual environment
1620
for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
1721
echo Testing Python ${version}
@@ -20,6 +24,12 @@ for version in ${PLOTLY_PYTHON_VERSIONS[@]}; do
2024
export PYENV_VERSION=${version}
2125
echo "Using pyenv version $(pyenv version)"
2226

27+
# this was a major issue previously, sanity check that we're using the
28+
# version we *think* we're using (that pyenv is pointing to)
29+
echo "python -c 'import sys; print(sys.version)'"
30+
python -c 'import sys; print(sys.version)'
31+
32+
2333
echo "install plotly (ignoring possibly cached versions)"
2434
pip install -I ${PLOTLY_PACKAGE_ROOT} ||
2535
error_exit "${LINENO}: can't install plotly package from project root"

plotly/exceptions.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
1616
1717
"""
18-
import json
18+
import sys
1919
import six
2020

21+
if sys.version[:3] == '2.6':
22+
import simplejson as json
23+
else:
24+
import json
25+
2126
## Base Plotly Error ##
2227

2328
class PlotlyError(Exception):
@@ -49,7 +54,10 @@ def __init__(self, requests_exception):
4954
elif content_type == 'text/plain':
5055
self.message = requests_exception.response.content
5156
else:
52-
self.message = requests_exception.message
57+
try:
58+
self.message = requests_exception.message
59+
except AttributeError:
60+
self.message = 'unknown error'
5361

5462
def __str__(self):
5563
return self.message

plotly/grid_objs/grid_objs.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
"""
66
from __future__ import absolute_import
77

8-
9-
import json
8+
import sys
109
from collections import MutableSequence
1110
from plotly import exceptions
1211
from plotly import utils
1312

13+
if sys.version[:3] == '2.6':
14+
import simplejson as json
15+
else:
16+
import json
17+
1418
__all__ = None
1519

1620

plotly/plotly/plotly.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import absolute_import
1818

1919
import sys
20-
import json
2120
import warnings
2221
import copy
2322
import os
@@ -30,6 +29,11 @@
3029
else:
3130
from urllib.parse import urlparse
3231

32+
if sys.version[:3] == '2.6':
33+
import simplejson as json
34+
else:
35+
import json
36+
3337
from plotly.plotly import chunked_requests
3438
from plotly import utils
3539
from plotly import tools

plotly/tests/test_core/test_get_figure/test_get_figure.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from plotly import exceptions
1111
from nose.tools import raises
1212
import six
13-
import json
1413

1514
from unittest import TestCase
16-
from unittest import skipIf
15+
16+
version = six.sys.version_info[:2] # need this for conditional testing
1717

1818

1919
# username for tests: 'plotlyimagetest'
@@ -198,12 +198,18 @@ def test_all():
198198

199199
class TestBytesVStrings(TestCase):
200200

201-
@skipIf(not six.PY3, 'Decoding and missing escapes is only seen in PY3')
202-
def test_proper_escaping(self):
203-
un = 'PlotlyImageTest'
204-
ak = '786r5mecv0'
205-
url = "https://plot.ly/~PlotlyImageTest/91/"
206-
py.sign_in(un, ak)
207-
print("getting: https://plot.ly/~PlotlyImageTest/91/")
208-
print("###########################################\n\n")
209-
fig = py.get_figure(url)
201+
# unittest `skipIf` not supported in 2.6
202+
if version < (2, 7) or (2, 7) < version < (3, 3):
203+
pass
204+
else:
205+
from unittest import skipIf
206+
207+
@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
208+
def test_proper_escaping(self):
209+
un = 'PlotlyImageTest'
210+
ak = '786r5mecv0'
211+
url = "https://plot.ly/~PlotlyImageTest/91/"
212+
py.sign_in(un, ak)
213+
print("getting: https://plot.ly/~PlotlyImageTest/91/")
214+
print("###########################################\n\n")
215+
fig = py.get_figure(url)

plotly/tests/test_core/test_get_requests/test_get_requests.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
import requests
1010
import copy
11-
import json
1211
import six
12+
import sys
13+
14+
if sys.version[:3] == '2.6':
15+
import simplejson as json
16+
else:
17+
import json
1318

1419
default_headers = {'plotly-username': '',
1520
'plotly-apikey': '',

plotly/tests/test_core/test_utils/test_utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import json
1+
import sys
22
from unittest import TestCase
33

44
from plotly.utils import PlotlyJSONEncoder
55

6+
if sys.version[:3] == '2.6':
7+
import simplejson as json
8+
else:
9+
import json
10+
611

712
class TestJSONEncoder(TestCase):
813

plotly/tests/test_optional/test_ipython/test_embed.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import threading
66
import six
77
import unittest
8-
from unittest import skip
98
version = six.sys.version_info[:2] # need this for conditional testing
109

1110
# unittest `skipIf` not supported in 2.6 and IPython not supported in 2.6/3.2
1211
if version < (2, 7) or (2, 7) < version < (3, 3):
1312
pass
1413
else:
14+
from unittest import skip
15+
1516
@skip
1617
class TestPlotlyDisplay(unittest.TestCase):
1718

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import six
12
from unittest import TestCase
23

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

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

6-
class TestWidgets(TestCase):
712

8-
def test_instantiate_graph_widget(self):
9-
widget = GraphWidget
13+
class TestWidgets(TestCase):
14+
15+
def test_instantiate_graph_widget(self):
16+
widget = GraphWidget

plotly/tests/test_optional/test_matplotlylib/test_date_times.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ def test_pandas_time_series_date_formatter(self):
6464

6565
x0 = fig.axes[0].lines[0].get_xydata()[0][0]
6666
self.assertEqual(x0, expected_x0)
67-
self.assertListEqual(pfig['data'][0]['x'], expected_x)
67+
self.assertEqual(pfig['data'][0]['x'], expected_x)

plotly/tests/test_optional/test_utils/test_utils.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
import json
1313
import pandas as pd
14+
import sys
1415
from pandas.util.testing import assert_series_equal
1516
import matplotlib.pyplot as plt
1617

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

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

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

7677
# should succeed when we've got specific pandas thingies
7778
res = utils.PlotlyJSONEncoder.encode_as_pandas(pd.NaT)
78-
self.assertIs(res, None)
79+
self.assertTrue(res is None)
7980

8081
def test_encode_as_numpy(self):
8182

@@ -132,7 +133,7 @@ def test_encode_as_date(self):
132133
utils.PlotlyJSONEncoder.encode_as_date, obj)
133134

134135
# should work with a date
135-
a_date = datetime.date(2013, 10, 01)
136+
a_date = datetime.date(2013, 10, 1)
136137
res = utils.PlotlyJSONEncoder.encode_as_date(a_date)
137138
self.assertEqual(res, '2013-10-01')
138139

@@ -248,9 +249,8 @@ def test_pandas_json_encoding():
248249
def test_numpy_masked_json_encoding():
249250
l = [1, 2, np.ma.core.masked]
250251
j1 = json.dumps(l, cls=utils.PlotlyJSONEncoder)
251-
print j1
252+
print(j1)
252253
assert(j1 == '[1, 2, null]')
253-
assert(set(l) == set([1, 2, np.ma.core.masked]))
254254

255255

256256
def test_masked_constants_example():
@@ -275,8 +275,9 @@ def test_masked_constants_example():
275275

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

281282

282283
def test_numpy_dates():

0 commit comments

Comments
 (0)