-
Notifications
You must be signed in to change notification settings - Fork 245
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
Conversation
930b93b
to
edfaab2
Compare
For reference, the following script was used to convert from 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 = {
"scmurl": metadata["scmurl"],
"scmrevision": 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) |
edfaab2
to
52b8a82
Compare
52b8a82
to
2ff4f6c
Compare
@lassoan This is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it looks good to me.
I don't really like the inconsistent naming convention (build_dependencies
uses _
separator, while scmrevision
does not use separator), but if you have a good reason for this then I can live with it.
b0679b9
to
b3566f6
Compare
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) ```
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
6699277
to
8528901
Compare
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") ```
4928e97
to
2a00294
Compare
In response to discussions during the Slicer developer hangout on March 12th, we have decided to revamp the organization of extension metadata in the extensions index, transitioning from the s4ext format to json.
Motivation:
CMakeLists.txt
from the ones organized in this repository and used to drive the build of extensions.Related issues:
Related pull requests:
Next steps:
cc: @lassoan @sjh26 @RafaelPalomar @mauigna06 @pieper
Footnotes
The
EXTENSION_CATEGORY
variable currently set in theCMakeLists.txt
will likely be deprecated ↩This is described on the Slice Discourse forum: https://discourse.slicer.org/t/introduction-of-tiers-for-slicer-extensions/34870 ↩