Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Sep 18, 2023
1 parent 09831ca commit fc7dbe0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ def __init__(
]
if config_dir and metadata_files and not metadata:
with metadata_files[0].open() as fp:
metadata = fail_if_plugins_in_metadata(parse_metadata(fp.read()), metadata_files[0].name)
metadata = fail_if_plugins_in_metadata(
parse_metadata(fp.read()), metadata_files[0].name
)

if config_dir and config_files and not config:
with config_files[0].open() as fp:
Expand Down
2 changes: 1 addition & 1 deletion datasette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def serve(

metadata_data = None
if metadata:
metadata_data = fail_if_plugins_in_metadata(parse_metadata(metadata.read()), metadata.name)
metadata_data = fail_if_plugins_in_metadata(parse_metadata(metadata.read()))

config_data = None
if config:
Expand Down
16 changes: 12 additions & 4 deletions datasette/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,17 @@ def pairs_to_nested_config(pairs: typing.List[typing.Tuple[str, typing.Any]]) ->
result = _combine(result, parsed_pair)
return result

def fail_if_plugins_in_metadata(metadata:dict, filename=None):
""" If plugin config is inside metadata, raise an Exception """

def fail_if_plugins_in_metadata(metadata: dict, filename=None):
"""If plugin config is inside metadata, raise an Exception"""
if metadata is not None and metadata.get("plugins") is not None:
suggested_extension = ".yaml" if filename is not None and (filename.endswith(".yaml") or filename.endswith(".yml")) else ".json"
raise Exception(f'Datasette no longer accepts plugin configuration in --metadata. Move your "plugins" configuration blocks to a separate file - we suggest calling that datasette.{suggested_extension} - and start Datasette with datasette -c datasette.{suggested_extension}. See https://docs.datasette.io/en/latest/configuration.html for more details.')
suggested_extension = (
".yaml"
if filename is not None
and (filename.endswith(".yaml") or filename.endswith(".yml"))
else ".json"
)
raise Exception(
f'Datasette no longer accepts plugin configuration in --metadata. Move your "plugins" configuration blocks to a separate file - we suggest calling that datasette.{suggested_extension} - and start Datasette with datasette -c datasette.{suggested_extension}. See https://docs.datasette.io/en/latest/configuration.html for more details.'
)
return metadata

0 comments on commit fc7dbe0

Please sign in to comment.