Skip to content

Commit

Permalink
Merge pull request #21 from trilogy-data/trilogy-refactor
Browse files Browse the repository at this point in the history
Trilogy refactor
  • Loading branch information
greenmtnboy authored Jul 27, 2024
2 parents e714aaf + 269213e commit 915d8df
Show file tree
Hide file tree
Showing 23 changed files with 473 additions and 474 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@


## Trilogy/PreQL Studio
## Trilog Studio

The Trilogy desktop editor. Develop and query in PreQL or SQL languages in a modern, expressive editor.
The Trilogy desktop editor. Develop and query in Trilogy or SQL languages in a modern, expressive editor.

![UI Preview](https://github.com/preqldata/preql-studio/blob/main/media/ui-example.png)

Expand Down
3 changes: 0 additions & 3 deletions backend/extra-hooks/hook-preql_nlp.py

This file was deleted.

3 changes: 3 additions & 0 deletions backend/extra-hooks/hook-trilogy_nlp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from PyInstaller.utils.hooks import get_package_paths

datas = [(get_package_paths("trilogy_nlp")[1], "trilogy_nlp")]
6 changes: 3 additions & 3 deletions backend/io_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List, Optional, Dict, Tuple

from preql.core.models import DataType, Purpose, ListType, MapType, StructType
from trilogy.core.models import DataType, Purpose, ListType, MapType, StructType
from pydantic import BaseModel, Field
from preql_nlp.enums import Provider
from preql import Dialects
from trilogy_nlp.enums import Provider
from trilogy import Dialects
from datetime import datetime


Expand Down
32 changes: 18 additions & 14 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from google.auth import default
from google.cloud import bigquery
from google.oauth2 import service_account
from preql.constants import DEFAULT_NAMESPACE
from preql.core.enums import Purpose
from preql.core.models import (
from trilogy.constants import DEFAULT_NAMESPACE
from trilogy.core.enums import Purpose
from trilogy.core.models import (
ProcessedQuery,
ProcessedQueryPersist,
ProcessedShowStatement,
Expand All @@ -38,12 +38,11 @@
PersistStatement,
DataType,
)
from preql import Environment, Executor, Dialects
from preql.parser import parse_text
from trilogy import Environment, Executor, Dialects
from trilogy.parser import parse_text
from starlette.background import BackgroundTask
from trilogy_public_models import models as public_models
from trilogy_public_models.inventory import parse_initial_models
from preql.parsing.render import render_query, Renderer
from trilogy.parsing.render import render_query, Renderer
from sqlalchemy import create_engine
from backend.io_models import (
ListModelResponse,
Expand All @@ -65,8 +64,9 @@

from sqlalchemy_bigquery.base import BigQueryDialect
from duckdb_engine import Dialect as DuckDBDialect
from preql.executor import generate_result_set
from preql_nlp.core import NLPEngine
from trilogy.executor import generate_result_set
from trilogy_nlp.core import NLPEngine
from trilogy.core.models import LazyEnvironment
from logging import getLogger
import click
from click_default_group import DefaultGroup
Expand Down Expand Up @@ -102,11 +102,15 @@ def load_pyinstaller_trilogy_files() -> None:

test = Path(search_path)

for item in test.glob("**/*preql"):
if item.name == "entrypoint.preql":
for item in test.glob("**/*trilogy"):
if item.name == "entrypoint.trilogy":
relative = item.parent.relative_to(test)
model = parse_initial_models(str(item))
public_models[str(relative).replace("/", ".")] = model
label = str(relative).replace("/", ".")
if label in public_models:
continue
public_models[label] = LazyEnvironment(
load_path=Path(item), working_path=Path(test.parent)
)


load_pyinstaller_trilogy_files()
Expand Down Expand Up @@ -378,7 +382,7 @@ def run_raw_query(query: QueryInSchema):

@router.post("/gen_ai_query")
def run_genai_query(query: GenAIQueryInSchema):
from preql_nlp.main import parse_query
from trilogy_nlp.main import parse_query

datetime.now()
executor = CONNECTIONS.get(query.connection)
Expand Down
6 changes: 3 additions & 3 deletions backend/models/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, List, Union

from preql.core.models import (
from trilogy.core.models import (
AggregateWrapper,
Comparison,
Concept,
Expand All @@ -17,8 +17,8 @@
)

from backend.io_models import LineageItem, Model, UIConcept
from preql.constants import DEFAULT_NAMESPACE
from preql.parsing.render import Renderer
from trilogy.constants import DEFAULT_NAMESPACE
from trilogy.parsing.render import Renderer


def flatten_array(input: Any, depth: int = 0) -> List[LineageItem]:
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.ruff]
line-length = 100

ignore = ["E402", "F403"]
lint.ignore = ["E402", "F403"]

[tool.mypy]
ignore_missing_imports = true
Binary file modified backend/requirements-lock.txt
Binary file not shown.
Binary file modified backend/requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/scripts/hit_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import requests
from backend.io_models import ConnectionInSchema, QueryInSchema
from preql import Dialects
from trilogy import Dialects

if __name__ == "__main__":
response = requests.post(
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..io_models import ModelSourceInSchema, GenAIConnectionInSchema
from typing import List, Mapping
from trilogy_public_models import models as public_models
from preql_nlp import Provider
from trilogy_nlp import Provider


def test_read_main(test_client: TestClient):
Expand Down
29 changes: 20 additions & 9 deletions backend/trilogy-studio-engine.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PyInstaller.utils.hooks import collect_all
import trilogy_public_models
import sys
import preql_nlp
import trilogy_nlp
from pathlib import Path
from logging import getLogger

Expand All @@ -26,24 +26,35 @@ def get_trilogy_data_files():
inclusion_files.append(( str(f), str(subroot)))
return inclusion_files

def get_preql_nlp_template_files():
root = sys.modules.get(f'preql_nlp')
def get_trilogy_nlp_template_files():
root = sys.modules.get(f'trilogy_nlp')
root = Path(root.__file__).parent

inclusion_files = []
for f in (root / 'prompts').iterdir():
if f.suffix == '.jinja2':
subroot = Path('preql_nlp') / 'prompts'
subroot = Path('trilogy_nlp') / 'prompts'
inclusion_files.append(( str(f), str(subroot)))
return inclusion_files


def get_trilogy_lark_file():
root = sys.modules.get(f'trilogy')
root = Path(root.__file__).parent

inclusion_files = []
for f in (root / 'parsing').iterdir():
if f.suffix == '.lark':
subroot = Path('trilogy') / 'parsing'
inclusion_files.append(( str(f), str(subroot)))
return inclusion_files


datas = get_trilogy_data_files() + get_preql_nlp_template_files()
datas = get_trilogy_data_files() + get_trilogy_nlp_template_files() + get_trilogy_lark_file()

#logger.info('Processing manual data files listed below')
#for data in datas:
# logger.info(data)
logger.info('Processing manual data files listed below')
for data in datas:
logger.info(data)
binaries = []
hiddenimports = ['sqlalchemy_bigquery']
tmp_ret = collect_all('uvicorn')
Expand All @@ -54,7 +65,7 @@ tmp_ret = collect_all('duckdb-engine')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('sqlalchemy')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('preql_nlp')
tmp_ret = collect_all('trilogy_nlp')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('langchain_community')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
Expand Down
9 changes: 0 additions & 9 deletions frontend/e2e/example.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/preql.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PreQL Studio</title>
<title>Trilogy Studio</title>
</head>
<script>var exports = {};</script>
<body>
Expand Down
Loading

0 comments on commit 915d8df

Please sign in to comment.