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

Skip to content

Manifest file #220

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

Merged
merged 10 commits into from
May 26, 2015
Merged
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include plotly/graph_reference/*.json
include plotly/widgets/*.js
40 changes: 25 additions & 15 deletions plotly/graph_objs/graph_objs_tools.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from __future__ import absolute_import
from plotly import utils
import textwrap
import os
import sys

from plotly import utils
from plotly.resources import (GRAPH_REFERENCE_GRAPH_OBJS_META,
GRAPH_REFERENCE_NAME_TO_KEY,
GRAPH_REFERENCE_KEY_TO_NAME,
GRAPH_REFERENCE_OBJ_MAP, GRAPH_REFERENCE_DIR)

if sys.version[:3] == '2.6':
try:
from ordereddict import OrderedDict
Expand All @@ -19,23 +25,27 @@
import json
import six

from pkg_resources import resource_string


# Define graph reference loader
def _load_graph_ref():
graph_reference_dir = 'graph_reference'
json_files = [
'graph_objs_meta.json',
'OBJ_MAP.json',
'NAME_TO_KEY.json',
'KEY_TO_NAME.json'
]
"""
A private method to load the graph reference json files.

:return: (tuple) A tuple of dict objects.

"""
out = []
for json_file in json_files:
relative_path = os.path.join(graph_reference_dir, json_file)
s = resource_string('plotly', relative_path).decode('utf-8')
tmp = json.loads(s, object_pairs_hook=OrderedDict)

# this splits directory path from basenames
filenames = [
os.path.split(GRAPH_REFERENCE_GRAPH_OBJS_META)[-1],
os.path.split(GRAPH_REFERENCE_OBJ_MAP)[-1],
os.path.split(GRAPH_REFERENCE_NAME_TO_KEY)[-1],
os.path.split(GRAPH_REFERENCE_KEY_TO_NAME)[-1]
]
for filename in filenames:
path = os.path.join(sys.prefix, GRAPH_REFERENCE_DIR, filename)
with open(path, 'r') as f:
tmp = json.load(f, object_pairs_hook=OrderedDict)
tmp = utils.decode_unicode(tmp)
out += [tmp]
return tuple(out)
Expand Down
27 changes: 27 additions & 0 deletions plotly/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
This module defines where non-python source files are located.

All paths are relative to sys.prefix. This is why they are in a plotly-specific
'plotly-data' directory.

"""
import os

# This is relative to `sys.prefix`. We store non-python files here.
DATA_DIR = 'plotly-data'

# For graph object definitions and local error handling
GRAPH_REFERENCE_DIR = os.path.join(DATA_DIR, 'graph_reference')
GRAPH_REFERENCE_GRAPH_OBJS_META = 'plotly/graph_reference/graph_objs_meta.json'
GRAPH_REFERENCE_KEY_TO_NAME = 'plotly/graph_reference/KEY_TO_NAME.json'
GRAPH_REFERENCE_NAME_TO_KEY = 'plotly/graph_reference/NAME_TO_KEY.json'
GRAPH_REFERENCE_OBJ_MAP = 'plotly/graph_reference/OBJ_MAP.json'
GRAPH_REFERENCE_FILES = [GRAPH_REFERENCE_GRAPH_OBJS_META,
GRAPH_REFERENCE_KEY_TO_NAME,
GRAPH_REFERENCE_NAME_TO_KEY,
GRAPH_REFERENCE_OBJ_MAP]

# For IPython widget support
WIDGETS_DIR = os.path.join(DATA_DIR, 'widgets')
WIDGETS_MAIN_JS = 'plotly/widgets/graphWidget.js'
WIDGETS_FILES = [WIDGETS_MAIN_JS]
2 changes: 1 addition & 1 deletion plotly/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.6.17'
__version__ = '1.6.18'
13 changes: 8 additions & 5 deletions plotly/widgets/graph_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import deque
import uuid
import os
import sys
import uuid
from collections import deque

# TODO: protected imports?
from IPython.html import widgets
Expand All @@ -10,7 +11,7 @@
import plotly.plotly.plotly as py
from plotly import utils, tools
from plotly.graph_objs import Figure
from pkg_resources import resource_string
from plotly.resources import WIDGETS_DIR, WIDGETS_MAIN_JS

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

display(Javascript(js_widget_code))

Expand Down
17 changes: 5 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from setuptools import setup
from setuptools import setup, find_packages

exec (open('plotly/version.py').read())
exec (open('plotly/resources.py').read())


def readme():
with open('README.rst') as f:
return f.read()


setup(name='plotly',
version=__version__,
use_2to3=False,
Expand All @@ -31,16 +31,9 @@ def readme():
'Topic :: Scientific/Engineering :: Visualization',
],
license='MIT',
packages=['plotly',
'plotly/plotly',
'plotly/plotly/chunked_requests',
'plotly/graph_objs',
'plotly/grid_objs',
'plotly/widgets',
'plotly/matplotlylib',
'plotly/matplotlylib/mplexporter',
'plotly/matplotlylib/mplexporter/renderers'],
package_data={'plotly': ['graph_reference/*.json', 'widgets/*.js']},
packages=find_packages(),
data_files=[(GRAPH_REFERENCE_DIR, GRAPH_REFERENCE_FILES),
(WIDGETS_DIR, WIDGETS_FILES)],
install_requires=['requests[security]', 'six', 'pytz'],
extras_require={"PY2.6": ['simplejson', 'ordereddict',
'requests[security]']},
Expand Down