easybuilders / easybuild-easyconfigs

A collection of easyconfig files that describe which software to build using which build options with EasyBuild.
https://easybuild.io
GNU General Public License v2.0
360 stars 690 forks source link

Automate updating of Perl modules (almost example script included) #18164

Open Micket opened 1 year ago

Micket commented 1 year ago

A while back i found a way to automate updating of perl modules by fetching metadata from Perl.

#/usr/bin/env python3

import requests

def latest_cpan_extension(module):
    data = requests.get('https://fastapi.metacpan.org/v1/module/' + module).json()
    version = data['version']
    url = data['download_url']
    source_url, filename = url.rsplit('/', maxsplit=1)
    source_tmpl = filename.replace(version, '%(version)s')
    return (module, version, {'source_tmpl': source_tmpl, 'source_urls': [source_url]})

extensions = ['Config::General', 'Test::Harness']  # TODO: take this from easyconfig file somehow
new_extensions = []
for module in extensions:
    new_extensions.append(latest_cpan_extension(module))

import json
print(json.dumps(new_extensions, indent=4))

needs to be cleaned up a bit, and added somewhere for convenient access. Presumably the perl bundle easyblock. I didn't have time to do it, and just manually copied in all the extensions myself.

Micket commented 2 weeks ago

Improved my script a bit

#!/usr/bin/env python3

import sys
import requests
from easybuild.framework.easyconfig.parser import EasyConfigParser

def latest_cpan_extension(module):
    data = requests.get('https://fastapi.metacpan.org/v1/module/' + module).json()
    version = data['version']
    url = data['download_url']
    source_url, filename = url.rsplit('/', maxsplit=1)
    source_tmpl = filename.replace(version, '%(version)s')
    return (module, version, {'source_tmpl': source_tmpl, 'source_urls': [source_url]})

ec = EasyConfigParser(sys.argv[1])
ecdict = ec.get_config_dict(validate=False)

extensions = ecdict['exts_list']
new_extensions = []
print('exts_list = [')
for module in extensions:
    opts = module[2]
    new_mod, version, new_opts = latest_cpan_extension(module[0])
    print(f"    ('{new_mod}', '{version}', {{")
    opts.update(new_opts)
    for x, y in opts.items():
        print(f'        {repr(x)}: {repr(y)},')
    print('    }),')

print(']')