prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  On first call, `pyodide config get emscripten_version` returns `Downloading xbuild environment Installing xbuild environment 3.1.27` instead of `3.1.27`
  ## 🐛 Bug
  
  In [the docs for out-of-tree builds](https://pyodide.org/en/stable/development/building-and-testing-packages.html#building-and-testing-packages-out-of-tree) it gives this code snippet:
  
  ```bash
  pip install pyodide-build
  
  git clone https://github.com/emscripten-core/emsdk.git
  cd emsdk
  
  PYODIDE_EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
  ./emsdk install ${PYODIDE_EMSCRIPTEN_VERSION}
  ./emsdk activate ${PYODIDE_EMSCRIPTEN_VERSION}
  source emsdk_env.sh
  ```
  But this doesn't work because on the first call, `pyodide config get emscripten_version` outputs this:
  ```
  Downloading xbuild environment
  Installing xbuild environment
  3.1.27
  ```
  On subsequent calls it returns `3.1.27`.
  
  ### To Reproduce
  
  See above.
  
  ### Expected behavior
  
  Calls to `pyodide config get emscripten_version` should only ever output the version string such that this command can be reliably used in build automation.
  
  ### Environment
  
  - Pyodide Version<!-- (e.g. 1.8.1) -->: Pyodide CLI Version: 0.2.2
  
  ### Additional context
  
  As a workaround for build scripts, `pyodide config get emscripten_version` can be called once before actually using it.
  
  
  </issue>
  <code>
  [start of pyodide-build/pyodide_build/cli/config.py]
  1 import typer
  2 
  3 from ..common import get_make_environment_vars
  4 from ..out_of_tree.utils import initialize_pyodide_root
  5 
  6 app = typer.Typer(help="Manage config variables used in pyodide")
  7 
  8 
  9 # A dictionary of config variables {key: env_var_in_makefile}
  10 PYODIDE_CONFIGS = {
  11     "emscripten_version": "PYODIDE_EMSCRIPTEN_VERSION",
  12     "python_version": "PYVERSION",
  13 }
  14 
  15 
  16 @app.callback(no_args_is_help=True)  # type: ignore[misc]
  17 def callback() -> None:
  18     return
  19 
  20 
  21 def _get_configs() -> dict[str, str]:
  22     initialize_pyodide_root()
  23 
  24     configs: dict[str, str] = get_make_environment_vars()
  25 
  26     configs_filtered = {k: configs[v] for k, v in PYODIDE_CONFIGS.items()}
  27     return configs_filtered
  28 
  29 
  30 @app.command("list")
  31 def list_config():
  32     """
  33     List config variables used in pyodide
  34     """
  35     configs = _get_configs()
  36 
  37     for k, v in configs.items():
  38         typer.echo(f"{k}={v}")
  39 
  40 
  41 @app.command("get")  # type: ignore[misc]
  42 def get_config(
  43     config_var: str = typer.Argument(
  44         ..., help="A config variable to get. Use `list` to see all possible values."
  45     ),
  46 ) -> None:
  47     """
  48     Get a value of a single config variable used in pyodide
  49     """
  50     configs = _get_configs()
  51 
  52     if config_var not in configs:
  53         typer.echo(f"Config variable {config_var} not found.")
  54         typer.Exit(1)
  55 
  56     typer.echo(configs[config_var])
  57
  [end of pyodide-build/pyodide_build/cli/config.py]
  [start of pyodide-build/pyodide_build/out_of_tree/utils.py]
  1 import os
  2 from pathlib import Path
  3 
  4 from ..common import search_pyodide_root
  5 
  6 
  7 def ensure_env_installed(env: Path) -> None:
  8     if env.exists():
  9         return
  10     from .. import __version__
  11     from ..install_xbuildenv import download_xbuildenv, install_xbuildenv
  12 
  13     if "dev" in __version__:
  14         raise RuntimeError(
  15             "To use out of tree builds with development Pyodide, you must explicitly set PYODIDE_ROOT"
  16         )
  17 
  18     download_xbuildenv(__version__, env)
  19     install_xbuildenv(__version__, env)
  20 
  21 
  22 def initialize_pyodide_root() -> None:
  23     if "PYODIDE_ROOT" in os.environ:
  24         return
  25     try:
  26         os.environ["PYODIDE_ROOT"] = str(search_pyodide_root(__file__))
  27         return
  28     except FileNotFoundError:
  29         pass
  30     env = Path(".pyodide-xbuildenv")
  31     os.environ["PYODIDE_ROOT"] = str(env / "xbuildenv/pyodide-root")
  32     ensure_env_installed(env)
  33
  [end of pyodide-build/pyodide_build/out_of_tree/utils.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pyodide-build/pyodide_build/cli/config.py b/pyodide-build/pyodide_build/cli/config.py
  --- a/pyodide-build/pyodide_build/cli/config.py
  +++ b/pyodide-build/pyodide_build/cli/config.py
  @@ -19,7 +19,7 @@
   
   
   def _get_configs() -> dict[str, str]:
  -    initialize_pyodide_root()
  +    initialize_pyodide_root(quiet=True)
   
       configs: dict[str, str] = get_make_environment_vars()
   
  diff --git a/pyodide-build/pyodide_build/out_of_tree/utils.py b/pyodide-build/pyodide_build/out_of_tree/utils.py
  --- a/pyodide-build/pyodide_build/out_of_tree/utils.py
  +++ b/pyodide-build/pyodide_build/out_of_tree/utils.py
  @@ -1,10 +1,12 @@
   import os
  +from contextlib import ExitStack, redirect_stdout
  +from io import StringIO
   from pathlib import Path
   
   from ..common import search_pyodide_root
   
   
  -def ensure_env_installed(env: Path) -> None:
  +def ensure_env_installed(env: Path, *, quiet: bool = False) -> None:
       if env.exists():
           return
       from .. import __version__
  @@ -15,11 +17,16 @@
               "To use out of tree builds with development Pyodide, you must explicitly set PYODIDE_ROOT"
           )
   
  -    download_xbuildenv(__version__, env)
  -    install_xbuildenv(__version__, env)
  +    with ExitStack() as stack:
  +        if quiet:
  +            # Prevent writes to stdout
  +            stack.enter_context(redirect_stdout(StringIO()))
   
  +        download_xbuildenv(__version__, env)
  +        install_xbuildenv(__version__, env)
   
  -def initialize_pyodide_root() -> None:
  +
  +def initialize_pyodide_root(*, quiet: bool = False) -> None:
       if "PYODIDE_ROOT" in os.environ:
           return
       try:
  @@ -29,4 +36,4 @@
           pass
       env = Path(".pyodide-xbuildenv")
       os.environ["PYODIDE_ROOT"] = str(env / "xbuildenv/pyodide-root")
  -    ensure_env_installed(env)
  +    ensure_env_installed(env, quiet=quiet)
  
verification_info: {"golden_diff": "diff --git a/pyodide-build/pyodide_build/cli/config.py b/pyodide-build/pyodide_build/cli/config.py\n--- a/pyodide-build/pyodide_build/cli/config.py\n+++ b/pyodide-build/pyodide_build/cli/config.py\n@@ -19,7 +19,7 @@\n \n \n def _get_configs() -> dict[str, str]:\n-    initialize_pyodide_root()\n+    initialize_pyodide_root(quiet=True)\n \n     configs: dict[str, str] = get_make_environment_vars()\n \ndiff --git a/pyodide-build/pyodide_build/out_of_tree/utils.py b/pyodide-build/pyodide_build/out_of_tree/utils.py\n--- a/pyodide-build/pyodide_build/out_of_tree/utils.py\n+++ b/pyodide-build/pyodide_build/out_of_tree/utils.py\n@@ -1,10 +1,12 @@\n import os\n+from contextlib import ExitStack, redirect_stdout\n+from io import StringIO\n from pathlib import Path\n \n from ..common import search_pyodide_root\n \n \n-def ensure_env_installed(env: Path) -> None:\n+def ensure_env_installed(env: Path, *, quiet: bool = False) -> None:\n     if env.exists():\n         return\n     from .. import __version__\n@@ -15,11 +17,16 @@\n             \"To use out of tree builds with development Pyodide, you must explicitly set PYODIDE_ROOT\"\n         )\n \n-    download_xbuildenv(__version__, env)\n-    install_xbuildenv(__version__, env)\n+    with ExitStack() as stack:\n+        if quiet:\n+            # Prevent writes to stdout\n+            stack.enter_context(redirect_stdout(StringIO()))\n \n+        download_xbuildenv(__version__, env)\n+        install_xbuildenv(__version__, env)\n \n-def initialize_pyodide_root() -> None:\n+\n+def initialize_pyodide_root(*, quiet: bool = False) -> None:\n     if \"PYODIDE_ROOT\" in os.environ:\n         return\n     try:\n@@ -29,4 +36,4 @@\n         pass\n     env = Path(\".pyodide-xbuildenv\")\n     os.environ[\"PYODIDE_ROOT\"] = str(env / \"xbuildenv/pyodide-root\")\n-    ensure_env_installed(env)\n+    ensure_env_installed(env, quiet=quiet)\n", "issue": "On first call, `pyodide config get emscripten_version` returns `Downloading xbuild environment Installing xbuild environment 3.1.27` instead of `3.1.27`\n## \ud83d\udc1b Bug\r\n\r\nIn [the docs for out-of-tree builds](https://pyodide.org/en/stable/development/building-and-testing-packages.html#building-and-testing-packages-out-of-tree) it gives this code snippet:\r\n\r\n```bash\r\npip install pyodide-build\r\n\r\ngit clone https://github.com/emscripten-core/emsdk.git\r\ncd emsdk\r\n\r\nPYODIDE_EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)\r\n./emsdk install ${PYODIDE_EMSCRIPTEN_VERSION}\r\n./emsdk activate ${PYODIDE_EMSCRIPTEN_VERSION}\r\nsource emsdk_env.sh\r\n```\r\nBut this doesn't work because on the first call, `pyodide config get emscripten_version` outputs this:\r\n```\r\nDownloading xbuild environment\r\nInstalling xbuild environment\r\n3.1.27\r\n```\r\nOn subsequent calls it returns `3.1.27`.\r\n\r\n### To Reproduce\r\n\r\nSee above.\r\n\r\n### Expected behavior\r\n\r\nCalls to `pyodide config get emscripten_version` should only ever output the version string such that this command can be reliably used in build automation.\r\n\r\n### Environment\r\n\r\n- Pyodide Version<!-- (e.g. 1.8.1) -->: Pyodide CLI Version: 0.2.2\r\n\r\n### Additional context\r\n\r\nAs a workaround for build scripts, `pyodide config get emscripten_version` can be called once before actually using it.\r\n\n", "before_files": [{"content": "import typer\n\nfrom ..common import get_make_environment_vars\nfrom ..out_of_tree.utils import initialize_pyodide_root\n\napp = typer.Typer(help=\"Manage config variables used in pyodide\")\n\n\n# A dictionary of config variables {key: env_var_in_makefile}\nPYODIDE_CONFIGS = {\n    \"emscripten_version\": \"PYODIDE_EMSCRIPTEN_VERSION\",\n    \"python_version\": \"PYVERSION\",\n}\n\n\n@app.callback(no_args_is_help=True)  # type: ignore[misc]\ndef callback() -> None:\n    return\n\n\ndef _get_configs() -> dict[str, str]:\n    initialize_pyodide_root()\n\n    configs: dict[str, str] = get_make_environment_vars()\n\n    configs_filtered = {k: configs[v] for k, v in PYODIDE_CONFIGS.items()}\n    return configs_filtered\n\n\n@app.command(\"list\")\ndef list_config():\n    \"\"\"\n    List config variables used in pyodide\n    \"\"\"\n    configs = _get_configs()\n\n    for k, v in configs.items():\n        typer.echo(f\"{k}={v}\")\n\n\n@app.command(\"get\")  # type: ignore[misc]\ndef get_config(\n    config_var: str = typer.Argument(\n        ..., help=\"A config variable to get. Use `list` to see all possible values.\"\n    ),\n) -> None:\n    \"\"\"\n    Get a value of a single config variable used in pyodide\n    \"\"\"\n    configs = _get_configs()\n\n    if config_var not in configs:\n        typer.echo(f\"Config variable {config_var} not found.\")\n        typer.Exit(1)\n\n    typer.echo(configs[config_var])\n", "path": "pyodide-build/pyodide_build/cli/config.py"}, {"content": "import os\nfrom pathlib import Path\n\nfrom ..common import search_pyodide_root\n\n\ndef ensure_env_installed(env: Path) -> None:\n    if env.exists():\n        return\n    from .. import __version__\n    from ..install_xbuildenv import download_xbuildenv, install_xbuildenv\n\n    if \"dev\" in __version__:\n        raise RuntimeError(\n            \"To use out of tree builds with development Pyodide, you must explicitly set PYODIDE_ROOT\"\n        )\n\n    download_xbuildenv(__version__, env)\n    install_xbuildenv(__version__, env)\n\n\ndef initialize_pyodide_root() -> None:\n    if \"PYODIDE_ROOT\" in os.environ:\n        return\n    try:\n        os.environ[\"PYODIDE_ROOT\"] = str(search_pyodide_root(__file__))\n        return\n    except FileNotFoundError:\n        pass\n    env = Path(\".pyodide-xbuildenv\")\n    os.environ[\"PYODIDE_ROOT\"] = str(env / \"xbuildenv/pyodide-root\")\n    ensure_env_installed(env)\n", "path": "pyodide-build/pyodide_build/out_of_tree/utils.py"}]}