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

Refactor module loading v2: move writing of module_config.bin to bootstrap #425

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion backend/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
4CAT Backend init - used to start the backend!
"""
import pickle
import shutil
import os

Expand All @@ -10,7 +11,6 @@
from common.lib.database import Database
from backend.lib.manager import WorkerManager
from common.lib.logger import Logger

from common.config_manager import config

def run(as_daemon=True):
Expand Down Expand Up @@ -66,6 +66,16 @@ def run(as_daemon=True):
config.with_db(db)
config.ensure_database()

# Load all modules and update config with module-specific settings
from backend import all_modules
module_config = {}
for worker in all_modules.workers.values():
if hasattr(worker, "config") and type(worker.config) is dict:
module_config.update(worker.config)
with config.get("PATH_ROOT").joinpath("config/module_config.bin").open("wb") as outfile:
pickle.dump(module_config, outfile)
config.load_user_settings()

# make it happen
# this is blocking until the back-end is shut down
WorkerManager(logger=log, database=db, queue=queue, as_daemon=as_daemon)
Expand Down
8 changes: 3 additions & 5 deletions common/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
import pickle
import time
import json

import configparser
import os
from pathlib import Path
from common.lib.database import Database

from common.lib.database import Database
from common.lib.exceptions import ConfigException
from common.lib.config_definition import config_definition
from common.lib.user_input import UserInput

import configparser
import os


class ConfigManager:
db = None
Expand Down
13 changes: 0 additions & 13 deletions common/lib/module_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pathlib import Path
import importlib
import inspect
import pickle
import sys
import re

Expand Down Expand Up @@ -52,18 +51,6 @@ def __init__(self):
# datasources, e.g. whether they have an associated search worker
self.expand_datasources()

# cache module-defined config options for use by the config manager
module_config = {}
for worker in self.workers.values():
if hasattr(worker, "config") and type(worker.config) is dict:
module_config.update(worker.config)

with config.get("PATH_ROOT").joinpath("config/module_config.bin").open("wb") as outfile:
pickle.dump(module_config, outfile)

# load from cache
config.load_user_settings()

@staticmethod
def is_4cat_class(object, only_processors=False):
"""
Expand Down
Loading