Repository: pyodide/pyodide

Issue:
Allow specifying output directory in pyodide build with -o or --outdir
I added the capability to specify output directory in pyodide build with `--output-directory`. But here `pypa/build` accepts either `--outdir` or `-o`. We should accept these as ways to specify the output directory for consistency


Discussion:
Can't we use the same parameter name as pypa/build? Or would that be a backward compatible change now? Maybe with a deprecation cycle..
I would say:
1. Add "correct" pypa/build names in addition to the "incorrect" one I used
2. remove "incorrect" name after a few versions

But we could remove it sooner if you strongly prefer. It just would make cibuildwheel add some version logic to decide which flags to pass.
It's certainly not urgent, as long as keep a single correct flag in the end. So a deprecation then removal after a few versions sounds good.

Resolving patch:
diff --git a/pyodide-build/pyodide_build/cli/build.py b/pyodide-build/pyodide_build/cli/build.py
--- a/pyodide-build/pyodide_build/cli/build.py
+++ b/pyodide-build/pyodide_build/cli/build.py
@@ -1,5 +1,6 @@
 import re
 import shutil
+import sys
 import tempfile
 from pathlib import Path
 from typing import Optional
@@ -113,9 +114,12 @@ def main(
         help="Build source, can be source folder, pypi version specification, or url to a source dist archive or wheel file. If this is blank, it will build the current directory.",
     ),
     output_directory: str = typer.Option(
-        "./dist",
+        "",
+        "--outdir",
+        "-o",
         help="which directory should the output be placed into?",
     ),
+    output_directory_compat: str = typer.Option("", "--output-directory", hidden=True),
     requirements_txt: str = typer.Option(
         "",
         "--requirements",
@@ -143,6 +147,16 @@ def main(
     ctx: typer.Context = typer.Context,
 ) -> None:
     """Use pypa/build to build a Python package from source, pypi or url."""
+    if output_directory_compat:
+        print(
+            "--output-directory is deprecated, use --outdir or -o instead",
+            file=sys.stderr,
+        )
+    if output_directory_compat and output_directory:
+        print("Cannot provide both --outdir and --output-directory", file=sys.stderr)
+        sys.exit(1)
+    output_directory = output_directory_compat or output_directory or "./dist"
+
     outpath = Path(output_directory).resolve()
     outpath.mkdir(exist_ok=True)
     extras: list[str] = []


Test patch:
diff --git a/pyodide-build/pyodide_build/tests/test_cli.py b/pyodide-build/pyodide_build/tests/test_cli.py
--- a/pyodide-build/pyodide_build/tests/test_cli.py
+++ b/pyodide-build/pyodide_build/tests/test_cli.py
@@ -444,9 +444,7 @@ def mocked_build(srcdir: Path, outdir: Path, env: Any, backend_flags: Any) -> st
     srcdir.mkdir()
     app = typer.Typer()
     app.command(**build.main.typer_kwargs)(build.main)  # type:ignore[attr-defined]
-    result = runner.invoke(
-        app, [str(srcdir), "--output-directory", str(outdir), "x", "y", "z"]
-    )
+    result = runner.invoke(app, [str(srcdir), "--outdir", str(outdir), "x", "y", "z"])
     print(result)
     print(result.stdout)
     assert result.exit_code == 0