code: def recursive_refs(envs, name):
      
      refs_by_name = {
          env['name']: set(env['refs'])
          for env in envs
      }
      refs = refs_by_name[name]
      if refs:
          indirect_refs = set(itertools.chain.from_iterable([
              recursive_refs(envs, ref)
              for ref in refs
          ]))
      else:
          indirect_refs = set()
      return set.union(refs, indirect_refs)
docs: Return set of recursive refs for given env name
  
      >>> local_refs = sorted(recursive_refs([
      ...     {'name': 'base', 'refs': []},
      ...     {'name': 'test', 'refs': ['base']},
      ...     {'name': 'local', 'refs': ['test']},
      ... ], 'local'))
      >>> local_refs == ['base', 'test']
      True