Skip to content

Commit

Permalink
click no longer a hard dependency (#86)
Browse files Browse the repository at this point in the history
* click no longer a hard dependency

* changelog
  • Loading branch information
edublancas authored Jan 12, 2024
1 parent b865409 commit 581bbe1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.2.22dev

* [Fix] `click` is no longer a dependency

## 0.2.21 (2024-01-12)

* [Fix] Fix error when determining if telemetry call was from a cloud user
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)

REQUIRES = [
"click",
"pyyaml",
"posthog",
'importlib-metadata;python_version<"3.8"',
Expand Down
24 changes: 18 additions & 6 deletions src/ploomber_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
from functools import wraps
from gettext import gettext as _

from click.exceptions import ClickException
from click._compat import get_text_stderr
from click.utils import echo
# click is an optional dependency. only available in packages that expose a CLI
try:
from click.exceptions import ClickException
from click._compat import get_text_stderr
from click.utils import echo
except ModuleNotFoundError:
ClickException = Exception
get_text_stderr = None
echo = None
CLICK_AVAILABLE = False
else:
CLICK_AVAILABLE = True

COMMUNITY_LINK = "https://ploomber.io/community"

Expand Down Expand Up @@ -48,10 +57,13 @@ def get_message(self):
return f"Error: {_build_message(self)}"

def show(self, file: t.Optional[t.IO] = None) -> None:
if file is None:
file = get_text_stderr()
if CLICK_AVAILABLE:
if file is None:
file = get_text_stderr()

echo(_(self.get_message()), file=file)
echo(_(self.get_message()), file=file)
else:
print(_(self.get_message()))


class PloomberValueError(ValueError):
Expand Down

0 comments on commit 581bbe1

Please sign in to comment.