Skip to content

Commit 44163bb

Browse files
committed
updated pr to new deepsearch ver
Signed-off-by: Miguel Brandão <[email protected]>
1 parent c5838af commit 44163bb

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

deepsearch/cli.py

+15-23
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,25 @@
22
from pathlib import Path
33
from typing import List
44

5-
from deepsearch import DeepSearchConfig
6-
from deepsearch.artifacts.cli.main import app as artifacts_app
7-
from deepsearch.core.cli.main import app
8-
from deepsearch.core.cli.plugins import get_cli_groups
9-
from deepsearch.core.util.config_paths import config_file_path
10-
from deepsearch.cps.cli.main import app as cps_app
11-
from deepsearch.documents.cli.main import app as documents_app
12-
from deepsearch.query.cli.main import app as query_app
13-
14-
# TODO review if unwanted information is being logged
5+
from deepsearch.core.client.settings_manager import settings_mgr
156

167

178
def setup_logger():
189
# Setting up root logger
19-
config_file = config_file_path()
20-
21-
if not config_file.exists():
22-
raise RuntimeError(
23-
f"Config file {config_file} does not exist. Please configure your default authentication with `$ deepsearch login`"
24-
)
25-
config = DeepSearchConfig.parse_file(config_file)
10+
active_profile_settings = settings_mgr.get_profile_settings(
11+
settings_mgr.get_active_profile()
12+
)
2613

27-
p = Path(config.log_configuration.target_file)
14+
p = Path(active_profile_settings.log_target_file)
2815
if not p.parent.is_dir():
2916
p.parent.mkdir(parents=True)
3017

18+
p = p.joinpath("deepsearch.log")
19+
3120
handlers: List[logging.Handler] = [
3221
logging.FileHandler(p),
3322
]
34-
if config.log_configuration.write_to_console:
23+
if active_profile_settings.log_to_console:
3524
handlers.append(logging.StreamHandler())
3625
formatter = logging.Formatter(
3726
"%(asctime)s %(name)s — %(levelname)s — %(module)s:%(funcName)s:%(lineno)d — %(message)s"
@@ -46,18 +35,21 @@ def setup_logger():
4635

4736
logger = setup_logger()
4837

38+
from deepsearch.artifacts.cli.main import app as artifacts_app
39+
from deepsearch.core.cli.main import app
40+
from deepsearch.core.cli.plugins import get_cli_groups
41+
from deepsearch.cps.cli.main import app as cps_app
42+
from deepsearch.documents.cli.main import app as documents_app
43+
from deepsearch.query.cli.main import app as query_app
44+
4945
app.add_typer(cps_app, name="cps", help="Interact with DeepSearch CPS component")
50-
logger.info("Cps module initialized")
5146
app.add_typer(query_app, name="query", help="Interact with DeepSearch Query component")
52-
logger.info("Query module initialized")
5347
app.add_typer(
5448
documents_app,
5549
name="documents",
5650
help="Interact with DeepSearch Document Conversion component",
5751
)
58-
logger.info("Documents module initialized")
5952
app.add_typer(artifacts_app, name="artifacts", help="Manage artifacts")
60-
logger.info("Artifacts module initialized")
6153

6254
for group in get_cli_groups():
6355
app.add_typer(group)

deepsearch/core/cli/profile.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional
22

3+
import platformdirs
34
import typer
45
from rich.console import Console
56
from rich.table import Table
@@ -29,6 +30,10 @@ def add_profile(
2930
username: str = typer.Option(prompt=True),
3031
api_key: str = typer.Option(prompt=True, hide_input=True),
3132
verify_ssl: bool = typer.Option(default=True),
33+
log_directory: str = typer.Option(
34+
prompt=True, default=platformdirs.user_log_dir("DeepSearch", "IBM")
35+
),
36+
log_to_console: bool = typer.Option(default=False),
3237
profile_name: str = typer.Option(
3338
default="",
3439
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.",
@@ -44,6 +49,8 @@ def add_profile(
4449
username=username,
4550
api_key=api_key,
4651
verify_ssl=verify_ssl,
52+
log_target_file=log_directory,
53+
log_to_console=log_to_console,
4754
)
4855

4956
settings_mgr.save_settings(

deepsearch/core/client/settings.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
from typing import Dict, Optional, Union
66

7+
import platformdirs
78
from pydantic import BaseSettings, SecretStr
89

910

@@ -38,6 +39,8 @@ class ProfileSettings(DumpableSettings):
3839
username: str
3940
api_key: SecretStr
4041
verify_ssl: bool = True
42+
log_target_file: str
43+
log_to_console: bool
4144

4245
class Config:
4346
env_prefix = "DEEPSEARCH_"
@@ -49,6 +52,8 @@ def from_cli_prompt(cls) -> ProfileSettings:
4952
username=input("Username: "),
5053
api_key=getpass("API key: "),
5154
verify_ssl=input("SSL verification [y/n]: "),
55+
log_directory=input("Log directory: "),
56+
log_to_console=input("log_to_console [y/n]: "),
5257
)
5358

5459

deepsearch/core/client/settings_manager.py

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def _migrate_legacy_config(self) -> None:
8686
username=legacy_cfg.auth.username,
8787
api_key=legacy_cfg.auth.api_key,
8888
verify_ssl=legacy_cfg.verify_ssl,
89+
log_directory=platformdirs.user_log_dir("DeepSearch", "IBM"),
90+
log_to_console=False,
8991
)
9092
self.save_settings(
9193
profile_settgs=new_cfg,

deepsearch/cps/cli/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
logger = logging.getLogger("root.cps")
4+
print(logger.handlers)
45

56
import typer
67

0 commit comments

Comments
 (0)