Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a97c888

Browse files
committed
Merge pull request plotly#220 from plotly/manifest-file
Manifest file
2 parents a5f5067 + 642dece commit a97c888

File tree

6 files changed

+68
-33
lines changed

6 files changed

+68
-33
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include plotly/graph_reference/*.json
2+
include plotly/widgets/*.js

plotly/graph_objs/graph_objs_tools.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
from __future__ import absolute_import
2-
from plotly import utils
32
import textwrap
43
import os
54
import sys
5+
6+
from plotly import utils
7+
from plotly.resources import (GRAPH_REFERENCE_GRAPH_OBJS_META,
8+
GRAPH_REFERENCE_NAME_TO_KEY,
9+
GRAPH_REFERENCE_KEY_TO_NAME,
10+
GRAPH_REFERENCE_OBJ_MAP, GRAPH_REFERENCE_DIR)
11+
612
if sys.version[:3] == '2.6':
713
try:
814
from ordereddict import OrderedDict
@@ -19,23 +25,27 @@
1925
import json
2026
import six
2127

22-
from pkg_resources import resource_string
23-
2428

25-
# Define graph reference loader
2629
def _load_graph_ref():
27-
graph_reference_dir = 'graph_reference'
28-
json_files = [
29-
'graph_objs_meta.json',
30-
'OBJ_MAP.json',
31-
'NAME_TO_KEY.json',
32-
'KEY_TO_NAME.json'
33-
]
30+
"""
31+
A private method to load the graph reference json files.
32+
33+
:return: (tuple) A tuple of dict objects.
34+
35+
"""
3436
out = []
35-
for json_file in json_files:
36-
relative_path = os.path.join(graph_reference_dir, json_file)
37-
s = resource_string('plotly', relative_path).decode('utf-8')
38-
tmp = json.loads(s, object_pairs_hook=OrderedDict)
37+
38+
# this splits directory path from basenames
39+
filenames = [
40+
os.path.split(GRAPH_REFERENCE_GRAPH_OBJS_META)[-1],
41+
os.path.split(GRAPH_REFERENCE_OBJ_MAP)[-1],
42+
os.path.split(GRAPH_REFERENCE_NAME_TO_KEY)[-1],
43+
os.path.split(GRAPH_REFERENCE_KEY_TO_NAME)[-1]
44+
]
45+
for filename in filenames:
46+
path = os.path.join(sys.prefix, GRAPH_REFERENCE_DIR, filename)
47+
with open(path, 'r') as f:
48+
tmp = json.load(f, object_pairs_hook=OrderedDict)
3949
tmp = utils.decode_unicode(tmp)
4050
out += [tmp]
4151
return tuple(out)

plotly/resources.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
This module defines where non-python source files are located.
3+
4+
All paths are relative to sys.prefix. This is why they are in a plotly-specific
5+
'plotly-data' directory.
6+
7+
"""
8+
import os
9+
10+
# This is relative to `sys.prefix`. We store non-python files here.
11+
DATA_DIR = 'plotly-data'
12+
13+
# For graph object definitions and local error handling
14+
GRAPH_REFERENCE_DIR = os.path.join(DATA_DIR, 'graph_reference')
15+
GRAPH_REFERENCE_GRAPH_OBJS_META = 'plotly/graph_reference/graph_objs_meta.json'
16+
GRAPH_REFERENCE_KEY_TO_NAME = 'plotly/graph_reference/KEY_TO_NAME.json'
17+
GRAPH_REFERENCE_NAME_TO_KEY = 'plotly/graph_reference/NAME_TO_KEY.json'
18+
GRAPH_REFERENCE_OBJ_MAP = 'plotly/graph_reference/OBJ_MAP.json'
19+
GRAPH_REFERENCE_FILES = [GRAPH_REFERENCE_GRAPH_OBJS_META,
20+
GRAPH_REFERENCE_KEY_TO_NAME,
21+
GRAPH_REFERENCE_NAME_TO_KEY,
22+
GRAPH_REFERENCE_OBJ_MAP]
23+
24+
# For IPython widget support
25+
WIDGETS_DIR = os.path.join(DATA_DIR, 'widgets')
26+
WIDGETS_MAIN_JS = 'plotly/widgets/graphWidget.js'
27+
WIDGETS_FILES = [WIDGETS_MAIN_JS]

plotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.6.17'
1+
__version__ = '1.6.18'

plotly/widgets/graph_widget.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from collections import deque
2-
import uuid
1+
import os
32
import sys
3+
import uuid
4+
from collections import deque
45

56
# TODO: protected imports?
67
from IPython.html import widgets
@@ -10,7 +11,7 @@
1011
import plotly.plotly.plotly as py
1112
from plotly import utils, tools
1213
from plotly.graph_objs import Figure
13-
from pkg_resources import resource_string
14+
from plotly.resources import WIDGETS_DIR, WIDGETS_MAIN_JS
1415

1516
# even though python 2.6 wouldn't be able to run *any* of this...
1617
if sys.version[:3] == '2.6':
@@ -21,8 +22,10 @@
2122
# Load JS widget code
2223
# No officially recommended way to do this in any other way
2324
# http://mail.scipy.org/pipermail/ipython-dev/2014-April/013835.html
24-
js_widget_code = resource_string('plotly',
25-
'widgets/graphWidget.js').decode('utf-8')
25+
js_file_path = os.path.join(sys.prefix, WIDGETS_DIR,
26+
os.path.split(WIDGETS_MAIN_JS)[-1])
27+
with open(js_file_path, 'r') as f:
28+
js_widget_code = f.read()
2629

2730
display(Javascript(js_widget_code))
2831

setup.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from setuptools import setup
1+
from setuptools import setup, find_packages
22

33
exec (open('plotly/version.py').read())
4+
exec (open('plotly/resources.py').read())
45

56

67
def readme():
78
with open('README.rst') as f:
89
return f.read()
910

10-
1111
setup(name='plotly',
1212
version=__version__,
1313
use_2to3=False,
@@ -31,16 +31,9 @@ def readme():
3131
'Topic :: Scientific/Engineering :: Visualization',
3232
],
3333
license='MIT',
34-
packages=['plotly',
35-
'plotly/plotly',
36-
'plotly/plotly/chunked_requests',
37-
'plotly/graph_objs',
38-
'plotly/grid_objs',
39-
'plotly/widgets',
40-
'plotly/matplotlylib',
41-
'plotly/matplotlylib/mplexporter',
42-
'plotly/matplotlylib/mplexporter/renderers'],
43-
package_data={'plotly': ['graph_reference/*.json', 'widgets/*.js']},
34+
packages=find_packages(),
35+
data_files=[(GRAPH_REFERENCE_DIR, GRAPH_REFERENCE_FILES),
36+
(WIDGETS_DIR, WIDGETS_FILES)],
4437
install_requires=['requests[security]', 'six', 'pytz'],
4538
extras_require={"PY2.6": ['simplejson', 'ordereddict',
4639
'requests[security]']},

0 commit comments

Comments
 (0)