How to use the watchgod.Change.modified 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
re_files = r'^.*(\.txt|\.js)$'
    re_dirs = r'^(?:(?!recursive_dir).)*$'

    watcher = RegExpWatcher(str(tmpdir), re_files, re_dirs)
    changes = watcher.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/borec.txt').write('ahoy')
    tmpdir.join('foo/borec-js.js').write('peace')
    tmpdir.join('foo/recursive_dir/b.js').write('borec')

    assert watcher.check() == {
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/borec.txt'))),
        (Change.added, str(tmpdir.join('foo/borec-js.js')))
    }
github samuelcolvin / harrier / tests / test_dev.py View on Github external
async def awatch_alt(*args, **kwargs):
        yield {(Change.modified, str(tmpdir.join('harrier.yml')))}
        yield {(Change.modified, foobar_path)}
        yield {(Change.modified, str(tmpdir.join('theme/assets/main.png')))}
        yield {(Change.modified, str(tmpdir.join('theme/sass/main.scss')))}
        yield {(Change.modified, str(tmpdir.join('theme/templates/main.jinja')))}
        yield {(Change.modified, str(tmpdir.join('extensions.py')))}
        yield {(Change.modified, str(tmpdir.join('data/foobar.yml')))}
github nitipit / shelfdb / docs.py View on Github external
for src in asset_files:
            dest = src.relative_to(template_dir)
            dest = docs_dest_dir.joinpath(dest)
            shutil.copyfile(src, dest)

        # Copy static files
        shutil.copytree(
            docs_src_dir.joinpath('asset'),
            docs_dest_dir.joinpath('static/asset'),
            dirs_exist_ok=True)

        async for changes in awatch(str(template_dir)):
            for change in changes:
                print(change)
                if (change[0] == Change.modified)\
                        or (change[0] == Change.added):
                    if re.match(r'.*\.html$', change[1]):
                        src = Path(change[1])
                        self.template_html(src)
                    elif re.match(r'.*\.md$', change[1]):
                        src = Path(change[1])
                        src = src.parent.joinpath(src.stem + '.html')
                        self.template_html(src)
                    elif re.match(r'.*\.styl$', change[1]):
                        src = Path(change[1])
                        await self.stylus(src)
                    elif re.match(r'.*\.js$', change[1]):
                        src = Path(change[1])
                        await self.parcel(src)
                    elif re.match(r'.*\.(png|jpg)', change[1]):
                        src = Path(change[1])