How to use the watchgod.Change function in watchgod

To help you get started, we’ve selected a few watchgod 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 samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_regexp_no_args(tmpdir):
    mktree(tmpdir, tree)

    watcher_no_args = RegExpWatcher(str(tmpdir))
    changes = watcher_no_args.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/recursive_dir/foo.js').write('change')

    assert watcher_no_args.check() == {
        (Change.modified, str(tmpdir.join('foo/spam.py'))),
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/recursive_dir/foo.js')))
    }
github samuelcolvin / harrier / tests / test_dev.py View on Github external
async def awatch_alt(*args, **kwargs):
        yield {(Change.modified, str(tmpdir.join('pages/foobar.md')))}
        yield {(Change.modified, str(tmpdir.join('pages/features/whatever.md')))}
        yield {(Change.modified, str(tmpdir.join('harrier.yml')))}
        yield {(Change.added, str(tmpdir.join('theme/sass/main.scss')))}
        tmpdir.join('harrier.yml').write('foo: 2')
        yield {(Change.modified, str(tmpdir.join('harrier.yml')))}
github samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_add(tmpdir):
    watcher = AllWatcher(str(tmpdir))
    changes = watcher.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo.txt').write('foobar')

    changes = watcher.check()
    assert changes == {(Change.added, str(tmpdir.join('foo.txt')))}
github samuelcolvin / harrier / harrier / dev.py View on Github external
rel_path = '/' + str(path.relative_to(config.pages_dir))
                    if change == Change.deleted:
                        page = SOM['pages'][rel_path]
                        outfile = get_outfile(page, config)
                        outfile.unlink()
                        if 'content_template' in page:
                            (tmp_dir / page['content_template']).unlink()
                        SOM['pages'].pop(rel_path)
                    else:
                        v = get_page_data(path, config=config)
                        if v:
                            v.pop('path_ref')
                            SOM['pages'][rel_path] = v
                            to_update.add(rel_path)
                log_complete(start, 'pages built', len(args.pages))
                args.templates = args.templates or any(change != Change.deleted for change, _ in args.pages)

            extra_pages = apply_page_generator(SOM, config)
            to_update = to_update | extra_pages
            SOM = apply_modifiers(SOM, config.extensions.som_modifiers)
            content_templates([SOM['pages'][k] for k in SOM['pages'] if k in to_update], config)

        SOM['path_lookup'] = get_path_lookup(config, SOM['pages'])
        if args.templates:
            global BUILD_CACHE
            BUILD_CACHE = render_pages(config, SOM, build_cache=BUILD_CACHE)
    except HarrierProblem as e:
        logger.debug('error during build %s %s %s', traceback.format_exc(), e.__class__.__name__, e)
        logger.warning('%sbuild failed in %0.3fs', log_prefix, time() - start_time)
        return 1
    else:
        logger.info('%sbuild completed in %0.3fs', log_prefix, time() - start_time)