in google-cloud-jupyter-config/google/cloud/jupyter_config/config.py [0:0]
def run_gcloud_subcommand(subcmd):
"""Run a specified gcloud sub-command and return its output.
The supplied subcommand is the full command line invocation, *except* for
the leading `gcloud` being omitted.
e.g. `info` instead of `gcloud info`.
We reuse the system stderr for the command so that any prompts from gcloud
will be displayed to the user.
"""
with tempfile.TemporaryFile() as t:
p = subprocess.run(
f"gcloud {subcmd}",
stdin=subprocess.DEVNULL,
stderr=sys.stderr,
stdout=t,
check=True,
encoding="UTF-8",
shell=True,
)
t.seek(0)
return t.read().decode("UTF-8").strip()