From d2176037d7a80435f80385175044ee8a77a63a98 Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Sun, 17 Jul 2022 11:44:06 +0300 Subject: [PATCH] Fix poetry plugin crash on windows when no pyproject.toml (#79) Also: - Make the plugin handle unexpected errors more gracefully - Update doc for installing plugin for correct shell syntax --- README.rst | 2 +- poethepoet/config.py | 2 +- poethepoet/plugin.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 43932b83..e6189b1e 100644 --- a/README.rst +++ b/README.rst @@ -71,7 +71,7 @@ Installation .. code-block:: bash - poetry self add poethepoet[poetry_plugin] + poetry self add 'poethepoet[poetry_plugin]' Enable tab completion for your shell ------------------------------------ diff --git a/poethepoet/config.py b/poethepoet/config.py index e209161c..deea4a5c 100644 --- a/poethepoet/config.py +++ b/poethepoet/config.py @@ -215,7 +215,7 @@ def find_pyproject_toml(self, target_dir: Optional[str] = None) -> Path: maybe_result = self.cwd.joinpath(self.TOML_NAME) while not maybe_result.exists(): - if maybe_result.parent == Path("/"): + if len(maybe_result.parents) == 1: raise PoeException( f"Poe could not find a pyproject.toml file in {self.cwd} or" " its parents" diff --git a/poethepoet/plugin.py b/poethepoet/plugin.py index a69d9cc0..50526103 100644 --- a/poethepoet/plugin.py +++ b/poethepoet/plugin.py @@ -74,6 +74,23 @@ def get_poe(cls, application: Application, io: IO): class PoetryPlugin(ApplicationPlugin): def activate(self, application: Application) -> None: + try: + return self._activate(application) + # pylint: disable=bare-except + except: + import os, sys + + print( + "error: poethepoet plugin failed to activate. Set DEBUG_POE_PLUGIN=1 for details.", + file=sys.stderr, + ) + if os.environ.get("DEBUG_POE_PLUGIN"): + import traceback + + traceback.print_exc() + raise SystemExit(1) + + def _activate(self, application: Application) -> None: try: poe_config = self._get_config(application) except RuntimeError: