kkonganti@0: #!/usr/bin/env python kkonganti@0: kkonganti@0: import platform kkonganti@0: import subprocess kkonganti@0: from textwrap import dedent kkonganti@0: kkonganti@0: import yaml kkonganti@0: kkonganti@0: kkonganti@0: def _make_versions_html(versions): kkonganti@0: html = [ kkonganti@0: dedent( kkonganti@0: """\\ kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: """ kkonganti@0: ) kkonganti@0: ] kkonganti@0: for process, tmp_versions in sorted(versions.items()): kkonganti@0: html.append("") kkonganti@0: for i, (tool, version) in enumerate(sorted(tmp_versions.items())): kkonganti@0: html.append( kkonganti@0: dedent( kkonganti@0: f"""\\ kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: """ kkonganti@0: ) kkonganti@0: ) kkonganti@0: html.append("") kkonganti@0: html.append("
Process Name Software Version
{process if (i == 0) else ''}{tool}{version}
") kkonganti@0: return "\\n".join(html) kkonganti@0: kkonganti@0: kkonganti@0: versions_this_module = {} kkonganti@0: versions_this_module["${task.process}"] = { kkonganti@0: "python": platform.python_version(), kkonganti@0: "yaml": yaml.__version__, kkonganti@0: } kkonganti@0: kkonganti@0: with open("$versions") as f: kkonganti@0: versions_by_process = yaml.load(f, Loader=yaml.BaseLoader) kkonganti@0: versions_by_process.update(versions_this_module) kkonganti@0: kkonganti@0: # aggregate versions by the module name (derived from fully-qualified process name) kkonganti@0: versions_by_module = {} kkonganti@0: for process, process_versions in versions_by_process.items(): kkonganti@0: module = process.split(":")[-1] kkonganti@0: try: kkonganti@0: assert versions_by_module[module] == process_versions, ( kkonganti@0: "We assume that software versions are the same between all modules. " kkonganti@0: "If you see this error-message it means you discovered an edge-case " kkonganti@0: "and should open an issue in nf-core/tools. " kkonganti@0: ) kkonganti@0: except KeyError: kkonganti@0: versions_by_module[module] = process_versions kkonganti@0: kkonganti@0: versions_by_module["CPIPES"] = { kkonganti@0: "Nextflow": "$workflow.nextflow.version", kkonganti@0: "$workflow.manifest.name": "$workflow.manifest.version", kkonganti@0: "${params.pipeline}": "${params.workflow_version}", kkonganti@0: } kkonganti@0: kkonganti@0: versions_mqc = { kkonganti@0: "id": "software_versions", kkonganti@0: "section_name": "${workflow.manifest.name} Software Versions", kkonganti@0: "section_href": "https://cfsan-git.fda.gov/Kranti.Konganti/${workflow.manifest.name.toLowerCase()}", kkonganti@0: "plot_type": "html", kkonganti@0: "description": "Collected at run time from the software output (STDOUT/STDERR).", kkonganti@0: "data": _make_versions_html(versions_by_module), kkonganti@0: } kkonganti@0: kkonganti@0: with open("software_versions.yml", "w") as f: kkonganti@0: yaml.dump(versions_by_module, f, default_flow_style=False) kkonganti@0: kkonganti@0: # print('sed -i -e "' + "s%'%%g" + '" *.yml') kkonganti@0: subprocess.run('sed -i -e "' + "s%'%%g" + '" software_versions.yml', shell=True) kkonganti@0: kkonganti@0: with open("software_versions_mqc.yml", "w") as f: kkonganti@0: yaml.dump(versions_mqc, f, default_flow_style=False) kkonganti@0: kkonganti@0: with open("versions.yml", "w") as f: kkonganti@0: yaml.dump(versions_this_module, f, default_flow_style=False)