From 8817481f758eeb0610b8c77fb9dd15dbdc37579b Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 16:25:59 -0700 Subject: [PATCH 1/9] Use `find_packages()` like all the cool kids do. --- setup.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 5b67b450378..5e0ed41b1ca 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup +from setuptools import setup, find_packages exec (open('plotly/version.py').read()) @@ -31,15 +32,7 @@ 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'], + packages=find_packages(), package_data={'plotly': ['graph_reference/*.json', 'widgets/*.js']}, install_requires=['requests', 'six', 'pytz'], extras_require={"PY2.6": ['simplejson', 'ordereddict', From 1b3766d7fe1d836f827eba58cb0886f67533f3af Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 16:28:22 -0700 Subject: [PATCH 2/9] To be *extra* sure. Create a MANIFEST.in as well. --- MANIFEST.in | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000000..a166475f1d8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include /plotly/graph_reference/*.json +include /plotly/widgets/*.js From 37b14647b839be9e28c82a117ecaebe6fa2ddd34 Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 17:55:25 -0700 Subject: [PATCH 3/9] Add resources file locating all non-python files. --- plotly/resources.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plotly/resources.py diff --git a/plotly/resources.py b/plotly/resources.py new file mode 100644 index 00000000000..3895dbf842f --- /dev/null +++ b/plotly/resources.py @@ -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] From 7ff6a6e7ed7c11692e93a267f25ef26ab62d717c Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 17:55:37 -0700 Subject: [PATCH 4/9] Fix bad paths in MAINFEST.in --- MANIFEST.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index a166475f1d8..721f474d95a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include /plotly/graph_reference/*.json -include /plotly/widgets/*.js +include plotly/graph_reference/*.json +include plotly/widgets/*.js From 18253710908bb191e06c7066dbab0c5c36b4fecb Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 17:57:03 -0700 Subject: [PATCH 5/9] Use resources file in setup.py. --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 5e0ed41b1ca..a589591fdee 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ from setuptools import setup, find_packages exec (open('plotly/version.py').read()) +exec (open('plotly/resources.py').read()) def readme(): @@ -33,6 +34,8 @@ def readme(): ], license='MIT', packages=find_packages(), + data_files=[(GRAPH_REFERENCE_DIR, GRAPH_REFERENCE_FILES), + (WIDGETS_DIR, WIDGETS_FILES)], package_data={'plotly': ['graph_reference/*.json', 'widgets/*.js']}, install_requires=['requests', 'six', 'pytz'], extras_require={"PY2.6": ['simplejson', 'ordereddict', From bde22fd20bab633fdce529eb87b11f7b3e008e3a Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 18:01:15 -0700 Subject: [PATCH 6/9] Switch to new resource-fetching scheme. --- plotly/graph_objs/graph_objs_tools.py | 37 +++++++++++++++++---------- plotly/widgets/graph_widget.py | 9 ++++--- setup.py | 1 - 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/plotly/graph_objs/graph_objs_tools.py b/plotly/graph_objs/graph_objs_tools.py index e828df7fd5e..30d838a2912 100644 --- a/plotly/graph_objs/graph_objs_tools.py +++ b/plotly/graph_objs/graph_objs_tools.py @@ -3,6 +3,11 @@ import textwrap import os import sys +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 @@ -19,23 +24,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) diff --git a/plotly/widgets/graph_widget.py b/plotly/widgets/graph_widget.py index 1f5ec836de5..890be8b91b3 100644 --- a/plotly/widgets/graph_widget.py +++ b/plotly/widgets/graph_widget.py @@ -1,5 +1,6 @@ from collections import deque import uuid +import os import sys # TODO: protected imports? @@ -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': @@ -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().decode('utf-8') display(Javascript(js_widget_code)) diff --git a/setup.py b/setup.py index a589591fdee..bd0224dda68 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ def readme(): packages=find_packages(), data_files=[(GRAPH_REFERENCE_DIR, GRAPH_REFERENCE_FILES), (WIDGETS_DIR, WIDGETS_FILES)], - package_data={'plotly': ['graph_reference/*.json', 'widgets/*.js']}, install_requires=['requests', 'six', 'pytz'], extras_require={"PY2.6": ['simplejson', 'ordereddict', 'requests[security]']}, From 30c2f4ad8a5f62236f88cd7fe8471abf1ff4ba07 Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 18:01:35 -0700 Subject: [PATCH 7/9] A little cleanup. --- plotly/graph_objs/graph_objs_tools.py | 3 ++- plotly/widgets/graph_widget.py | 4 ++-- setup.py | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plotly/graph_objs/graph_objs_tools.py b/plotly/graph_objs/graph_objs_tools.py index 30d838a2912..0b782cef349 100644 --- a/plotly/graph_objs/graph_objs_tools.py +++ b/plotly/graph_objs/graph_objs_tools.py @@ -1,8 +1,9 @@ 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, diff --git a/plotly/widgets/graph_widget.py b/plotly/widgets/graph_widget.py index 890be8b91b3..61e3f4461f8 100644 --- a/plotly/widgets/graph_widget.py +++ b/plotly/widgets/graph_widget.py @@ -1,7 +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 diff --git a/setup.py b/setup.py index bd0224dda68..98dda778059 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -from setuptools import setup from setuptools import setup, find_packages exec (open('plotly/version.py').read()) @@ -9,7 +8,6 @@ def readme(): with open('README.rst') as f: return f.read() - setup(name='plotly', version=__version__, use_2to3=False, From a8ea810a411d2dd3af7d83daf39239a551bb2e20 Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 18:02:24 -0700 Subject: [PATCH 8/9] =?UTF-8?q?version=20bump=20=E2=80=94>=201.6.18=20(dit?= =?UTF-8?q?ch=20pkg=5Fresources!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plotly/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/version.py b/plotly/version.py index 1ab8ed42c96..34382a93fb7 100644 --- a/plotly/version.py +++ b/plotly/version.py @@ -1 +1 @@ -__version__ = '1.6.17' +__version__ = '1.6.18' From cb37c6a64b6fc6c48b52eb3d0e0ff3828dee679d Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Sun, 24 May 2015 18:17:42 -0700 Subject: [PATCH 9/9] =?UTF-8?q?Remove=20decode=20now=20that=20we=20don?= =?UTF-8?q?=E2=80=99t=20have=20to!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plotly/widgets/graph_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/widgets/graph_widget.py b/plotly/widgets/graph_widget.py index 61e3f4461f8..9a1ce85f458 100644 --- a/plotly/widgets/graph_widget.py +++ b/plotly/widgets/graph_widget.py @@ -25,7 +25,7 @@ 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().decode('utf-8') + js_widget_code = f.read() display(Javascript(js_widget_code))