-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge GREMLIN35-v2 into GREMLIN35 (#208)
* 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
1 parent
bc6a744
commit 19a85fb
Showing
6 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |