Skip to content

Commit

Permalink
Updated holoviews.examples to copy examples directory
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 28, 2017
1 parent 356b9fe commit 4f9068b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
39 changes: 13 additions & 26 deletions holoviews/__init__.py
@@ -1,6 +1,6 @@

from __future__ import print_function, absolute_import
import os, sys, pydoc
import os, sys, pydoc, shutil

import numpy as np # noqa (API import)

Expand Down Expand Up @@ -92,28 +92,15 @@ def examples(path='holoviews-examples', verbose=False, force=False):
"""
Copies the notebooks to the supplied path.
"""
import glob
from shutil import copytree, ignore_patterns, copyfile

# A dictionary defining the example files to collect structured
# into subfolders along with globs and file type extensions
example_files = {'notebooks': [('../doc/Tutorials/*.{ext}', ('ipynb',))],
'assets': [('../doc/assets/*.{ext}', ('png', 'svg', 'rst'))]}

packaged_examples = os.path.join(__path__[0], './examples')
if os.path.exists(packaged_examples) and not force:
copytree(packaged_examples, path, ignore=ignore_patterns('.ipynb_checkpoints','*.pyc','*~'))
if verbose:
print("%s copied to %s" % (source, path))
else:
if not os.path.isdir(path): os.mkdir(path)
for subpath, files in example_files.items():
subfolder = os.path.join(path, subpath)
if not os.path.isdir(subfolder): os.mkdir(subfolder)
for gl, extensions in files:
file_glob = os.path.join(__path__[0], gl)
for p in [p for ext in extensions for p in glob.glob(file_glob.format(ext=ext))]:
dest = os.path.join(subfolder, os.path.basename(p))
copyfile(p, dest)
if verbose:
print("%s copied to %s" % (p, path))
filepath = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.join(filepath, './examples')
if not os.path.exists(example_dir):
example_dir = os.path.join(filepath, '../examples')
if os.path.exists(path):
if not force:
print('%s directory already exists, either delete it or set the force flag' % path)
return
shutil.rmtree(path)
ignore = shutil.ignore_patterns('.ipynb_checkpoints','*.pyc','*~')
shutil.copytree(os.path.abspath(example_dir), path, ignore=ignore,
symlinks=True)
33 changes: 24 additions & 9 deletions setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import sys, os, glob
from shutil import copyfile, rmtree
from shutil import rmtree
try:
from setuptools import setup
except ImportError:
Expand Down Expand Up @@ -90,19 +90,34 @@ def check_pseudo_package(path):
raise Exception("Please make sure pseudo-package %s is populated." % path)


excludes = ['DS_Store', '.log', 'ipynb_checkpoints']
packages = []
extensions = []

def walker(arg, top, names):
"""
Walks a directory and records all packages and file extensions.
"""
global packages, extensions
if any(exc in top for exc in excludes):
return
packages.append(top[top.rfind('holoviews'):].replace(os.path.sep, '.'))
for name in names:
ext = '*.%s' % '.'.join(name.split('.')[1:])
if ext and ext not in excludes and ext not in extensions:
extensions.append(ext)


def package_assets(example_path):
"""
Generates pseudo-packages for example files.
Generates pseudo-packages for the examples directory.
"""
import holoviews
holoviews.examples(example_path, force=True)

setup_args['packages'] += ['holoviews.examples', 'holoviews.examples.assets', 'holoviews.examples.notebooks']
setup_args['package_data']['holoviews.examples.notebooks'] = ['*.ipynb', '*.npy']
setup_args['package_data']['holoviews.examples.assets'] = ['*.png', '*.svg', '*.rst']

check_pseudo_package(os.path.join('.', 'holoviews', 'examples', 'assets'))
check_pseudo_package(os.path.join('.', 'holoviews', 'examples', 'notebooks'))
os.path.walk(example_path, walker, None)
setup_args['packages'] += packages
for p in packages:
setup_args['package_data'][p] = extensions


if __name__=="__main__":
Expand Down

0 comments on commit 4f9068b

Please sign in to comment.