Skip to content

Commit

Permalink
remove dependency on flask_neomodel library
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeddy committed Jul 15, 2019
1 parent 513f7e7 commit 6084742
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 57 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ py2neo >= 2.5.0
healthcheck >= 1.3.3
iso8601 >= 0.1.12
pytz >= 2019.1
git+https://github.com/pdonorio/flask-neomodel.git@master
7 changes: 4 additions & 3 deletions synprov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from healthcheck import HealthCheck

from synprov import config
from synprov.config import neo4j_connection

def neo4j_available():
if config.neomod.test_connection():
try:
neo4j_connection.run('MATCH () RETURN 1 LIMIT 1')
return True, "neo4j ok"
else:
except AttributeError:
return False, "neo4j connection not found"


Expand Down
8 changes: 2 additions & 6 deletions synprov/__main__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/usr/bin/env python3

import connexion
from py2neo import Graph

from synprov import create_app
from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.graph.client import GraphClient
from synprov.mock.main import create_mock_graph


graph = Graph(neomod.neo.db.url)


def init_db(num_activities=30):
graph.run(
'''
Expand All @@ -26,7 +22,7 @@ def main():
app = create_app()

init_db()
app.run(host='localhost', port=8080, debug=True)
app.run(host='localhost', port=8080)


if __name__ == '__main__':
Expand Down
15 changes: 8 additions & 7 deletions synprov/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import os
import connexion

from flask_neomodel import NeoModel
from py2neo import Graph


connex_app = connexion.App(__name__, specification_dir='./openapi/')

env_host = os.environ.get('NEO4J_HOST')
neo4j_host = env_host if env_host is not None else 'localhost'
print(neo4j_host)

neo_user = os.environ['NEO4J_USERNAME']
neo_pass = os.environ['NEO4J_PASSWORD']

neomod = NeoModel(connex_app.app, variables={
'user': neo_user,
'password': neo_pass,
'host': neo4j_host,
'port': 7687
})
neo4j_connection = Graph(
scheme='bolt',
host=neo4j_host,
user=neo_user,
password=neo_pass
)
3 changes: 1 addition & 2 deletions synprov/graph/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from py2neo import Graph

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.models.activity_form import ActivityForm
from synprov.graph.client import GraphClient
from synprov.graph.models.activity import GraphActivity
Expand All @@ -12,7 +12,6 @@


logger = logging.getLogger(__name__)
graph = Graph(neomod.neo.db.url)


class ActivityBuilder(ActivityForm):
Expand Down
2 changes: 1 addition & 1 deletion synprov/graph/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import logging

from py2neo import Graph, Node
from py2neo import Node

from synprov.mock.dict import NodeRelationships

Expand Down
7 changes: 2 additions & 5 deletions synprov/graph/controllers/activities_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import humps
import json

from py2neo import Graph, Node, NodeMatcher
from py2neo import Node, NodeMatcher

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.graph import GraphActivity, GraphReference, GraphAgent
from synprov.util import neo4j_to_d3


graph = Graph(neomod.neo.db.url)


def create_activity(body=None): # noqa: E501
"""Create a new.
Expand Down
7 changes: 2 additions & 5 deletions synprov/graph/controllers/agents_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import uuid
import humps

from py2neo import Graph, Node, NodeMatcher
from py2neo import Node, NodeMatcher

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.graph import GraphActivity, GraphReference, GraphAgent


graph = Graph(neomod.neo.db.url)


def get_agent_subgraph(id): # noqa: E501
"""Get subgraph connected to an agent.
Expand Down
7 changes: 2 additions & 5 deletions synprov/graph/controllers/references_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import uuid
import humps

from py2neo import Graph, Node, NodeMatcher
from py2neo import Node, NodeMatcher

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.graph import GraphActivity, GraphReference, GraphAgent


graph = Graph(neomod.neo.db.url)


def get_reference_subgraph(id): # noqa: E501
"""Get subgraph connected to an entity.
Expand Down
7 changes: 0 additions & 7 deletions synprov/graph/models/activity.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import uuid

from py2neo import Graph, Node, Relationship, NodeMatcher

from synprov.config import neomod
from synprov.models.activity import Activity
from synprov.util import get_datetime


graph = Graph(neomod.neo.db.url)
matcher = NodeMatcher(graph)


class GraphActivity(Activity):

def __init__(self,
Expand Down
1 change: 0 additions & 1 deletion synprov/graph/models/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import uuid

from synprov.config import neomod
from synprov.models.agent import Agent
from synprov.util import get_datetime

Expand Down
7 changes: 0 additions & 7 deletions synprov/graph/models/reference.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import uuid

from py2neo import Graph, Node, Relationship, NodeMatcher

from synprov.config import neomod
from synprov.models.reference import Reference
from synprov.models.agent import Agent
from synprov.util import get_datetime

graph = Graph(neomod.neo.db.url)
matcher = NodeMatcher(graph)


class GraphReference(Reference):

Expand Down
5 changes: 2 additions & 3 deletions synprov/mock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import argparse

from random import randrange
from py2neo import Graph, Node, NodeMatcher
from py2neo import Node, NodeMatcher

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.mock.models.activity import MockActivity
from synprov.mock.mocker import ActivityMocker
from synprov.graph.client import GraphClient
Expand All @@ -14,7 +14,6 @@
logging.basicConfig(format='%(asctime)s | %(levelname)s : %(message)s',
level=logging.INFO,
stream=sys.stdout)
graph = Graph(neomod.neo.db.url)
matcher = NodeMatcher(graph)

# ------------------------------
Expand Down
3 changes: 1 addition & 2 deletions synprov/mock/mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from random import randrange, sample
from py2neo import Graph, NodeMatcher

from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.mock.models.activity import MockActivity
from synprov.mock.models.agent import MockAgent
from synprov.mock.models.reference import MockReference
Expand All @@ -12,7 +12,6 @@


logger = logging.getLogger(__name__)
graph = Graph(neomod.neo.db.url)
matcher = NodeMatcher(graph)


Expand Down
3 changes: 1 addition & 2 deletions synprov/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from py2neo import Graph

from synprov import create_app
from synprov.config import neomod
from synprov.config import neo4j_connection as graph
from synprov.graph.client import GraphClient
from synprov.mock.main import create_mock_graph

Expand All @@ -26,7 +26,6 @@ def client():
@pytest.fixture(scope='function')
def mock_graph():
logger.info("setup: initializing graph database")
graph = Graph(neomod.neo.db.url)
yield graph

logger.info("teardown: deleting graph database records")
Expand Down

0 comments on commit 6084742

Please sign in to comment.