Skip to content

Commit

Permalink
Display pebblo version (daxa-ai#426)
Browse files Browse the repository at this point in the history
* Display pebblo version

Find pebblo pkg version and display during
server startup.

Add CLI arg "--version" / "-v" to just display
version and exit

* lint fixes
  • Loading branch information
srics authored Jul 24, 2024
1 parent 33ea743 commit 9c48eb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pebblo/app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 18 additions & 4 deletions pebblo/app/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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!")

Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions pebblo/app/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from importlib.metadata import PackageNotFoundError, version


def get_pebblo_version():
try:
ver = version("pebblo")
except PackageNotFoundError:
ver = "unknown"
return ver

0 comments on commit 9c48eb5

Please sign in to comment.