-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbootstrap.py
More file actions
116 lines (99 loc) · 3.65 KB
/
bootstrap.py
File metadata and controls
116 lines (99 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import dataclasses
import logging
from testgen import settings
from testgen.commands.run_upgrade_db_config import get_schema_revision
from testgen.common import configure_logging, version_service
from testgen.ui.navigation.menu import Menu, Version
from testgen.ui.navigation.page import Page
from testgen.ui.navigation.router import Router
from testgen.ui.session import session
from testgen.ui.views.connections import ConnectionsPage
from testgen.ui.views.data_catalog import DataCatalogPage
from testgen.ui.views.hygiene_issues import HygieneIssuesPage
from testgen.ui.views.login import LoginPage
from testgen.ui.views.profiling_results import ProfilingResultsPage
from testgen.ui.views.profiling_runs import DataProfilingPage
from testgen.ui.views.project_dashboard import ProjectDashboardPage
from testgen.ui.views.project_settings import ProjectSettingsPage
from testgen.ui.views.quality_dashboard import QualityDashboardPage
from testgen.ui.views.score_details import ScoreDetailsPage
from testgen.ui.views.score_explorer import ScoreExplorerPage
from testgen.ui.views.table_groups import TableGroupsPage
from testgen.ui.views.test_definitions import TestDefinitionsPage
from testgen.ui.views.test_results import TestResultsPage
from testgen.ui.views.test_runs import TestRunsPage
from testgen.ui.views.test_suites import TestSuitesPage
from testgen.utils import plugins, singleton
BUILTIN_PAGES: list[type[Page]] = [
LoginPage,
ProjectDashboardPage,
QualityDashboardPage,
ScoreDetailsPage,
ScoreExplorerPage,
DataCatalogPage,
DataProfilingPage,
ProfilingResultsPage,
HygieneIssuesPage,
TestRunsPage,
TestResultsPage,
ConnectionsPage,
TableGroupsPage,
TestSuitesPage,
TestDefinitionsPage,
ProjectSettingsPage,
]
LOG = logging.getLogger("testgen")
class Application(singleton.Singleton):
def __init__(self, logo: plugins.Logo, router: Router, menu: Menu, logger: logging.Logger) -> None:
self.logo = logo
self.router = router
self.menu = menu
self.logger = logger
def get_version(self) -> Version:
latest_version = self.menu.version.latest
if not session.latest_version:
latest_version = version_service.get_latest_version()
return Version(
current=settings.VERSION,
latest=latest_version,
schema=get_schema_revision(),
)
def run(log_level: int = logging.INFO) -> Application:
pages = [*BUILTIN_PAGES]
installed_plugins = plugins.discover()
if not settings.IS_DEBUG:
"""
This cleanup is called so that TestGen can remove uninstalled
plugins without having to be reinstalled.
The check for DEBUG mode is because multithreading for Streamlit
fragments loads before the plugins can be re-loaded.
"""
plugins.cleanup()
configure_logging(level=log_level)
logo_class = plugins.Logo
for plugin in installed_plugins:
spec = plugin.load()
if spec.page:
pages.append(spec.page)
if spec.logo:
logo_class = spec.logo
if spec.component:
spec.component.provide()
return Application(
logo=logo_class(),
router=Router(routes=pages),
menu=Menu(
items=list(
{
page.path: dataclasses.replace(page.menu_item, page=page.path)
for page in pages if page.menu_item
}.values()
),
version=Version(
current=settings.VERSION,
latest="...",
schema=get_schema_revision(),
),
),
logger=LOG,
)