Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update monorepo setup #288

Merged
merged 12 commits into from
Nov 27, 2023
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This Dockerfile is used to setup an image for code linting (namely config files)
FROM node:lts
eric-nguyen-cs marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /code
Expand Down
12 changes: 8 additions & 4 deletions backend/sample/dump.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ def get_options(args=None):
return parser.parse_args(args)


if __name__ == "__main__":
options = get_options()
session = get_session(options.url)
with open(options.file, "w") as f:
def dump_db(file_path, url=DEFAULT_URL):
session = get_session(url)
with open(file_path, "w") as f:
f.write('{"nodes": [')
dump_nodes(session, f)
f.write('], "relations": [')
dump_relations(session, f)
f.write("]}")


if __name__ == "__main__":
options = get_options()
dump_db(file_path=options.file, url=options.url)
45 changes: 36 additions & 9 deletions backend/sample/load.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from neo4j import GraphDatabase

DEFAULT_URL = os.environ.get("NEO4J_URI", "bolt://localhost:7687")
DEFAULT_LOAD_DB_ARGS = {
"url": DEFAULT_URL,
"reset_db": False,
"confirm_reset_db": False,
}


def get_session(uri=DEFAULT_URL):
Expand Down Expand Up @@ -58,13 +63,21 @@ def load_jsonl(file_path, session):

def get_options(args=None):
parser = argparse.ArgumentParser(description="Import json file to Neo4J database")
parser.add_argument("--url", default=DEFAULT_URL, help="Neo4J database bolt URL")
parser.add_argument(
"--url", default=DEFAULT_LOAD_DB_ARGS["url"], help="Neo4J database bolt URL"
)
parser.add_argument("file", help="Json file to import")
parser.add_argument(
"--reset", default=False, action="store_true", help="Clean all database before importing"
"--reset",
default=DEFAULT_LOAD_DB_ARGS["reset_db"],
action="store_true",
help="Clean all database before importing",
)
parser.add_argument(
"--yes", default=False, action="store_true", help="Assume yes to all questions"
"--yes",
default=DEFAULT_LOAD_DB_ARGS["confirm_reset_db"],
action="store_true",
help="Assume yes to all questions",
)
return parser.parse_args(args)

Expand All @@ -77,13 +90,27 @@ def confirm_clean_db(session):
return response.lower() in ("y", "yes")


if __name__ == "__main__":
options = get_options()
session = get_session(options.url)
if options.reset:
confirmed = options.yes or confirm_clean_db(session)
def load_file(
file_path,
url=DEFAULT_LOAD_DB_ARGS["url"],
reset_db=DEFAULT_LOAD_DB_ARGS["reset_db"],
confirm_reset_db=DEFAULT_LOAD_DB_ARGS["confirm_reset_db"],
):
session = get_session(url)
if reset_db:
confirmed = confirm_reset_db or confirm_clean_db(session)
if not confirmed:
sys.exit(1)
else:
clean_db(session)
load_jsonl(options.file, session)
load_jsonl(file_path, session)


if __name__ == "__main__":
options = get_options()
load_file(
file_path=options.file,
url=options.url,
reset_db=options.reset,
confirm_reset_db=options.yes,
)
8 changes: 5 additions & 3 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import os
import subprocess

import pytest

from sample.dump import dump_db
from sample.load import load_file
eric-nguyen-cs marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(autouse=True)
def test_setup(neo4j):
Expand Down Expand Up @@ -119,11 +121,11 @@ def test_load_and_dump():
test_data_path = "sample/dumped-test-taxonomy.json"

# Run load.py to import data into Neo4j database
subprocess.run(["sample/load.py", test_data_path])
load_file(test_data_path)

# Run dump.py to dump the Neo4j database into a JSON file
dumped_file_path = "sample/dump.json"
subprocess.run(["sample/dump.py", dumped_file_path])
dump_db(dumped_file_path)

try:
# Read the original and dumped JSON files
Expand Down
1 change: 1 addition & 0 deletions docker/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ services:
PROD_UI_SUFFIX: "${PROD_UI_SUFFIX--static}"
DEV_UI_SUFFIX: "${DEV_UI_SUFFIX-}"

# we want to be able to run linting from a container
taxonomy_editor_code:
eric-nguyen-cs marked this conversation as resolved.
Show resolved Hide resolved
image: taxonomy-editor/taxonomy_editor_code:dev
build:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"//": "This file is for global dev tools only ! For frontend see in taxonomy-editor-frontend folder",
"devDependencies": {
eric-nguyen-cs marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "3.0.3",
"prettier-plugin-toml": "^1.0.0"
Expand Down