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

Utility to help with "Datasette no longer accepts plugin configuration in --metadata" #1

Closed
simonw opened this issue Jan 16, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Contributor

simonw commented Jan 16, 2024

The first utility in this class will help plugins that want to work against Datasette before and after this change: simonw/datasette@3d6d1e3

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.'
        )
    return metadata
@simonw simonw added the enhancement New feature or request label Jan 16, 2024
@simonw
Copy link
Contributor Author

simonw commented Jan 16, 2024

I'm going to do this with a custom Datasette subclass:

from datasette_test import Datasette

ds = Datasette(metadata={}, plugin_config={...})

This will change plugin_config into either metadata["plugins"] = ... or config["plugins"] = ... depending on the Datasette version.

It's going to attempt to import datasette.utils.fail_if_plugins_in_metadata to check if it should act or not.

simonw added a commit that referenced this issue Jan 16, 2024
Tests against multiple Datasette versions, refs #1
@simonw
Copy link
Contributor Author

simonw commented Jan 16, 2024

Released as first version, details here:

simonw added a commit that referenced this issue Jan 16, 2024
@simonw simonw closed this as completed in ccf69db Jan 16, 2024
simonw added a commit that referenced this issue Jan 16, 2024
simonw added a commit to simonw/datasette-edit-templates that referenced this issue Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant