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

Fix test failures due to presence of local config #357

Merged
merged 2 commits into from
Oct 10, 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
33 changes: 13 additions & 20 deletions src/reader/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,27 @@ def wrapper(*args, **kwargs):

def config_option(*args, **kwargs):
def callback(ctx, param, value):
# TODO: the default file is allowed to not exist, a user specified file must exist
config_path = value if value is not None else get_default_config_path()
try:
with open(value) as file:
with open(config_path) as file:
config = make_reader_config(yaml.safe_load(file))
except FileNotFoundError as e:
if value != param.default:
raise click.BadParameter(str(e), ctx=ctx, param=param) from None
except FileNotFoundError:
assert value is None
config = make_reader_config({})

ctx.default_map = config['cli'].get('defaults', {})

ctx.obj = config
return config

def inner(fn):
return click.option(
*args,
type=click.Path(dir_okay=False),
callback=callback,
is_eager=True,
expose_value=False,
**kwargs,
)(fn)

return inner
return click.option(
*args,
type=click.Path(exists=True, dir_okay=False),
callback=callback,
is_eager=True,
expose_value=False,
**kwargs,
)


def pass_reader(fn):
Expand All @@ -166,7 +162,6 @@ def wrapper(*args, **kwargs):
'--db',
type=click.Path(dir_okay=False),
envvar=reader._DB_ENVVAR,
show_default=True,
help=f"Path to the reader database. [default: {get_default_db_path()}]",
)
@click.option(
Expand All @@ -184,9 +179,7 @@ def wrapper(*args, **kwargs):
@config_option(
'--config',
envvar=reader._CONFIG_ENVVAR,
help="Path to the reader config.",
default=get_default_config_path(),
show_default=True,
help=f"Path to the reader config. [default: {get_default_config_path()}]",
)
@click.option(
'--feed-root',
Expand Down
1 change: 1 addition & 0 deletions tests/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from click.testing import CliRunner

from reader import make_reader
from test_cli import patch_app_dir
from test_reader_filter import setup_reader_for_tags


Expand Down