@memoized_method
  def list_imports(self, pkg, gopath=None):
    go_cmd = self._go_dist.create_go_cmd('list', args=['-json', pkg], gopath=gopath)
    with self._workunit_factory(pkg, cmd=str(go_cmd), labels=[WorkUnitLabel.TOOL]) as workunit:
      # TODO(John Sirois): It would be nice to be able to tee the stdout to the workunit to we have
      # a capture of the json available for inspection in the server console.
      process = go_cmd.spawn(stdout=subprocess.PIPE, stderr=workunit.output('stderr'))
      out, _ = process.communicate()
      returncode = process.returncode
      workunit.set_outcome(WorkUnit.SUCCESS if returncode == 0 else WorkUnit.FAILURE)
      if returncode != 0:
        raise self.ListDepsError('Problem listing imports for {}: {} failed with exit code {}'
                                 .format(pkg, go_cmd, returncode))
      data = json.loads(out)

      # XTestImports are for black box tests.  These test files live inside the package dir but
      # declare a different package and thus can only access the public members of the package's
      # production code.  This style of test necessarily means the test file will import the main
      # package.  For pants, this would lead to a cyclic self-dependency, so we omit the main
      # package as implicitly included as its own dependency.
      x_test_imports = [i for i in data.get('XTestImports', []) if i != pkg]

      return self.ImportListing(pkg_name=data.get('Name'),
                                imports=data.get('Imports', []),
                                test_imports=data.get('TestImports', []),
                                x_test_imports=x_test_imports)
Return a listing of the dependencies of the given package.
dataset/ETHPy150Open pantsbuild/pants/contrib/go/src/python/pants/contrib/go/tasks/go_task.py/ImportOracle.list_imports