Skip to content

Commit

Permalink
Fix issue where errors would pop up if poetry was run outside of a pr…
Browse files Browse the repository at this point in the history
…oject
  • Loading branch information
vstrimaitis committed Aug 5, 2022
1 parent 95e81cf commit e5fc86b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-pre-commit-plugin"
version = "0.1.0"
version = "0.1.1"
description = "Poetry plugin for automatically installing pre-commit hook when it is added to a project"
authors = ["Vytautas Strimaitis <vstrimaitis@gmail.com>"]
homepage = "https://github.com/vstrimaitis/poetry-pre-commit-plugin"
Expand Down
14 changes: 9 additions & 5 deletions src/poetry_pre_commit_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def _handle_post_command(
# this attribute seems to only be present on a TERMINATE event, so be careful
# to not use similar logic if listening to different events
exit_code: int = event._exit_code
command = event.command

if not any(isinstance(command, t) for t in [InstallCommand, AddCommand]):
# Only run the plugin for install and add commands
return

if exit_code != 0:
# The command failed, so the plugin shouldn't do anything
Expand All @@ -38,11 +43,10 @@ def _handle_post_command(
# pre-commit hooks already installed - nothing to do
return

command = event.command
if isinstance(command, InstallCommand) or isinstance(command, AddCommand):
if command.option("dry-run") is True:
return
self._install_pre_commit_hooks(event.io)
if command.option("dry-run") is True:
return

self._install_pre_commit_hooks(event.io)

def _install_pre_commit_hooks(self, io: IO) -> None:
try:
Expand Down

0 comments on commit e5fc86b

Please sign in to comment.