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

Show config message only in debug mode in CLI #1140

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Not yet released
^^^^^^^^^^^^^^^^
**release date:** TBA

* [CLI] show the message about the config file only with the ``--debug`` option.
* Relax the ``platformdirs`` dependency requirement to ``>= 3``

2.2.0
Expand Down
13 changes: 9 additions & 4 deletions subliminal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,18 @@ def convert(self, value: str, param: click.Parameter | None, ctx: click.Context
def configure(ctx: click.Context, param: click.Parameter | None, filename: str | os.PathLike) -> None:
"""Read a configuration file."""
filename = pathlib.Path(filename).expanduser()
msg = ''
toml_dict = {}
if filename.is_file():
try:
with open(filename, 'rb') as f:
toml_dict = tomli.load(f)
except tomli.TOMLDecodeError:
msg = f'Cannot read the configuration file at {filename}'
click.echo(msg)
else:
msg = f'Using configuration file at {filename}'
click.echo(msg)
else:
msg = 'Not using any configuration file.'
click.echo(msg)

options = {}

Expand All @@ -148,7 +146,11 @@ def configure(ctx: click.Context, param: click.Parameter | None, filename: str |
providers_dict = toml_dict.setdefault('provider', {})
refiners_dict = toml_dict.setdefault('refiner', {})

ctx.obj = {'provider_configs': providers_dict, 'refiner_configs': refiners_dict}
ctx.obj = {
'__config__': {'dict': toml_dict, 'debug_message': msg},
'provider_configs': providers_dict,
'refiner_configs': refiners_dict,
}
ctx.default_map = options


Expand Down Expand Up @@ -254,6 +256,9 @@ def subliminal(
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
logging.getLogger('subliminal').addHandler(handler)
logging.getLogger('subliminal').setLevel(logging.DEBUG)
# log about the config file
msg = ctx.obj['__config__']['debug_message']
logger.info(msg)

ctx.obj['debug'] = debug
# provider configs
Expand Down
Loading