Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @neptune_graph_only decorator #569

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd

## Upcoming
- Updated `create-graph` CLI commands in Neptune Analytics samples ([Link to PR](https://github.com/aws/graph-notebook/pull/565))
- Added `@neptune_graph_only` magics decorator ([Link to PR](https://github.com/aws/graph-notebook/pull/569))

## Release 4.1.0 (February 1, 2024)
- New Neptune Analytics notebook - Vector Similarity Algorithms ([Link to PR](https://github.com/aws/graph-notebook/pull/555))
Expand Down
19 changes: 18 additions & 1 deletion src/graph_notebook/decorators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import ipywidgets as widgets
from graph_notebook.visualization.template_retriever import retrieve_template
from graph_notebook.neptune.client import NEPTUNE_ANALYTICS_SERVICE_NAME
from graph_notebook.neptune.client import NEPTUNE_ANALYTICS_SERVICE_NAME, NEPTUNE_DB_SERVICE_NAME
from gremlin_python.driver.protocol import GremlinServerError
from requests import HTTPError

Expand Down Expand Up @@ -151,6 +151,23 @@ def check_neptune_db(*args, **kwargs):
return check_neptune_db


def neptune_graph_only(func):
@functools.wraps(func)
def check_neptune_graph(*args, **kwargs):
self = args[0]
if not hasattr(self.graph_notebook_config, 'neptune_service'):
return func(*args, **kwargs)
else:
service_type = self.graph_notebook_config.neptune_service
if service_type == NEPTUNE_DB_SERVICE_NAME:
print(f'This magic is unavailable for Neptune DB.')
return
else:
return func(*args, **kwargs)

return check_neptune_graph


def http_ex_to_html(http_ex: HTTPError):
try:
error = json.loads(http_ex.response.content.decode('utf-8'))
Expand Down
Loading