code: def watch(self, source, write=True, package=None, run=False, force=False):
          
          from coconut.command.watch import Observer, RecompilationWatcher
  
          source = fixpath(source)
  
          logger.show()
          logger.show_tabulated("Watching", showpath(source), "(press Ctrl-C to end)...")
  
          def recompile(path):
              path = fixpath(path)
              if os.path.isfile(path) and os.path.splitext(path)[1] in code_exts:
                  with self.handling_exceptions():
                      if write is True or write is None:
                          writedir = write
                      else:
                          # correct the compilation path based on the relative position of path to source
                          dirpath = os.path.dirname(path)
                          writedir = os.path.join(write, os.path.relpath(dirpath, source))
                      filepaths = self.compile_path(path, writedir, package, run, force, show_unchanged=False)
                      self.run_mypy(filepaths)
  
          watcher = RecompilationWatcher(recompile)
          observer = Observer()
          observer.schedule(watcher, source, recursive=True)
  
          with self.running_jobs():
              observer.start()
              try:
                  while True:
                      time.sleep(watch_interval)
                      watcher.keep_watching()
              except KeyboardInterrupt:
                  logger.show_sig("Got KeyboardInterrupt; stopping watcher.")
              finally:
                  observer.stop()
                  observer.join()
docs: Watch a source and recompiles on change.