Skip to content

Commit

Permalink
Fix poetry plugin crash on windows when no pyproject.toml (#81)
Browse files Browse the repository at this point in the history
Also:
- Make the plugin handle unexpected errors more gracefully
- Update doc for installing plugin for correct shell syntax
  • Loading branch information
nat-n committed Jul 17, 2022
1 parent 2302abb commit 84b41ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion poethepoet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions poethepoet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ 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

debug = bool(int(os.environ.get("DEBUG_POE_PLUGIN", "0")))
print(
"error: poethepoet plugin failed to activate."
+ ("" if debug else " Set DEBUG_POE_PLUGIN=1 for details."),
file=sys.stderr,
)
if debug:
import traceback

traceback.print_exc()
raise SystemExit(1)

def _activate(self, application: Application) -> None:
try:
poe_config = self._get_config(application)
except RuntimeError:
Expand Down

0 comments on commit 84b41ea

Please sign in to comment.