How to use the ubelt.cmd 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 / ubelt / tests / test_cmd.py View on Github external
"""
    CommandLine:
        pytest ubelt/tests/test_cmd.py::test_cmd_tee_thread -s
        python ubelt/tests/test_cmd.py test_cmd_tee_thread
    """
    if 'tqdm' in sys.modules:
        if tuple(map(int, sys.modules['tqdm'].__version__.split('.'))) < (4, 19):
            pytest.skip(reason='threads cause issues with early tqdms')

    import threading
    # check which threads currently exist (ideally 1)
    existing_threads = list(threading.enumerate())
    print('existing_threads = {!r}'.format(existing_threads))

    command = 'python -c "for i in range(10): print(str(i))"'
    result = ub.cmd(command, verbose=0, tee_backend='thread')
    assert result['out'] == '\n'.join(list(map(str, range(10)))) + '\n'

    after_threads = list(threading.enumerate())
    print('after_threads = {!r}'.format(after_threads))
    assert len(existing_threads) <= len(after_threads), (
        'we should be cleaning up our threads')
github Erotemic / xdoctest / dev / _compare / compare.py View on Github external
def main():
    generate()
    # Run the files

    print('\n\n' + ub.codeblock(
        '''
        ___  ____ ____ ___ ____ ____ ___
        |  \ |  | |     |  |___ [__   |
        |__/ |__| |___  |  |___ ___]  |

        Cant do most of this in doctest, although apparently you can
        use asserts, whereas I previously thought they didnt work
        ''') + '\n\n')

    ub.cmd('python _doc_version.py', verbose=2)

    print('\n\n' + ub.codeblock(
        '''
        _  _ ___  ____ ____ ___ ____ ____ ___
         \/  |  \ |  | |     |  |___ [__   |
        _/\_ |__/ |__| |___  |  |___ ___]  |

        Just run the assert failure to illustrate how failures look
        ''') + '\n\n')
    ub.cmd('python _xdoc_version.py do_asserts_work --demo-failure', verbose=2)

    print('\n\n' + ub.codeblock(
        '''
        _  _ ___  ____ ____ ___ ____ ____ ___
         \/  |  \ |  | |     |  |___ [__   |
        _/\_ |__/ |__| |___  |  |___ ___]  |
github Erotemic / ubelt / tests / test_cmd.py View on Github external
def test_env():
    import sys
    import ubelt as ub
    import os
    if not sys.platform.startswith('win32'):
        env = os.environ.copy()
        env.update({'UBELT_TEST_ENV': '42'})
        info = ub.cmd('echo $UBELT_TEST_ENV', env=env, shell=True)
        print(info['out'])
        assert info['out'].strip() == env['UBELT_TEST_ENV']
github Erotemic / ubelt / tests / test_cmd.py View on Github external
def test_cmd_stdout_quiet():
    with ub.CaptureStdout() as cap:
        result = ub.cmd('echo hello stdout', verbose=False)
    assert result['out'].strip() == 'hello stdout', 'should still capture internally'
    assert cap.text.strip() == '', 'nothing should print to stdout'
github Erotemic / ubelt / tests / test_cmd.py View on Github external
def test_cmd_stderr():
    result = ub.cmd('echo hello stderr 1>&2', shell=True, verbose=True)
    assert result['err'].strip() == 'hello stderr'
github Erotemic / xdoctest / dev / make_rtd.py View on Github external
'--full',
        '--output-dir="{}"'.format(doc_dpath),
        '--doc-author="{}"'.format(setupkw['author']),
        '--doc-version="{}"'.format(short_version),
        '--doc-release="{}"'.format(full_version),
        '--maxdepth="8"',
        # '--ext-autodoc',
        # '--ext-ifconfig',
        # '--ext-githubpages',
        # '--ext-mathjax',
        setupkw['name'],
    ]
    cmdstr = ' '.join(args)

    import ubelt as ub
    result = ub.cmd(cmdstr, verbose=2)
    assert result['ret'] == 0
github Erotemic / ubelt / ubelt / _util_deprecated.py View on Github external
editor = os.environ.get('VISUAL', 'gvim')
    if not ub.find_exe(editor):
        warnings.warn('Cannot find visual editor={}'.format(editor), UserWarning)
        # Try and fallback on commonly installed editor
        alt_candidates = [
            'gedit',
            'TextEdit'
            'Notepad',
        ]
        for cand in alt_candidates:
            if ub.find_exe(cand):
                editor = cand

    if not exists(fpath):
        raise IOError('Cannot start nonexistant file: %r' % fpath)
    ub.cmd([editor, fpath], fpath, detach=True)