Skip to content

Commit

Permalink
Merge GREMLIN35-v2 into GREMLIN35 (#208)
Browse files Browse the repository at this point in the history
* Pin ipython and ipykernel dependency versions (#207)

* Pin ipython and ipykernel dependency versions

* Update Changelog

Co-authored-by: Michael Chin <chnmch@amazon.com>

* Apply nest_asyncio for Gremlin client requests, Update dependencies and install docs

* Switch to python script for starting jupyter

* Allow specifying notebooks directory on startup

* Pinning nbconvert version to resolve ipython-contrib/jupyter_contrib_nbextensions#1529

* Fix OC query smart indent bug

* Fix failure to overwrite notebook.json

Co-authored-by: Michael Chin <chnmch@amazon.com>
  • Loading branch information
michaelnchin and michaelnchin authored Oct 20, 2021
1 parent bc6a744 commit 19a85fb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
- Allow `%%neptune_ml` to accept JSON blob as parameter input for most phases ([Link to PR](https://github.com/aws/graph-notebook/pull/202))
- Added `--silent` option for suppressing query output ([PR #1](https://github.com/aws/graph-notebook/pull/201)) ([PR #2](https://github.com/aws/graph-notebook/pull/203))
- Added all `parserConfiguration` options to `%load` ([Link to PR](https://github.com/aws/graph-notebook/pull/205))
- Pinned `ipython` and `ipykernel` dependency versions ([Link to PR](https://github.com/aws/graph-notebook/pull/207))

## Release 3.0.6 (September 20, 2021)
- Added a new `%stream_viewer` magic that allows interactive exploration of the Neptune CDC stream (if enabled). ([Link to PR](https://github.com/aws/graph-notebook/pull/191))
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ It is recommended to check the [ChangeLog.md](ChangeLog.md) file periodically to

You will need:

* [Python](https://www.python.org/downloads/) 3.6.1-3.6.12
* [Jupyter Notebook](https://jupyter.org/install) 5.7.13
* [Tornado](https://pypi.org/project/tornado/) 4.5.3
* [Python](https://www.python.org/downloads/) 3.6.13-3.9.7
* [RDFLib](https://pypi.org/project/rdflib/) 5.0.0
* A graph database that provides one or more of:
* A SPARQL 1.1 endpoint
Expand All @@ -101,9 +99,7 @@ You will need:
## Installation

```
# pin specific versions of Jupyter, Tornado, and RDFLib dependencies
pip install notebook==5.7.13
pip install tornado==4.5.3
# pin specific versions of required dependencies
pip install rdflib==5.0.0
# install the package
Expand All @@ -121,7 +117,7 @@ python -m graph_notebook.nbextensions.install
python -m graph_notebook.notebooks.install --destination ~/notebook/destination/dir
# start jupyter
jupyter notebook ~/notebook/destination/dir
python -m graph_notebook.start_notebook --notebooks-dir ~/notebook/destination/dir
```

## Connecting to a graph database
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
tornado==4.5.3
SPARQLWrapper==1.8.4
networkx==2.4
Jinja2==2.11.3
jupyter
notebook==5.7.13
notebook>=6.1.5
ipywidgets==7.5.1
jupyter-contrib-nbextensions
widgetsnbextension
gremlinpython<=3.4.*
gremlinpython>=3.5.1
requests==2.24.0
ipython==7.16.1
ipython>=7.16.1
ipykernel==5.3.4
neo4j==4.2.1
rdflib~=5.0.0
traitlets~=4.3.3
setuptools~=40.6.2
nbconvert<6

# requirements for testing
botocore~=1.18.18
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ def get_version():
package_dir={'': 'src'},
include_package_data=True,
install_requires=[
'gremlinpython<3.5.*',
'gremlinpython>=3.5.1',
'SPARQLWrapper==1.8.4',
'tornado==4.5.3',
'requests',
'ipywidgets',
'networkx==2.4',
'Jinja2==2.11.3',
'notebook',
'notebook>=6.1.5',
'jupyter-contrib-nbextensions',
'widgetsnbextension',
'jupyter>=1.0.0',
Expand All @@ -82,7 +81,9 @@ def get_version():
'boto3>=1.17.58',
'ipython>=7.16.1',
'neo4j==4.3.2',
'rdflib==5.0.0'
'rdflib==5.0.0',
'ipykernel==5.3.4',
'nbconvert==5.6.1'
],
package_data={
'graph_notebook': ['graph_notebook/widgets/nbextensions/static/*.js',
Expand Down
4 changes: 3 additions & 1 deletion src/graph_notebook/neptune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from botocore.awsrequest import AWSRequest
from gremlin_python.driver import client
from neo4j import GraphDatabase
from tornado import httpclient
import nest_asyncio

# This patch is no longer needed when graph_notebook is using the a Gremlin Python
# client >= 3.5.0 as the HashableDict is now part of that client driver.
Expand Down Expand Up @@ -160,6 +160,8 @@ def sparql_cancel(self, query_id: str, silent: bool = False):
return self._query_status('sparql', query_id=query_id, silent=silent, cancelQuery=True)

def get_gremlin_connection(self) -> client.Client:
nest_asyncio.apply()

uri = f'{self._http_protocol}://{self.host}:{self.port}/gremlin'
request = self._prepare_request('GET', uri)

Expand Down
48 changes: 48 additions & 0 deletions src/graph_notebook/start_notebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""

import os
import argparse
import json

HOME_PATH = os.path.expanduser("~")
NOTEBOOK_CFG_PATH = HOME_PATH + '/.jupyter/nbconfig/notebook.json'


def patch_cm_cypher_config():
cypher_cfg = {
"cm_config": {
"smartIndent": False,
"mode": "cypher"
}
}

try:
with open(NOTEBOOK_CFG_PATH, 'r') as file:
notebook_cfg = json.load(file)
except (json.decoder.JSONDecodeError, FileNotFoundError) as e:
notebook_cfg = {}

notebook_cfg["CodeCell"] = cypher_cfg

with open(NOTEBOOK_CFG_PATH, 'w') as file:
json.dump(notebook_cfg, file)


def main():
parser = argparse.ArgumentParser()
parser.add_argument('--notebooks-dir', default='', type=str, help='The directory to start Jupyter from.')

args = parser.parse_args()

patch_cm_cypher_config()

kernel_manager_option = "--NotebookApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager"
notebooks_dir = '~/notebook/destination/dir' if args.notebooks_dir == '' else args.notebooks_dir
os.system(f'''jupyter notebook {kernel_manager_option} {notebooks_dir}''')


if __name__ == '__main__':
main()

0 comments on commit 19a85fb

Please sign in to comment.