aiidateam / aiida-registry

Find plugins for AiiDA
http://aiidateam.github.io/aiida-registry
Other
16 stars 66 forks source link

Fix on plug-ins who moved from `setup.json` to `pyproject.toml` but haven't updated aiida-registry about this #309

Closed khsrali closed 8 months ago

khsrali commented 8 months ago

Regrading issue raised by @giovannipizzi of appearing W002 for functioning plug-ins.

There are 26 packages that moved from setup.json to pyproject.toml but haven't updated aiida-registry about this. Currently, 9 of these packages cause W002 to appear on aiida-registry webpage. With this commit, errors caused for this reason should disappear.

Note for future: we (I and @unkcpz) think it's better to have an automated action such, if it doesn't find the info in the plugin_info url, looks for other possibilities, like pyproject.toml, setup.cfg, etc. and once found it could fire a PR for that. If not, drop an email to the responsible plug-in developers about this.

unkcpz commented 8 months ago

@khsrali thanks! How do you make the change? If the changes are made automatically by script, you can easily convert it to a GHA as such: https://github.com/unkcpz/aiida-core-i18n/blob/cf54fcdef9dc8cb6ac04308dcb704f1f00e12b5c/.github/workflows/ci-update-pot.yml#L46-L55

I am looking forward to see the problem is solved once for all and don't need to maintain for long time in the future.

github-actions[bot] commented 8 months ago

PR Preview Action v1.4.7 :---: :rocket: Deployed preview to https://aiidateam.github.io/aiida-registry/pr-preview/pr-309/ on branch gh-pages at 2024-03-20 12:55 UTC

khsrali commented 8 months ago

Thanks @unkcpz for sharing the link! I think it's very useful. yes with a script, I'll follow to make a GHA, on that.

Anyways, for a quick check on deployed preview, here is the list of 9 plug-ins with appearing W002: aiida-ddec aiida-flexpart aiida-environ aiida-lammps aiida-nanotech-empa aiida-nims-scheduler aiida-yascheduler aiida-z2pack aiida-fenics

khsrali commented 8 months ago

Hi @unkcpz , ok updated, when converting to GHA, we don't need that uglyKEYcheck anymore. so i don't bring it here.

import yaml
import requests
from uglyKEYcheck import search_in_url

maindomain = "https://aiidateam.github.io/aiida-registry/"

def load_yaml_file(file_path):
    with open(file_path, 'r') as file:
        return yaml.safe_load(file)

def save_yaml_file(file_path, data):
    with open(file_path, 'w') as file:
        yaml.safe_dump(data, file, sort_keys=False)

def check_if_toml(url):
    new_url = '/'.join(url.split('/')[:-1]) + '/pyproject.toml'
    response = requests.head(new_url, timeout=10)
    if response.status_code == 404:
        return None
    else:
        return new_url

def check_urls(data):
    updates = False
    for plugin, info in data.items():
        url = info.get("plugin_info")
        if url:
            try:
                response = requests.get(url, allow_redirects=True)
                if response.status_code == 404:
                    new_url = check_if_toml(url)
                    if new_url:
                        print(f"{plugin}: returned a 404 status. But *pyproject.toml* detected!")
                        if search_in_url(maindomain+plugin, 'W002'):
                            data[plugin]["plugin_info"] = new_url
                            updates = True
                            print(plugin, ' updated')
                    else:
                        print(f"{plugin}: returned a 404 status. No *pyproject.toml* detected.")
                else:
                    pass
            except requests.RequestException as e:
                print(f"Error checking {plugin}: {url}. Error: {e}")
    return updates

yaml_file_path = 'plugins.yaml'

data = load_yaml_file(yaml_file_path)
if check_urls(data):
    save_yaml_file('plugins-out.yaml', data)
    print("YAML file updated.")
khsrali commented 8 months ago

Thanks @unkcpz for your quick & nice review