code: def setup_env(app):
      
      env = app.env
      GalleryEntryExtractor.env = env
      out_imgdir = os.path.join(app.outdir, '_images')
  
      if not os.path.isdir(RST_PATH):
          os.makedirs(RST_PATH)
  
      if not os.path.isdir(out_imgdir):
          os.makedirs(out_imgdir)
  
      if not hasattr(env, 'gallery_entries'):
          # When rebuilding, the pickeled environment has the
          # gallery entries. If caching becomes a problem we
          # can clear the entries at the start of every build.
          # Otherwise, `make clean && make html` should suffice.
          env.gallery_entries = []
          env.has_gallery_entries = False
      else:
          env.has_gallery_entries = True
docs: Setup enviroment
  
      Creates required directory and storage objects (on the
      global enviroment) used by this extension.