How to use the ubelt.writeto 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 / mkinit / tests / test_with_dummy.py View on Github external
ub.writeto(paths['subdir1_init'], ub.codeblock(
        '''
        simple_subattr1 = "hello world"
        simple_subattr2 = "hello world"
        _private_attr = "hello world"
        '''))

    ub.writeto(paths['subdir2_init'], ub.codeblock(
        '''
        __all__ = ['public_attr']

        public_attr = "hello world"
        private_attr = "hello world"
        '''))

    ub.writeto(paths['submod1'], ub.codeblock(
        '''
        import six

        attr1 = True
        attr2 = six.moves.zip

        # ------------------------

        if True:
            good_attr_01 = None

        if False:
            bad_attr_false1 = None

        if None:
            bad_attr_none1 = None
github Erotemic / mkinit / tests / test_with_dummy.py View on Github external
'submod2': ub.touch(join(root, 'submod2.py')),
        'subdir1': ub.ensuredir(join(root, 'subdir1')),
        'subdir2': ub.ensuredir(join(root, 'subdir2')),
    }
    paths['subdir1_init'] = ub.touch(join(paths['subdir1'], '__init__.py'))
    paths['subdir2_init'] = ub.touch(join(paths['subdir2'], '__init__.py'))
    paths['root_init'] = ub.touch(join(paths['root'], '__init__.py'))

    ub.writeto(paths['subdir1_init'], ub.codeblock(
        '''
        simple_subattr1 = "hello world"
        simple_subattr2 = "hello world"
        _private_attr = "hello world"
        '''))

    ub.writeto(paths['subdir2_init'], ub.codeblock(
        '''
        __all__ = ['public_attr']

        public_attr = "hello world"
        private_attr = "hello world"
        '''))

    ub.writeto(paths['submod1'], ub.codeblock(
        '''
        import six

        attr1 = True
        attr2 = six.moves.zip

        # ------------------------
github Erotemic / mkinit / tests / test_with_dummy.py View on Github external
"""
    root = ub.ensuredir(join(dpath, pkgname))
    ub.delete(root)
    ub.ensuredir(root)
    paths = {
        'root': root,
        'submod1': ub.touch(join(root, 'submod1.py')),
        'submod2': ub.touch(join(root, 'submod2.py')),
        'subdir1': ub.ensuredir(join(root, 'subdir1')),
        'subdir2': ub.ensuredir(join(root, 'subdir2')),
    }
    paths['subdir1_init'] = ub.touch(join(paths['subdir1'], '__init__.py'))
    paths['subdir2_init'] = ub.touch(join(paths['subdir2'], '__init__.py'))
    paths['root_init'] = ub.touch(join(paths['root'], '__init__.py'))

    ub.writeto(paths['subdir1_init'], ub.codeblock(
        '''
        simple_subattr1 = "hello world"
        simple_subattr2 = "hello world"
        _private_attr = "hello world"
        '''))

    ub.writeto(paths['subdir2_init'], ub.codeblock(
        '''
        __all__ = ['public_attr']

        public_attr = "hello world"
        private_attr = "hello world"
        '''))

    ub.writeto(paths['submod1'], ub.codeblock(
        '''
github Erotemic / ubelt / tests / test_hash.py View on Github external
def test_hash_file():
    fpath = join(ub.ensure_app_cache_dir('ubelt'), 'tmp.txt')
    ub.writeto(fpath, 'foobar')
    hashid1_a = ub.hash_file(fpath, hasher='sha512', hashlen=8, stride=1, blocksize=1)
    hashid2_a = ub.hash_file(fpath, hasher='sha512', hashlen=8, stride=2, blocksize=1)

    hashid1_b = ub.hash_file(fpath, hasher='sha512', hashlen=8, stride=1, blocksize=10)
    hashid2_b = ub.hash_file(fpath, hasher='sha512', hashlen=8, stride=2, blocksize=10)

    assert hashid1_a == hashid1_b
    assert hashid2_a != hashid2_b, 'blocksize matters when stride is > 1'
    assert hashid1_a != hashid2_a
github Erotemic / xdoctest / dev / _compare / compare.py View on Github external
content = ub.readfrom('base_diff.py') + '\n\n'
    xdoc_version = content + ub.codeblock(
        '''
        if __name__ == '__main__':
            import xdoctest
            xdoctest.doctest_module(__file__)
        ''') + '\n'

    doc_version = content + ub.codeblock(
        '''
        if __name__ == '__main__':
            import doctest
            doctest.testmod()
        ''') + '\n'

    ub.writeto('_doc_version.py', doc_version)
    ub.writeto('_xdoc_version.py', xdoc_version)
github Erotemic / xdoctest / dev / make_rtd.py View on Github external
source = ub.readfrom(conf_path)
    red = redbaron.RedBaron(source)

    # Insert custom extensions
    extra_extensions = [
        '"sphinxcontrib.napoleon"'
    ]

    ext_node = red.find('name', value='extensions').parent
    ext_node.value.value.extend(extra_extensions)

    # Overwrite theme to read-the-docs
    theme_node = red.find('name', value='html_theme').parent
    theme_node.value.value = '"sphinx_rtd_theme"'

    ub.writeto(conf_path, red.dumps())
github Erotemic / ubelt / tests / test_import.py View on Github external
def test_import_modpath_basic():
    assert 'testmod' not in sys.modules

    with ub.TempDir() as temp:
        modpath = join(temp.dpath, 'testmod.py')
        text = ub.codeblock(
            '''
            a = 'value'
            ''')
        ub.writeto(modpath, text)
        assert temp.dpath not in sys.path
        module = ub.import_module_from_path(modpath)
        assert temp.dpath not in sys.path, 'pythonpath should remain clean'
        assert module.a == 'value'
        assert module.__file__ == modpath
        assert module.__name__ == 'testmod'
        assert 'testmod' in sys.modules
github Erotemic / xdoctest / dev / _compare / compare.py View on Github external
xdoc_version = content + ub.codeblock(
        '''
        if __name__ == '__main__':
            import xdoctest
            xdoctest.doctest_module(__file__)
        ''') + '\n'

    doc_version = content + ub.codeblock(
        '''
        if __name__ == '__main__':
            import doctest
            doctest.testmod()
        ''') + '\n'

    ub.writeto('_doc_version.py', doc_version)
    ub.writeto('_xdoc_version.py', xdoc_version)