diff --git a/easybuild/tools/docs.py b/easybuild/tools/docs.py index 4f4bfca99c..84666a6e10 100644 --- a/easybuild/tools/docs.py +++ b/easybuild/tools/docs.py @@ -39,6 +39,7 @@ import copy import inspect import os +import json from easybuild.tools import LooseVersion from easybuild.base import fancylogger @@ -75,6 +76,7 @@ FORMAT_MD = 'md' FORMAT_RST = 'rst' FORMAT_TXT = 'txt' +FORMAT_JSON = 'json' def generate_doc(name, params): @@ -1024,6 +1026,34 @@ def list_software_txt(software, detailed=False): return '\n'.join(lines) +def list_software_json(software, detailed=False): + """ + Return overview of supported software in json + + :param software: software information (strucuted like list_software does) + :param detailed: whether or not to return detailed information (incl. version, versionsuffix, toolchain info) + :return: multi-line string presenting requested info + """ + lines = ['['] + for key in sorted(software, key=lambda x: x.lower()): + for tmp in software[key]: + if detailed: + # deep copy here to avoid modifying the original dict + x = copy.deepcopy(tmp) + x['description'] = x['description'].split('\n')[0].strip() + else: + x = {} + x['name'] = key + + lines.append(json.dumps(x, indent=4) + ",") + if detailed: + break + # remove last comma + if len(lines) > 1: + lines[-1] = lines[-1][:-1] + return '\n'.join(lines) + '\n]' + + def list_toolchains(output_format=FORMAT_TXT): """Show list of known toolchains.""" _, all_tcs = search_toolchain('') diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index e69d96b2f6..2a7d990e01 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -79,7 +79,7 @@ from easybuild.tools.config import get_pretend_installpath, init, init_build_options, mk_full_default_path from easybuild.tools.config import BuildOptions, ConfigurationVariables from easybuild.tools.configobj import ConfigObj, ConfigObjError -from easybuild.tools.docs import FORMAT_MD, FORMAT_RST, FORMAT_TXT +from easybuild.tools.docs import FORMAT_MD, FORMAT_RST, FORMAT_TXT, FORMAT_JSON from easybuild.tools.docs import avail_cfgfile_constants, avail_easyconfig_constants, avail_easyconfig_licenses from easybuild.tools.docs import avail_toolchain_opts, avail_easyconfig_params, avail_easyconfig_templates from easybuild.tools.docs import list_easyblocks, list_toolchains @@ -469,7 +469,7 @@ def override_options(self): 'mpi-tests': ("Run MPI tests (when relevant)", None, 'store_true', True), 'optarch': ("Set architecture optimization, overriding native architecture optimizations", None, 'store', None), - 'output-format': ("Set output format", 'choice', 'store', FORMAT_TXT, [FORMAT_MD, FORMAT_RST, FORMAT_TXT]), + 'output-format': ("Set output format", 'choice', 'store', FORMAT_TXT, [FORMAT_MD, FORMAT_RST, FORMAT_TXT, FORMAT_JSON]), 'output-style': ("Control output style; auto implies using Rich if available to produce rich output, " "with fallback to basic colored output", 'choice', 'store', OUTPUT_STYLE_AUTO, OUTPUT_STYLES),