Skip to content

Commit 5085fa0

Browse files
etpinardtheengineear
authored andcommitted
load graph reference from pkg copy of plot schema
- instead of making a request to plot.ly to grab the most up-to-date schema Conflicts: plotly/graph_reference.py plotly/tests/test_core/test_graph_reference/test_graph_reference.py
1 parent 5886831 commit 5085fa0

File tree

5 files changed

+92
-1727
lines changed

5 files changed

+92
-1727
lines changed

plotly/api/v2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from __future__ import absolute_import
22

3-
from plotly.api.v2 import files, folders, grids, images, plot_schema, plots
3+
from plotly.api.v2 import files, folders, grids, images, plots

plotly/graph_reference.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
"""
55
from __future__ import absolute_import
66

7-
import hashlib
87
import os
98
import re
109
from pkg_resources import resource_string
1110

1211
import six
1312
from requests.compat import json as _json
1413

15-
from plotly import exceptions, files, utils
16-
from plotly.api import v2
17-
18-
GRAPH_REFERENCE_DOWNLOAD_TIMEOUT = 5 # seconds
14+
from plotly import utils
1915

2016

2117
# For backwards compat, we keep this list of previously known objects.
@@ -65,32 +61,14 @@
6561

6662
def get_graph_reference():
6763
"""
68-
Attempts to load local copy of graph reference or makes GET request if DNE.
64+
Load graph reference JSON (aka plot-schema)
6965
7066
:return: (dict) The graph reference.
71-
:raises: (PlotlyError) When graph reference DNE and GET request fails.
7267
7368
"""
74-
if files.check_file_permissions():
75-
graph_reference = utils.load_json_dict(files.GRAPH_REFERENCE_FILE)
76-
else:
77-
graph_reference = {}
78-
79-
sha1 = hashlib.sha1(six.b(str(graph_reference))).hexdigest()
80-
81-
try:
82-
response = v2.plot_schema.retrieve(
83-
sha1, timeout=GRAPH_REFERENCE_DOWNLOAD_TIMEOUT
84-
)
85-
except exceptions.PlotlyRequestError:
86-
if not graph_reference:
87-
path = os.path.join('graph_reference', 'default-schema.json')
88-
s = resource_string('plotly', path).decode('utf-8')
89-
graph_reference = _json.loads(s)
90-
else:
91-
data = response.json()
92-
if data['modified']:
93-
graph_reference = data['schema']
69+
path = os.path.join('graph_reference', 'default-schema.json')
70+
s = resource_string('plotly', path).decode('utf-8')
71+
graph_reference = _json.loads(s)
9472

9573
return utils.decode_unicode(graph_reference)
9674

0 commit comments

Comments
 (0)