From b9813e766f80b6ce97dd695a9bd9d077225f21f5 Mon Sep 17 00:00:00 2001 From: Filip Sedlak Date: Sat, 2 May 2015 11:23:23 +0200 Subject: [PATCH] Normalize default uri into a config option --- docs/index.rst | 13 +++++++++++++ src/cypher/magic.py | 3 +++ src/cypher/parse.py | 5 +---- src/cypher/run.py | 4 ++-- src/cypher/utils.py | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index a6f130c..b9afca3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -83,6 +83,19 @@ Or to a NetworkX ``MultiDiGraph``:: See real examples in an `IPython Notebook`_. +Configuration +============= + +To change the behaviour of the cypher magic function, you can configure it:: + + %config CypherMagic + + ... list of options + + %config CypherMagic.some_option = new_value + + + Contents ======== diff --git a/src/cypher/magic.py b/src/cypher/magic.py index 2fbe113..78824d8 100644 --- a/src/cypher/magic.py +++ b/src/cypher/magic.py @@ -56,6 +56,9 @@ class CypherMagic(Magics, Configurable): feedback = Bool(defaults.feedback, config=True, help=""" Print number of rows affected """) + uri = Unicode(defaults.uri, config=True, help=""" + Default database URL if none is defined inline + """) def __init__(self, shell): Configurable.__init__(self, config=shell.config) diff --git a/src/cypher/parse.py b/src/cypher/parse.py index 2cb8f08..0ccafba 100644 --- a/src/cypher/parse.py +++ b/src/cypher/parse.py @@ -1,12 +1,9 @@ import os -from cypher.utils import DEFAULT_URI - - def parse(cell, config): uri = (os.environ.get("NEO4J_URI") or os.environ.get("NEO4J_URL") - or DEFAULT_URI) + or config.uri) uri_as = "" parts = [part.strip() for part in cell.split(None, 1)] if not parts: diff --git a/src/cypher/run.py b/src/cypher/run.py index 6356017..355d352 100644 --- a/src/cypher/run.py +++ b/src/cypher/run.py @@ -25,7 +25,7 @@ from cypher.column_guesser import ColumnGuesserMixin from cypher.connection import Connection from cypher.utils import ( - DefaultConfigurable, DEFAULT_URI, DEFAULT_CONFIGURABLE, StringIO, + DefaultConfigurable, DEFAULT_CONFIGURABLE, StringIO, string_types ) @@ -489,7 +489,7 @@ def run(query, params=None, config=None, conn=None, **kwargs): if params is None: params = {} if conn is None: - conn = Connection.get(DEFAULT_URI) + conn = Connection.get(DEFAULT_CONFIGURABLE["uri"]) elif isinstance(conn, string_types): conn = Connection.get(conn) if config is None: diff --git a/src/cypher/utils.py b/src/cypher/utils.py index cdbf5b6..28c006e 100644 --- a/src/cypher/utils.py +++ b/src/cypher/utils.py @@ -17,7 +17,6 @@ text_type = str string_types = (str, ) -DEFAULT_URI = 'http://localhost:7474/db/data/' DEFAULT_CONFIGURABLE = { "auto_limit": 0, "style": 'DEFAULT', @@ -29,6 +28,7 @@ "auto_networkx": False, "rest": False, "feedback": True, + "uri": 'http://localhost:7474/db/data/', } DefaultConfigurable = namedtuple(