diff --git a/pebblo/app/config/config.py b/pebblo/app/config/config.py index bd8b16e8..5a1d28dc 100644 --- a/pebblo/app/config/config.py +++ b/pebblo/app/config/config.py @@ -33,16 +33,18 @@ class ClassifierConfig(BaseSettings): # ConfigFile BaseModel class Config(BaseSettings): + version: str = Field(default="unknown") daemon: PortConfig reports: ReportConfig logging: LoggingConfig classifier: ClassifierConfig -def load_config(path) -> dict: +def load_config(path, version) -> dict: try: # If Path does not exist in command, set default config value conf_obj = Config( + version=version, daemon=PortConfig(host="localhost", port=8000), reports=ReportConfig( format="pdf", renderer="xhtml2pdf", outputDir="~/.pebblo" diff --git a/pebblo/app/daemon.py b/pebblo/app/daemon.py index 93e26e55..5bf6571f 100644 --- a/pebblo/app/daemon.py +++ b/pebblo/app/daemon.py @@ -8,6 +8,7 @@ from tqdm import tqdm from pebblo.app.config.config import load_config +from pebblo.app.utils.version import get_pebblo_version warnings.filterwarnings("ignore", category=UserWarning) warnings.filterwarnings("ignore", category=DeprecationWarning) @@ -20,12 +21,20 @@ def start(): global config_details # For loading config file details parser = argparse.ArgumentParser(description="Pebblo CLI") - parser.add_argument("--config", type=str, help="config file path") + parser.add_argument("-c", "--config", type=str, help="config file path") + parser.add_argument( + "-v", "--version", action="store_true", help="display the version" + ) args = parser.parse_args() + + version = get_pebblo_version() + if args.version: + print(f"Pebblo Server version: {version}") + exit(0) + path = args.config p_bar = tqdm(range(10)) - config_details = load_config(path) - classifier_init(p_bar) + config_details = load_config(path, version) server_start(config_details, p_bar) print("Pebblo server Stopped. BYE!") @@ -56,7 +65,12 @@ def classifier_init(p_bar): def server_start(config: dict, p_bar: tqdm): """Start server.""" - p_bar.write("Pebblo server starting ...") + version = config.get("version", "unknown") + p_bar.write(f"Pebblo server version {version} starting ...") + + # Initialize Topic and Entity Classifier + classifier_init(p_bar) + # Starting Uvicorn Service Using config details from pebblo.app.config.service import Service diff --git a/pebblo/app/utils/version.py b/pebblo/app/utils/version.py new file mode 100644 index 00000000..2b81cae3 --- /dev/null +++ b/pebblo/app/utils/version.py @@ -0,0 +1,9 @@ +from importlib.metadata import PackageNotFoundError, version + + +def get_pebblo_version(): + try: + ver = version("pebblo") + except PackageNotFoundError: + ver = "unknown" + return ver