Slicer / ExtensionsIndex

Slicer extensions index
https://github.com/Slicer/ExtensionsIndex/#slicer-extensions-index
65 stars 238 forks source link

Meta issue referencing extension updates #2041

Open jcfr opened 4 months ago

jcfr commented 4 months ago

These pull requests were created in the context of https://github.com/Slicer/ExtensionsIndex/pull/2011

List of pull requests intended to fix and consolidate extension metadata:

fedorov commented 4 months ago

@jcfr can you please review this comment: https://github.com/QIICR/SlicerDevelopmentToolbox/pull/45#issuecomment-2075484010 ?

Extension build stopped working today, which coincided with your PR...

jcfr commented 4 months ago

Thanks for pointing this out, I will have a look later when back on the 👨‍💻

jcfr commented 3 months ago

List of pull requests and issues intended to fix and consolidate extension metadata for extension not yet integrated:

For future reference, following code was used to generate the s4ext from json:

import json
import sys
from pathlib import Path

extensions_index_dir = Path("/home/jcfr/Projects/ExtensionsIndex")
updated_extensions_index_dir = extensions_index_dir

def parse_s4ext(ext_file_path):
    """Parse a Slicer extension description file.
    :param ext_file_path: Path to a Slicer extension description file.
    """
    ext_metadata = {}
    with open(ext_file_path) as ext_file:
        for line in ext_file:
            if not line.strip() or line.startswith("#"):
                continue
            fields = [field.strip() for field in line.split(' ', 1)]
            assert(len(fields) <= 2)
            ext_metadata[fields[0]] = fields[1] if len(fields) == 2 else None
    return ext_metadata

# Collect s4ext files
s4ext_filepaths = list(extensions_index_dir.glob("*.s4ext"))

print(f"Found {len(s4ext_filepaths)} extension files (.s4ext)")

# Parse s4ext files and generate corresponding json files
for index, filepath in enumerate(s4ext_filepaths):

    metadata = parse_s4ext(filepath)
    #print("filepath", filepath)
    updated_metadata = {
        "$schema": "https://raw.githubusercontent.com/Slicer/Slicer/main/Schemas/slicer-extension-catalog-entry-schema-v1.0.0.json#",
        "scm_url": metadata["scmurl"],
        "scm_revision": metadata["scmrevision"],
        "build_dependencies": [] if metadata.get("depends", "NA") == "NA" else metadata["depends"].split(" "),
        "category": metadata["category"],
        "build_subdirectory": metadata["build_subdirectory"],
    }

    with open(updated_extensions_index_dir / f"{filepath.stem}.json", 'w') as fileContents:
        fileContents.write(json.dumps(updated_metadata, sort_keys=True, indent=2))
        fileContents.write("\n")

print(f"Generated {index + 1} extension files (.json)")

from pprint import pprint as pp

print(f"\nMetadata of extension #{index + 1} ({filepath.stem}):\n")
pp(updated_metadata)