Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Transition from s4ext to json #2011

Merged
merged 7 commits into from
Apr 24, 2024
Merged

Commits on Apr 23, 2024

  1. ENH: Convert s4ext to json files

    A script like the following was used. Note that "pre-commit run -a" was
    also executed to reformat the json files afterward.
    
    ```
    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
    
    s4ext_filepaths = list(extensions_index_dir.glob("*.s4ext"))
    
    print(f"Found {len(s4ext_filepaths)} extension files (.s4ext)")
    
    for index, filepath in enumerate(s4ext_filepaths):
    
        metadata = parse_s4ext(filepath)
        updated_metadata = {
            "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)
    ```
    jcfr committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    a198447 View commit details
    Browse the repository at this point in the history
  2. CI: Update workflows and templates to expect json files

    Update GitHub and CircleCI settings to check for json files.
    
    Update `check_description_files` CLI to parse json files:
    * Remove `parse_s4ext` and introduce `parse_json` function along with
      `ExtensionParseError` exception.
    * Update list of supported URL schemes. Only `https` and `git` are supported
    * Remove obsolete `check_scm_notlocal` check
    jcfr committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    d68c8e5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e64a350 View commit details
    Browse the repository at this point in the history

Commits on Apr 24, 2024

  1. ENH: Update .json files to reference schema

    A script like the following was used. Note that "pre-commit run -a" was
    also executed to reformat the json files afterward.
    
    ```
    import json
    import sys
    from pathlib import Path
    
    extensions_index_dir = Path("/home/jcfr/Projects/ExtensionsIndex")
    
    json_filepaths = list(extensions_index_dir.glob("*.json"))
    print(f"Found {len(json_filepaths)} extension files (.json)")
    
    for index, filepath in enumerate(json_filepaths):
        with open(filepath) as fileContents:
            metadata = json.load(fileContents)
            metadata["$schema"] = "https://raw.githubusercontent.com/Slicer/Slicer/main/Schemas/slicer-extension-catalog-entry-schema-v1.0.0.json#"
    
        with open(extensions_index_dir / filepath, 'w') as fileContents:
            fileContents.write(json.dumps(metadata, sort_keys=True, indent=2))
            fileContents.write("\n")
    ```
    jcfr committed Apr 24, 2024
    Configuration menu
    Copy the full SHA
    d5a6233 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    80e05b4 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    2a00294 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0b4f9cd View commit details
    Browse the repository at this point in the history