Ejemplo n.º 1
0
def setuptools_setup(setup_fpath=None, module=None, **kwargs):
    # TODO: Learn this better
    # https://docs.python.org/3.1/distutils/apiref.html
    # https://pythonhosted.org/an_example_pypi_project/setuptools.html
    # https://docs.python.org/2/distutils/setupscript.html https://docs.python.org/2/distutils/setupscript.html
    # Useful documentation: http://bashelton.com/2009/04/setuptools-tutorial/#setup.py-package_dir
    """
    Arguments which can be passed to setuptools::

        ============       =====            ===========
        Install-Data       Value            Description
        ------------       -----            -----------
        *packages          strlist          a list of packages modules to be distributed
        py_modules         strlist          a list of singlefile modules to be distributed
        scripts            strlist          a list of standalone scripts to build and install
        *install_requires  list             e.g: ['distribute == 0.7.3', 'numpy', 'matplotlib']
        data_files         strlist          a list of data files to install
        zip_safe           bool             install efficiently installed as a zipped module?
        namespace_packages list             packages without meaningful __init__.py's
        package_dir        dict             keys are packagenames ('' is the root)
        package_data       dict             keys are foldernames, values are a list of globstrs
        *entry_pionts      dict             installs a script {'console_scripts': ['script_name_to_install = entry_module:entry_function']}

        ============       =====            ===========
        Meta-Data          Value            Description
        ------------       -----            -----------
        name               short string     ('name of the package')
        version            short string     ('version of this release')
        author             short string     ('package authors name')
        author_email       email address    ('email address of the package author')
        maintainer         short string     ('package maintainers name')
        maintainer_email   email address    ('email address of the package maintainer')
        url                URL              ('home page for the package')
        description        short string     ('short, summary description of the package')
        long_description   long string      ('longer description of the package')
        download_url       URL              ('location where the package may be downloaded')
        classifiers        list of strings  ('a list of classifiers')
        platforms          list of strings  ('a list of platforms')
        license            short string     ('license for the package')
    """
    from utool.util_inject import inject_colored_exceptions
    inject_colored_exceptions()  # Fluffly, but nice
    if VERBOSE:
        print(util_str.dict_str(kwargs))
    __infer_setup_kwargs(module, kwargs)
    presetup_commands(setup_fpath, kwargs)
    if VERBOSE:
        print(util_str.dict_str(kwargs))
    return kwargs
Ejemplo n.º 2
0
def setuptools_setup(setup_fpath=None, module=None, **kwargs):
    # TODO: Learn this better
    # https://docs.python.org/3.1/distutils/apiref.html
    # https://pythonhosted.org/an_example_pypi_project/setuptools.html
    # https://docs.python.org/2/distutils/setupscript.html https://docs.python.org/2/distutils/setupscript.html
    # Useful documentation: http://bashelton.com/2009/04/setuptools-tutorial/#setup.py-package_dir
    """
    Arguments which can be passed to setuptools::

        ============       =====            ===========
        Install-Data       Value            Description
        ------------       -----            -----------
        *packages          strlist          a list of packages modules to be distributed
        py_modules         strlist          a list of singlefile modules to be distributed
        scripts            strlist          a list of standalone scripts to build and install
        *install_requires  list             e.g: ['distribute == 0.7.3', 'numpy', 'matplotlib']
        data_files         strlist          a list of data files to install
        zip_safe           bool             install efficiently installed as a zipped module?
        namespace_packages list             packages without meaningful __init__.py's
        package_dir        dict             keys are packagenames ('' is the root)
        package_data       dict             keys are foldernames, values are a list of globstrs
        *entry_pionts      dict             installs a script {'console_scripts': ['script_name_to_install = entry_module:entry_function']}

        ============       =====            ===========
        Meta-Data          Value            Description
        ------------       -----            -----------
        name               short string     ('name of the package')
        version            short string     ('version of this release')
        author             short string     ('package authors name')
        author_email       email address    ('email address of the package author')
        maintainer         short string     ('package maintainers name')
        maintainer_email   email address    ('email address of the package maintainer')
        url                URL              ('home page for the package')
        description        short string     ('short, summary description of the package')
        long_description   long string      ('longer description of the package')
        download_url       URL              ('location where the package may be downloaded')
        classifiers        list of strings  ('a list of classifiers')
        platforms          list of strings  ('a list of platforms')
        license            short string     ('license for the package')
    """
    from utool.util_inject import inject_colored_exceptions
    inject_colored_exceptions()  # Fluffly, but nice
    if VERBOSE:
        print(util_str.dict_str(kwargs))
    __infer_setup_kwargs(module, kwargs)
    presetup_commands(setup_fpath, kwargs)
    if VERBOSE:
        print(util_str.dict_str(kwargs))
    return kwargs
Ejemplo n.º 3
0
def print_locals(*args, **kwargs):
    """
    Prints local variables in function.

    If no arguments all locals are printed.

    Variables can be specified directly (variable values passed in) as varargs
    or indirectly (variable names passed in) in kwargs by using keys and a list
    of strings.
    """
    from utool import util_str
    from utool import util_dbg
    from utool import util_dict
    locals_ = util_dbg.get_caller_locals()
    keys = kwargs.get('keys', None if len(args) == 0 else [])
    to_print = {}
    for arg in args:
        varname = util_dbg.get_varname_from_locals(arg, locals_)
        to_print[varname] = arg
    if keys is not None:
        to_print.update(util_dict.dict_take(locals_, keys))
    if not to_print:
        to_print = locals_
    locals_str = util_str.dict_str(to_print)
    print(locals_str)
Ejemplo n.º 4
0
def print_locals(*args, **kwargs):
    """
    Prints local variables in function.

    If no arguments all locals are printed.

    Variables can be specified directly (variable values passed in) as varargs
    or indirectly (variable names passed in) in kwargs by using keys and a list
    of strings.
    """
    from utool import util_str
    from utool import util_dbg
    from utool import util_dict
    locals_ = util_dbg.get_caller_locals()
    keys = kwargs.get('keys', None if len(args) == 0 else [])
    to_print = {}
    for arg in args:
        varname = util_dbg.get_varname_from_locals(arg, locals_)
        to_print[varname] = arg
    if keys is not None:
        to_print.update(util_dict.dict_take(locals_, keys))
    if not to_print:
        to_print = locals_
    locals_str = util_str.dict_str(to_print)
    print(locals_str)
Ejemplo n.º 5
0
def text_dict_write(fpath, dict_):
    """
    Very naive, but readable way of storing a dictionary on disk
    FIXME: This broke on RoseMary's big dataset. Not sure why. It gave bad
    syntax. And the SyntaxError did not seem to be excepted.
    """
    #dict_ = text_dict_read(fpath)
    #dict_[key] = val
    dict_text2 = util_str.dict_str(dict_, strvals=False)
    if VERBOSE:
        print('[cache] ' + str(dict_text2))
    util_io.write_to(fpath, dict_text2)
Ejemplo n.º 6
0
 def wrp_onexceptreport(*args, **kwargs):
     try:
         #import utool
         #if utool.DEBUG:
         #    print('[IN EXCPRPT] args=%r' % (args,))
         #    print('[IN EXCPRPT] kwargs=%r' % (kwargs,))
         return func(*args, **kwargs)
     except Exception as ex:
         from utool import util_str
         print('ERROR occured! Reporting input to function')
         if keys is not None:
             from utool import util_inspect
             from utool import util_list
             from utool import util_dict
             argspec = util_inspect.get_func_argspec(func)
             in_kwargs_flags = [key in kwargs for key in keys]
             kwarg_keys = util_list.compress(keys, in_kwargs_flags)
             kwarg_vals = [kwargs.get(key) for key in kwarg_keys]
             flags = util_list.not_list(in_kwargs_flags)
             arg_keys = util_list.compress(keys, flags)
             arg_idxs = [argspec.args.index(key) for key in arg_keys]
             num_nodefault = len(argspec.args) - len(argspec.defaults)
             default_vals = (([None] * (num_nodefault)) +
                             list(argspec.defaults))
             args_ = list(args) + default_vals[len(args) + 1:]
             arg_vals = util_list.take(args_, arg_idxs)
             requested_dict = dict(util_list.flatten(
                 [zip(kwarg_keys, kwarg_vals), zip(arg_keys, arg_vals)]))
             print('input dict = ' + util_str.dict_str(
                 util_dict.dict_subset(requested_dict, keys)))
             # (print out specific keys only)
             pass
         arg_strs = ', '.join([repr(util_str.truncate_str(str(arg)))
                               for arg in args])
         kwarg_strs = ', '.join([
             util_str.truncate_str('%s=%r' % (key, val))
             for key, val in six.iteritems(kwargs)])
         msg = ('\nERROR: funcname=%r,\n * args=%s,\n * kwargs=%r\n' % (
             meta_util_six.get_funcname(func), arg_strs, kwarg_strs))
         msg += ' * len(args) = %r\n' % len(args)
         msg += ' * len(kwargs) = %r\n' % len(kwargs)
         util_dbg.printex(ex, msg, pad_stdout=True)
         raise
Ejemplo n.º 7
0
def print_dict(dict_, dict_name=None, **kwargs):
    import utool as ut
    if dict_name is None:
        dict_name = ut.get_varname_from_stack(dict_, N=1)
    dict_repr = util_str.dict_str(dict_, **kwargs)
    print(dict_name + ' = ' + dict_repr)
Ejemplo n.º 8
0
def global_cache_dump(appname='default'):
    shelf_fpath = get_global_shelf_fpath(appname)
    print('shelf_fpath = %r' % shelf_fpath)
    with GlobalShelfContext(appname) as shelf:
        print(util_str.dict_str(shelf))
Ejemplo n.º 9
0
def print_locals():
    from utool import util_str
    from utool import util_dbg
    locals_ = util_dbg.get_caller_locals()
    print(util_str.dict_str(locals_))
Ejemplo n.º 10
0
def print_dict(dict_, dict_name=None, **kwargs):
    import utool as ut
    if dict_name is None:
        dict_name = ut.get_varname_from_stack(dict_, N=1)
    dict_repr = util_str.dict_str(dict_, **kwargs)
    print(dict_name + ' = ' + dict_repr)