How to use the ubelt.repr2 function in ubelt

To help you get started, we’ve selected a few ubelt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Erotemic / xdoctest / xdoctest / parser.py View on Github external
print('')
                print('!!! FAILED !!!')
                print('failpoint = {!r}'.format(failpoint))

                import ubelt as ub
                import traceback
                tb_text = traceback.format_exc()
                tb_text = ub.highlight_code(tb_text)
                tb_text = ub.indent(tb_text)
                print(tb_text)

                print('Failed to parse string = <<<<<<<<<<<')
                print(string)
                print('>>>>>>>>>>>  # end string')

                print('info = {}'.format(ub.repr2(info)))
                print('-----')
                print('orig_ex = {}'.format(orig_ex))
                print('labeled_lines = {}'.format(ub.repr2(labeled_lines)))
                print('grouped_lines = {}'.format(ub.repr2(grouped_lines, nl=3)))
                print('all_parts = {}'.format(ub.repr2(all_parts)))
                print('')

                sys.exit(1)
            raise exceptions.DoctestParseError(
                'Failed to parse doctest in {}'.format(failpoint),
                string=string, info=info, orig_ex=orig_ex)
        if DEBUG > 1:
            print('\n===== FINISHED PARSE ====')
        return all_parts
github Erotemic / xdoctest / xdoctest / parser.py View on Github external
import ubelt as ub
                import traceback
                tb_text = traceback.format_exc()
                tb_text = ub.highlight_code(tb_text)
                tb_text = ub.indent(tb_text)
                print(tb_text)

                print('Failed to parse string = <{[<{[<{[')
                print(string)
                print(']}>a]}>]}>  # end string')

                print('info = {a}'.format(a=ub.repr2(info)))
                print('-----')
                print('orig_ex = {a}'.format(a=orig_ex))
                print('labeled_lines = {a}'.format(a=ub.repr2(labeled_lines)))
                print('grouped_lines = {a}'.format(a=ub.repr2(grouped_lines, nl=3)))
                print('all_parts = {a}'.format(a=ub.repr2(all_parts)))
                print('')
                # sys.exit(1)
            raise exceptions.DoctestParseError(
                'Failed to parse doctest in {a}'.format(a=failpoint),
                string=string, info=info, orig_ex=orig_ex)
        if DEBUG > 1:
            print('\n===== FINISHED PARSE ====')
        return all_parts
github Erotemic / ubelt / tests / test_cmd.py View on Github external
def test_cwd():
    """
    CommandLine:
        python ~/code/ubelt/ubelt/tests/test_cmd.py test_cwd
    """
    import sys
    import os
    import ubelt as ub
    if not sys.platform.startswith('win32'):
        dpath = ub.ensure_app_resource_dir('ubelt')
        dpath = os.path.realpath(dpath)
        info = ub.cmd('pwd', cwd=dpath, shell=True)
        print('info = {}'.format(ub.repr2(info, nl=1)))
        print('dpath = {!r}'.format(dpath))
        assert info['out'].strip() == dpath
github Erotemic / ubelt / tests / test_format.py View on Github external
def test_empty():
    import ubelt as ub
    assert ub.repr2(list()) == '[]'
    assert ub.repr2(dict()) == '{}'
    assert ub.repr2(set()) == '{}'
    assert ub.repr2(tuple()) == '()'
    assert ub.repr2(dict(), explicit=1) == 'dict()'
    # Even when no braces are no, still include them when input is empty
    assert ub.repr2(list(), nobr=1) == '[]'
    assert ub.repr2(dict(), nobr=1) == '{}'
    assert ub.repr2(set(), nobr=1) == '{}'
    assert ub.repr2(tuple(), nobr=1) == '()'
    assert ub.repr2(dict(), nobr=1, explicit=1) == 'dict()'
github Erotemic / ubelt / tests / test_format.py View on Github external
def test_empty():
    import ubelt as ub
    assert ub.repr2(list()) == '[]'
    assert ub.repr2(dict()) == '{}'
    assert ub.repr2(set()) == '{}'
    assert ub.repr2(tuple()) == '()'
    assert ub.repr2(dict(), explicit=1) == 'dict()'
    # Even when no braces are no, still include them when input is empty
    assert ub.repr2(list(), nobr=1) == '[]'
    assert ub.repr2(dict(), nobr=1) == '{}'
    assert ub.repr2(set(), nobr=1) == '{}'
    assert ub.repr2(tuple(), nobr=1) == '()'
    assert ub.repr2(dict(), nobr=1, explicit=1) == 'dict()'
github Erotemic / xdoctest / xdoctest / parser.py View on Github external
print('Labeled lines so far: <<<<<<<<<<<')
                        for line in labeled_lines:
                            print(line)
                        print('>>>>>>>>>>>')
                        print('')
                    raise
            elif curr_state == WANT:
                labeled_lines.append((WANT, line))
            elif curr_state == TEXT:
                labeled_lines.append((TEXT, line))
            prev_state = curr_state

        if DEBUG > 1:
            import ubelt as ub
            print('')

        return labeled_lines
github Erotemic / ubelt / dev / count_usage_freq.py View on Github external
hist_iter = iter(pkg_to_hist.values())
    usage = next(hist_iter).copy()
    for other in hist_iter:
        for k, v in other.items():
            usage[k] += v
    for attr in ub.__all__:
        usage[attr] += 0

    for name in pkg_to_hist.keys():
        pkg_to_hist[name] = ub.odict(sorted(pkg_to_hist[name].items(), key=lambda t: t[1])[::-1])

    usage = ub.odict(sorted(usage.items(), key=lambda t: t[1])[::-1])

    if config['print_packages']:
        print(ub.repr2(pkg_to_hist, nl=2))

    if config['remove_zeros']:
        for k, v in list(usage.items()):
            if v == 0:
                usage.pop(k)

    if config['hardcoded_ubelt_hack']:
        for k in list(usage):
            if k.startswith('util_'):
                usage.pop(k)
            if k.startswith('_util_'):
                usage.pop(k)
            # ub._util_deprecated
            from ubelt import _util_deprecated
            if k in dir(_util_deprecated):
                usage.pop(k)
github Erotemic / ubelt / dev / count_usage_freq.py View on Github external
for k, v in list(usage.items()):
            if v == 0:
                usage.pop(k)

    if config['hardcoded_ubelt_hack']:
        for k in list(usage):
            if k.startswith('util_'):
                usage.pop(k)
            if k.startswith('_util_'):
                usage.pop(k)
            # ub._util_deprecated
            from ubelt import _util_deprecated
            if k in dir(_util_deprecated):
                usage.pop(k)

    print(ub.repr2(usage, nl=1))
    return usage