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

Sort engine entries in searx/settings.yml alphabetically by name #3317

Open
thunder-coding opened this issue Mar 10, 2024 · 5 comments
Open

Comments

@thunder-coding
Copy link
Contributor

Currently this is a giant mess, which makes it really difficult to decide where a new engine should go. Sorting it by name can help improve it.

@return42
Copy link
Member

May we should isolate them in a separated file engines.yml .. and switch to less error-prone engines.toml / The yaml document from hell

@unixfox
Copy link
Member

unixfox commented Mar 10, 2024

OK at first to sort the subentries of each section.

Not the order of each section because some of these are purposefully placed at the top of the file for a reason.


May we should isolate them in a separated file engines.yml .. and switch to less error-prone engines.toml / The yaml document from hell

We could do like the helm tool, allow to specify the configuration in the yaml files that you want.

This way we keep the backwards compatibility but allow for more organized yaml files: https://stackoverflow.com/questions/51097553/can-i-have-multiple-values-yaml-files-for-helm

I do not agree on moving to an entirely new format though. YAML is fine for our usecase and I'm more towards not breaking existing installations.

@dalf
Copy link
Member

dalf commented Mar 10, 2024

I do not agree on moving to an entirely new format though. YAML is fine for our usecase and I'm more towards not breaking existing installations.

👍

@thunder-coding
Copy link
Contributor Author

Not the order of each section because some of these are purposefully placed at the top of the file for a reason.

I specifically wanted to draw attention towards unsorted engines. Unsorted other options are fine and should continue to be as is so that commonly used options are easy to discover. I'm modifying my issue title to reflect the same

@thunder-coding thunder-coding changed the title Sort entries in searx/settings.yml alphabetically by name Sort engine entries in searx/settings.yml alphabetically by name Mar 10, 2024
@dalf
Copy link
Member

dalf commented Mar 10, 2024

pip install ruamel.yaml

from ruamel.yaml import YAML


def parse(settings):
    settings["engines"].sort(key=lambda e: e["name"])


def main():
    yaml=YAML()
    with open("searx/settings.yml", 'r', encoding='utf-8') as f:
        settings = yaml.load(f)
    parse(settings)
    with open("settings_new.yml", "w", encoding="utf-8") as f:
        yaml.dump(settings, f)


if __name__ == "__main__":
    main()

result:
https://gist.github.com/dalf/4ccd6bfb74678f2aa7b01d96dc44400f

It does not sort the commented engines

ping @thunder-coding @return42 @unixfox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants