import os, sys, inspect, shutil

from collections import defaultdict
from inspect import Parameter, Signature
from types import FunctionType
from pathlib import Path

import param

from pyviz_comms import extension as _pyviz_extension

from ..core import (
    Dataset, DynamicMap, HoloMap, Dimensioned, ViewableElement,
    StoreOptions, Store
)
from ..core.options import Keywords, Options, options_policy
from ..core.operation import Operation
from ..core.overlay import Overlay
from ..core.util import merge_options_to_dict, OrderedDict
from ..core.operation import OperationCallable
from ..core import util
from ..operation.element import function
from ..streams import Stream, Params, streams_list_from_dict
from .settings import OutputSettings, list_formats, list_backends

Store.output_settings = OutputSettings



def examples(path='holoviews-examples', verbose=False, force=False, root=__file__):
    """
    Copies the notebooks to the supplied path.
    """
    filepath = os.path.abspath(os.path.dirname(root))
    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','*~')
    tree_root = os.path.abspath(example_dir)
    if os.path.isdir(tree_root):
        shutil.copytree(tree_root, path, ignore=ignore, symlinks=True)
    else:
        print('Cannot find %s' % tree_root)