# Path: anypytools/tools.py
# def define2str(key, value=None):
#     if isinstance(value, str):
#         if value.startswith('"') and value.endswith('"'):
#             defstr = '-def %s=---"\\"%s\\""' % (key, value[1:-1].replace("\\", "\\\\"))
#         else:
#             defstr = '-def %s="%s"' % (key, value)
#     elif value is None:
#         defstr = '-def %s=""' % (key)
#     elif isinstance(value, float):
#         defstr = '-def %s="%g"' % (key, value)
#     else:
#         defstr = '-def %s="%d"' % (key, value)
#     return defstr
# 
# def path2str(key, path="."):
#     return '-p %s=---"%s"' % (key, path.replace("\\", "\\\\"))
# 
# def array2anyscript(arr):
#     """Format a numpy array as an anyscript variable."""
# 
#     def tostr(v):
#         # pylint: disable=no-member
#         if np.isreal(v):
#             return "{:.12g}".format(v)
#         elif isinstance(v, (str, np.str_)):
#             return '"{}"'.format(v)
# 
#     def createsubarr(arr):
#         outstr = ""
#         if isinstance(arr, np.ndarray):
#             if len(arr) == 1 and not isinstance(arr[0], np.ndarray):
#                 return "{" + tostr(arr[0]) + "},"
#             outstr += "{"
#             for row in arr:
#                 outstr += createsubarr(row)
#             outstr = outstr.strip(",") + "},"
#             return outstr
#         else:
#             return outstr + tostr(arr) + ","
# 
#     if isinstance(arr, np.ndarray) and not arr.shape:
#         return tostr(arr.tolist())
#     elif isinstance(arr, np.ndarray):
#         return createsubarr(arr).strip(",")
#     elif isinstance(arr, float):
#         return tostr(arr)
#     else:
#         return str(arr)


import types
import logging
import numpy as np
            import pyDOE
    import pytest
from pprint import pprint, pformat  # noqa
from copy import deepcopy
from collections.abc import MutableSequence
from scipy.stats import distributions
from anypytools.tools import define2str, path2str, array2anyscript
    --------
    >>> Load('model.main.any')
    load "model.main.any"

    >>> paths = {'DATA':'c:/MyModel/Data'}
    >>> defines = {'EXCLUDE_ARMS':None, 'N_STEP':20}
    >>> Load('c:/MyModel/model.main.any', defines, paths)
    load "c:/MyModel/model.main.any" -def EXCLUDE_ARMS="" -def N_STEP="20" -p DATA=---"c:/MyModel/Data"

    >>> mcr = AnyMacro( Load('model_{id}.main.any'), counter_token = '{id}')
    >>> mcr.create_macros(3)
    [[u'load "model_0.main.any"'],
     [u'load "model_1.main.any"'],
     [u'load "model_2.main.any"']]

    """

    def __init__(self, filename, defs={}, paths={}):
        self.filename = filename
        self.defs = defs.copy()
        self.paths = paths.copy()

    def get_macro(self, index, **kwarg):
        cmd = ['load "{}"'.format(self.filename)]

        for key in sorted(self.defs):
            value = self.defs[key]
            cmd.append(define2str(key, value))
        for key in sorted(self.paths):
            value = self.paths[key]

# Path: anypytools/tools.py
# def define2str(key, value=None):
#     if isinstance(value, str):
#         if value.startswith('"') and value.endswith('"'):
#             defstr = '-def %s=---"\\"%s\\""' % (key, value[1:-1].replace("\\", "\\\\"))
#         else:
#             defstr = '-def %s="%s"' % (key, value)
#     elif value is None:
#         defstr = '-def %s=""' % (key)
#     elif isinstance(value, float):
#         defstr = '-def %s="%g"' % (key, value)
#     else:
#         defstr = '-def %s="%d"' % (key, value)
#     return defstr
# 
# def path2str(key, path="."):
#     return '-p %s=---"%s"' % (key, path.replace("\\", "\\\\"))
# 
# def array2anyscript(arr):
#     """Format a numpy array as an anyscript variable."""
# 
#     def tostr(v):
#         # pylint: disable=no-member
#         if np.isreal(v):
#             return "{:.12g}".format(v)
#         elif isinstance(v, (str, np.str_)):
#             return '"{}"'.format(v)
# 
#     def createsubarr(arr):
#         outstr = ""
#         if isinstance(arr, np.ndarray):
#             if len(arr) == 1 and not isinstance(arr[0], np.ndarray):
#                 return "{" + tostr(arr[0]) + "},"
#             outstr += "{"
#             for row in arr:
#                 outstr += createsubarr(row)
#             outstr = outstr.strip(",") + "},"
#             return outstr
#         else:
#             return outstr + tostr(arr) + ","
# 
#     if isinstance(arr, np.ndarray) and not arr.shape:
#         return tostr(arr.tolist())
#     elif isinstance(arr, np.ndarray):
#         return createsubarr(arr).strip(",")
#     elif isinstance(arr, float):
#         return tostr(arr)
#     else:
#         return str(arr)


# Path: anypytools/macroutils.py
import types
import logging
import numpy as np
            import pyDOE
    import pytest
from pprint import pprint, pformat  # noqa
from copy import deepcopy
from collections.abc import MutableSequence
from scipy.stats import distributions
from anypytools.tools import define2str, path2str, array2anyscript

    --------
    >>> Load('model.main.any')
    load "model.main.any"

    >>> paths = {'DATA':'c:/MyModel/Data'}
    >>> defines = {'EXCLUDE_ARMS':None, 'N_STEP':20}
    >>> Load('c:/MyModel/model.main.any', defines, paths)
    load "c:/MyModel/model.main.any" -def EXCLUDE_ARMS="" -def N_STEP="20" -p DATA=---"c:/MyModel/Data"

    >>> mcr = AnyMacro( Load('model_{id}.main.any'), counter_token = '{id}')
    >>> mcr.create_macros(3)
    [[u'load "model_0.main.any"'],
     [u'load "model_1.main.any"'],
     [u'load "model_2.main.any"']]

    """

    def __init__(self, filename, defs={}, paths={}):
        self.filename = filename
        self.defs = defs.copy()
        self.paths = paths.copy()

    def get_macro(self, index, **kwarg):
        cmd = ['load "{}"'.format(self.filename)]

        for key in sorted(self.defs):
            value = self.defs[key]
            cmd.append(define2str(key, value))
        for key in sorted(self.paths):
            value = self.paths[key]

            cmd.append(path2str(key, value))