Skip to content

Commit

Permalink
austinkline/windows (#6)
Browse files Browse the repository at this point in the history
* Windows Compatibility

- Fix path generation to permit windows compatibility
- use `pip install -e .` when installing for unit and integration tests
- add install hooks for nbextensions using jupyter install syntax
- fix bug causing datetimes to not be serialized properly from Neptune

Co-authored-by: Austin Kline <[email protected]>
  • Loading branch information
austinkline and Austin Kline authored Nov 10, 2020
1 parent e93f281 commit c2bc0b1
Show file tree
Hide file tree
Showing 39 changed files with 4,835 additions and 1,422 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install
run: |
pip install .
pip install -e .
- name: Create Stack
id: create-stack
run: |
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install
run: |
pip install .
pip install -e .
- name: Give user /etc/hosts permission
run: |
sudo chmod 777 /etc/hosts
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ jobs:
- name: Install
run: |
pip install .
pip install -e .
- name: Post-install commands
run: |
jupyter nbextension install --py --sys-prefix graph_notebook.widgets
jupyter nbextension enable --py --sys-prefix graph_notebook.widgets
python -m graph_notebook.static_resources.install
python -m graph_notebook.nbextensions.install
python -m graph_notebook.notebooks.install
- name: Test with pytest
run: |
pytest
8 changes: 2 additions & 6 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
include tsconfig.json
include package.json
include webpack.config.js
include src/graph_notebook/widgets/labextension/*.tgz

# Javascript files
graft graph_notebook/widgets/nbextension
graft graph_notebook/widgets/labextension
graft graph_notebook/widgets/src
graft graph_notebook/widgets/css
graft **/node_modules
recursive-include src/graph_notebook/widgets *
prune **/node_modules
prune coverage

# Patterns to exclude from any directory
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Python package integrating Jupyter notebooks with various graph-stores including
[Apache TinkerPop](https://tinkerpop.apache.org/) and [RDF SPARQL](https://www.w3.org/TR/rdf-sparql-query/).

## Requirements
- Python 3.6

- Python 3.6.1 or higher, Python 3.7
- Jupyter Notebook

## Introduction
The graph-notebook provides a way to interact using a Jupyter notebook with any graph database that follows the Gremlin Server or RDF HTTP protocols. These databases could be running locally on your laptop, in a private data center or in the cloud. This project was initially created as a way to work with Amazon Neptune but is not limited to that database engine. For example you can connect to a Gremlin Server running on your laptop using this solution. The instructions below describe the process for connecting to Amazon Neptune. We encourage others to contribute configurations they find useful. There is an [`additional-databases`](additional-databases) folder where such information can be found.


## Installation

```
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPARQLWrapper==1.8.4
networkx==2.4
Jinja2==2.10.1
jupyter
notebook<=5.7.8
notebook==5.7.10
ipywidgets
jupyter-contrib-nbextensions
widgetsnbextension
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[options]
packages =
graph_notebook
include_package_data = True

[tool:pytest]
minversion = 6.0
addopts = -ra -q
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def get_version():
'jupyter>=1.0.0'
],
package_data={
'graph_notebook': ['graph_notebook/widgets/nbextensions/static/*.js',
'graph_notebook/widgets/labextension/*.tgz'],
'': ['*.ipynb', '*.html', '*.css', '*.js', '*.txt', '*.json', '*.ts', '*.css', '*.yaml', '*.md', '*.tgz']
},
cmdclass=cmd_class,
Expand Down
2 changes: 1 addition & 1 deletion src/graph_notebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
SPDX-License-Identifier: Apache-2.0
"""

__version__ = '1.32.0'
__version__ = '1.33.0'
25 changes: 25 additions & 0 deletions src/graph_notebook/nbextensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""


def _jupyter_nbextension_paths():
return [
dict(
section="notebook",
src="gremlin_syntax/static",
dest="gremlin_syntax",
require="gremlin_syntax/main"),
dict(
section="notebook",
src="sparql_syntax/static",
dest="sparql_syntax",
require="sparql_syntax/main"),
dict(
section="notebook",
src="neptune_menu/static",
dest="neptune_menu",
require="neptune_menu/main"),
dict(
section="notebook",
src="playable_cells/static",
dest="playable_cells",
require="playable_cells/main"),
]
10 changes: 10 additions & 0 deletions src/graph_notebook/nbextensions/gremlin_syntax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""


# template for this taken from
# https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Defining-the-server-extension-and-nbextension
def _jupyter_nbextension_paths():
return [dict(
section="notebook",
src="static",
dest="gremlin_syntax",
require="gremlin_syntax/main")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""
19 changes: 8 additions & 11 deletions src/graph_notebook/nbextensions/install.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""

import argparse
import os

Expand All @@ -16,17 +21,9 @@ def main():
parser.add_argument('--plugin-name', default='', type=str, help='install and enable this jupyter plugin')

args = parser.parse_args()
if args.plugin_name == '':
for p in PLUGINS:
os.system(f'''echo "installing {p}";\
cd {dir_path}; \
jupyter nbextension install {p} --sys-prefix --overwrite;\
jupyter nbextension enable {p}/main --sys-prefix''')
else:
os.system(f'''echo "installing {args.plugin_name}";\
cd {dir_path}; \
jupyter nbextension install {args.plugin_name} --sys-prefix --overwrite;\
jupyter nbextension enable {args.plugin_name}/main --sys-prefix''')
plugin_name = 'graph_notebook.nbextensions' if args.plugin_name == '' else args.plugin_name
os.system(f'''jupyter nbextension install --py {plugin_name} --sys-prefix --overwrite''')
os.system(f'''jupyter nbextension enable --py {plugin_name} --sys-prefix''')


if __name__ == '__main__':
Expand Down
10 changes: 10 additions & 0 deletions src/graph_notebook/nbextensions/neptune_menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""


# template for this taken from
# https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Defining-the-server-extension-and-nbextension
def _jupyter_nbextension_paths():
return [dict(
section="notebook",
src="static",
dest="neptune_menu",
require="neptune_menu/main")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""
10 changes: 10 additions & 0 deletions src/graph_notebook/nbextensions/playable_cells/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""


# template for this taken from
# https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Defining-the-server-extension-and-nbextension
def _jupyter_nbextension_paths():
return [dict(
section="notebook",
src="static",
dest="playable_cells",
require="playable_cells/main")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""
10 changes: 10 additions & 0 deletions src/graph_notebook/nbextensions/sparql_syntax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""


# template for this taken from
# https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Defining-the-server-extension-and-nbextension
def _jupyter_nbextension_paths():
return [dict(
section="notebook",
src="static",
dest="sparql_syntax",
require="sparql_syntax/main")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
"""
2 changes: 1 addition & 1 deletion src/graph_notebook/network/gremlin/GremlinNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def parse_pattern_list_str(pattern_str: str) -> list:


def generate_id_from_dict(data: dict) -> str:
data_str = json.dumps(data)
data_str = json.dumps(data, default=str)
hashed = hashlib.md5(data_str.encode())
generate_id = hashed.hexdigest()
return f'graph_notebook-{generate_id}'
Expand Down
9 changes: 5 additions & 4 deletions src/graph_notebook/seed/load_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
"""

import os
from os.path import join as pjoin


# returns a list of queries which correspond to a given query language and name
def get_queries(query_language, name):
d = os.path.dirname(os.path.realpath(__file__))
path_to_data_sets = f'{d}/queries/{query_language}/{name}'
path_to_data_sets = pjoin(d, 'queries', query_language, name)
queries = []

for file in os.listdir(path_to_data_sets):
if file == '__init__.py' or file == '__pycache__':
continue
full_path = f'{path_to_data_sets}/{file}'
full_path = pjoin(path_to_data_sets, file)
with open(full_path, mode='r', encoding="utf-8") as f:
query = {
'name': file,
Expand All @@ -29,9 +30,9 @@ def get_queries(query_language, name):
def get_data_sets(query_language):
query_language = query_language.lower()
d = os.path.dirname(os.path.realpath(__file__))
path_to_data_sets = f'{d}/queries/{query_language}'
path_to_data_sets = pjoin(d, 'queries', query_language)
data_sets = []
for data_set in os.listdir(path_to_data_sets):
if data_set != '__pycache__' and os.path.isdir(f'{path_to_data_sets}/{data_set}'):
if data_set != '__pycache__' and os.path.isdir(pjoin(path_to_data_sets, data_set)):
data_sets.append(data_set)
return data_sets
8 changes: 5 additions & 3 deletions src/graph_notebook/static_resources/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import site
from shutil import copy2
from os.path import join as pjoin

files = [
'datatables.css',
Expand All @@ -14,12 +15,13 @@


def main():
sitepackages = site.getsitepackages()[0]
destination = f'{sitepackages}/notebook/static'
sitepackages = site.getsitepackages()
static_base_directory = sitepackages[0] if os.name != 'nt' else sitepackages[1]
destination = pjoin(static_base_directory, 'notebook', 'static')

dir_path = os.path.dirname(os.path.realpath(__file__))
for file in files:
full_path = f'{dir_path}/{file}'
full_path = pjoin(dir_path, file)
print(f'copying file {file} to {destination}')
copy2(full_path, destination)

Expand Down
10 changes: 10 additions & 0 deletions src/graph_notebook/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
SPDX-License-Identifier: Apache-2.0
"""

import json
import os

from .force import Force # noqa F401


def get_package_json():
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'package.json'), 'r') as file:
package_json = json.load(file)
return package_json


def _jupyter_nbextension_paths():
"""Called by Jupyter Notebook Server to detect if it is a valid nbextension and
to install the widget
Expand Down
Loading

0 comments on commit c2bc0b1

Please sign in to comment.