Repository: sbidoul/pip-deepfreeze (language: python)

Issue:
Search for `py` before `python` when looking for the default python interpreter



Discussion / hints:

Fix patch:
diff --git a/README.rst b/README.rst
index 926c583..a0f2774 100644
--- a/README.rst
+++ b/README.rst
@@ -71,9 +71,9 @@ Using `pip <https://pypi.org/project/pip/>`__:
 
    It is *not* recommended to install ``pip-deepfreeze`` in the same environment as your
    application, so its dependencies do not interfere with your app. By default it works
-   with the ``python`` found in your ``PATH`` (which does what you normally expect in an
-   activated virtualenv), but you can ask it to work within another environment using
-   the ``--python`` option.
+   with the ``py`` or ``python`` executable found in your ``PATH`` (which does what you
+   normally expect in an activated virtualenv), but you can ask it to work within
+   another environment using the ``--python`` option.
 
 Quick start
 -----------
diff --git a/news/100.feature b/news/100.feature
new file mode 100644
index 0000000..0fd4858
--- /dev/null
+++ b/news/100.feature
@@ -0,0 +1,4 @@
+Search for ``py``, then ``python``  executable in ``PATH`` when the ``--python`` option
+is not provided. This should provide a better experience on `Windows
+<https://docs.python.org/3/using/windows.html#launcher>`_ and for users of the the
+`Python Launcher for Unix <https://python-launcher.app/>`_.
diff --git a/src/pip_deepfreeze/__main__.py b/src/pip_deepfreeze/__main__.py
index 005509a..3d79faf 100644
--- a/src/pip_deepfreeze/__main__.py
+++ b/src/pip_deepfreeze/__main__.py
@@ -1,6 +1,6 @@
 import shutil
 from pathlib import Path
-from typing import Any, List
+from typing import Any, List, Optional
 
 import typer
 from packaging.utils import canonicalize_name
@@ -113,18 +113,34 @@ def project_root_callback(ctx: typer.Context, param: Any, value: Path) -> Path:
     return value
 
 
+def _find_python_from(pythons: List[str]) -> str:
+    for python in pythons:
+        python_abspath = shutil.which(python)
+        if python_abspath:
+            return python_abspath
+    log_error(f"Python interpreter not found ({', '.join(pythons)}).")
+    raise typer.Exit(1)
+
+
+def _find_python(python: Optional[str]) -> str:
+    if python:
+        return _find_python_from([python])
+    return _find_python_from(["py", "python"])
+
+
 @app.callback()
 def callback(
     ctx: typer.Context,
-    python: str = typer.Option(
-        "python",
+    python: Optional[str] = typer.Option(
+        None,
         "--python",
+        "--py",
         "-p",
         show_default=False,
         metavar="PYTHON",
         help=(
             "The python executable to use. Determines the python environment to "
-            "work on. Defaults to the 'python' executable found in PATH."
+            "work on. Defaults to the 'py' or 'python' executable found in PATH."
         ),
     ),
     project_root: Path = typer.Option(
@@ -147,12 +163,8 @@ def callback(
     if verbose:
         increase_verbosity()
     # find python
-    python_abspath = shutil.which(python)
-    if not python_abspath:
-        log_error(f"Python interpreter {python!r} not found.")
-        raise typer.Exit(1)
-    ctx.obj.python = python_abspath
-    log_debug(f"Using python {python_abspath}")
+    ctx.obj.python = _find_python(python)
+    log_debug(f"Using python {ctx.obj.python}")
     # sanity checks
     if not check_env(ctx.obj.python):
         raise typer.Exit(1)


Test patch:
diff --git a/tests/test_sync.py b/tests/test_sync.py
index 075b01c..b495c07 100644
--- a/tests/test_sync.py
+++ b/tests/test_sync.py
@@ -73,7 +73,7 @@ def test_python_not_found():
     runner = CliRunner()
     result = runner.invoke(app, ["--python", "this-is-not-a-python", "sync"])
     assert result.exit_code != 0
-    assert "Python interpreter 'this-is-not-a-python' not found" in result.output
+    assert "Python interpreter not found (this-is-not-a-python)" in result.output
 
 
 @pytest.fixture