How to use the watchgod.Change.added 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 / 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
mktree(tmpdir, tree)

    re_files = r'^.*(\.txt|\.js)$'

    watcher_no_re_dirs = RegExpWatcher(str(tmpdir), re_files)
    changes = watcher_no_re_dirs.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_re_dirs.check() == {
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/recursive_dir/foo.js')))
    }
github gleb-sevruk / pycrunch-engine / pycrunch / watcher / fs_watcher.py View on Github external
from pycrunch.pipeline.file_modification_task import FileModifiedNotificationTask

        logger.debug('thread_proc')
        logger.debug(f'files {self.files}')

        logger.debug(f'files {self.files}')

        path = Path('.').absolute()
        print('watching this:...')
        print(path)
        async for changes in awatch(path, watcher_cls=PythonWatcher):
            for c in changes:
                change_type = c[0]

                force = False
                if change_type == Change.added:
                    force = True

                file = c[1]
                logger.info(f'File watcher alarm: file: `{file}` type `{change_type}` ')

                if force or self.should_watch(file):
                    if change_type == Change.deleted:
                        execution_pipeline.add_task(FileRemovedTask(file=file))
                        logger.info('Added file removal for pipeline ' + file)
                    else:
                        execution_pipeline.add_task(FileModifiedNotificationTask(file=file))
                        logger.info('Added file modification for pipeline ' + file)
                else:
                    logger.debug('non-significant file changed ' + file)

        logger.debug('END thread_proc')
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])
                        self.copy(src)