Skip to content

Commit

Permalink
updated pr to new deepsearch ver
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Brandão <[email protected]>
  • Loading branch information
HolyMichael committed Jul 25, 2023
1 parent c8b8381 commit 91024ef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
38 changes: 15 additions & 23 deletions deepsearch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,25 @@
from pathlib import Path
from typing import List

from deepsearch import DeepSearchConfig
from deepsearch.artifacts.cli.main import app as artifacts_app
from deepsearch.core.cli.main import app
from deepsearch.core.cli.plugins import get_cli_groups
from deepsearch.core.util.config_paths import config_file_path
from deepsearch.cps.cli.main import app as cps_app
from deepsearch.documents.cli.main import app as documents_app
from deepsearch.query.cli.main import app as query_app

# TODO review if unwanted information is being logged
from deepsearch.core.client.settings_manager import settings_mgr


def setup_logger():
# Setting up root logger
config_file = config_file_path()

if not config_file.exists():
raise RuntimeError(
f"Config file {config_file} does not exist. Please configure your default authentication with `$ deepsearch login`"
)
config = DeepSearchConfig.parse_file(config_file)
active_profile_settings = settings_mgr.get_profile_settings(
settings_mgr.get_active_profile()
)

p = Path(config.log_configuration.target_file)
p = Path(active_profile_settings.log_target_file)
if not p.parent.is_dir():
p.parent.mkdir(parents=True)

p = p.joinpath("deepsearch.log")

handlers: List[logging.Handler] = [
logging.FileHandler(p),
]
if config.log_configuration.write_to_console:
if active_profile_settings.log_to_console:
handlers.append(logging.StreamHandler())
formatter = logging.Formatter(
"%(asctime)s %(name)s — %(levelname)s — %(module)s:%(funcName)s:%(lineno)d — %(message)s"
Expand All @@ -46,18 +35,21 @@ def setup_logger():

logger = setup_logger()

from deepsearch.artifacts.cli.main import app as artifacts_app
from deepsearch.core.cli.main import app
from deepsearch.core.cli.plugins import get_cli_groups
from deepsearch.cps.cli.main import app as cps_app
from deepsearch.documents.cli.main import app as documents_app
from deepsearch.query.cli.main import app as query_app

app.add_typer(cps_app, name="cps", help="Interact with DeepSearch CPS component")
logger.info("Cps module initialized")
app.add_typer(query_app, name="query", help="Interact with DeepSearch Query component")
logger.info("Query module initialized")
app.add_typer(
documents_app,
name="documents",
help="Interact with DeepSearch Document Conversion component",
)
logger.info("Documents module initialized")
app.add_typer(artifacts_app, name="artifacts", help="Manage artifacts")
logger.info("Artifacts module initialized")

for group in get_cli_groups():
app.add_typer(group)
Expand Down
7 changes: 7 additions & 0 deletions deepsearch/core/cli/profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

import platformdirs
import typer
from rich.console import Console
from rich.table import Table
Expand Down Expand Up @@ -29,6 +30,10 @@ def add_profile(
username: str = typer.Option(prompt=True),
api_key: str = typer.Option(prompt=True, hide_input=True),
verify_ssl: bool = typer.Option(default=True),
log_directory: str = typer.Option(
prompt=True, default=platformdirs.user_log_dir("DeepSearch", "IBM")
),
log_to_console: bool = typer.Option(default=False),
profile_name: str = typer.Option(
default="",
help="If not set, the active profile will be updated or, if no profile available, a new profile with a predetermined name will be created.",
Expand All @@ -44,6 +49,8 @@ def add_profile(
username=username,
api_key=api_key,
verify_ssl=verify_ssl,
log_target_file=log_directory,
log_to_console=log_to_console,
)

settings_mgr.save_settings(
Expand Down
5 changes: 5 additions & 0 deletions deepsearch/core/client/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Dict, Optional, Union

import platformdirs
from pydantic import BaseSettings, SecretStr


Expand Down Expand Up @@ -38,6 +39,8 @@ class ProfileSettings(DumpableSettings):
username: str
api_key: SecretStr
verify_ssl: bool = True
log_target_file: str
log_to_console: bool

class Config:
env_prefix = "DEEPSEARCH_"
Expand All @@ -49,6 +52,8 @@ def from_cli_prompt(cls) -> ProfileSettings:
username=input("Username: "),
api_key=getpass("API key: "),
verify_ssl=input("SSL verification [y/n]: "),
log_directory=input("Log directory: "),
log_to_console=input("log_to_console [y/n]: "),
)


Expand Down
2 changes: 2 additions & 0 deletions deepsearch/core/client/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def _migrate_legacy_config(self) -> None:
username=legacy_cfg.auth.username,
api_key=legacy_cfg.auth.api_key,
verify_ssl=legacy_cfg.verify_ssl,
log_directory=platformdirs.user_log_dir("DeepSearch", "IBM"),
log_to_console=False,
)
self.save_settings(
profile_settgs=new_cfg,
Expand Down
1 change: 1 addition & 0 deletions deepsearch/cps/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

logger = logging.getLogger("root.cps")
print(logger.handlers)

import typer

Expand Down

0 comments on commit 91024ef

Please sign in to comment.