Skip to content

Commit

Permalink
fix(backends): only recommend installing ibis-foo when foo is a known…
Browse files Browse the repository at this point in the history
… backend

- list for _KNOWN_BACKENDS was compiled by referencing the backends
  that were not already part of ibis-framework:
  https://ibis-project.org/docs/3.1.0/backends/
  • Loading branch information
anjakefala authored and cpcloud committed Aug 9, 2022
1 parent 350fd43 commit ac6974a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions ibis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

__version__ = "3.1.0"

_KNOWN_BACKENDS = ['bigquery', 'heavyai']


def _get_backend_entrypoints() -> list[_importlib_metadata.EntryPoint]:
"""Get the list of installed `ibis.backend` entrypoints"""
Expand Down Expand Up @@ -56,11 +58,11 @@ def __getattr__(name: str) -> BaseBackend:
entry_points = {ep for ep in _get_backend_entrypoints() if ep.name == name}

if not entry_points:
raise AttributeError(
f"module 'ibis' has no attribute '{name}'. "
f"If you are trying to access the '{name}' backend, "
f"try installing it first with `pip install ibis-{name}`"
)
msg = f"module 'ibis' has no attribute '{name}'. "
if name in _KNOWN_BACKENDS:
msg += f"""If you are trying to access the '{name}' backend,
try installing it first with `pip install ibis-{name}`"""
raise AttributeError(msg)

if len(entry_points) > 1:
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion ibis/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_backends_tab_completion():


def test_missing_backend():
msg = "If you are trying to access the 'foo' backend"
msg = "module 'ibis' has no attribute 'foo'."
with pytest.raises(AttributeError, match=msg):
ibis.foo

Expand Down

0 comments on commit ac6974a

Please sign in to comment.