Skip to content

Commit

Permalink
Merge pull request #4 from crabhi/master
Browse files Browse the repository at this point in the history
Normalize default uri into a config option
  • Loading branch information
versae committed May 4, 2015
2 parents b261575 + b9813e7 commit 01595a6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========

Expand Down
3 changes: 3 additions & 0 deletions src/cypher/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/cypher/parse.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/cypher/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/cypher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
text_type = str
string_types = (str, )

DEFAULT_URI = 'http://localhost:7474/db/data/'
DEFAULT_CONFIGURABLE = {
"auto_limit": 0,
"style": 'DEFAULT',
Expand All @@ -29,6 +28,7 @@
"auto_networkx": False,
"rest": False,
"feedback": True,
"uri": 'http://localhost:7474/db/data/',
}

DefaultConfigurable = namedtuple(
Expand Down

0 comments on commit 01595a6

Please sign in to comment.