CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
104 lines
2.9 KiB
Python
104 lines
2.9 KiB
Python
#!/usr/bin/env python
|
|
#
|
|
# ===- csv2json.py - Static Analyzer test helper ---*- python -*-===#
|
|
#
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
#
|
|
# ===------------------------------------------------------------------------===#
|
|
|
|
r"""
|
|
Clang Static Analyzer test helper
|
|
=================================
|
|
|
|
This script converts a CSV file to a JSON file with a specific structure.
|
|
|
|
The JSON file contains a single dictionary. The keys of this dictionary
|
|
are taken from the first column of the CSV. The values are dictionaries
|
|
themselves, mapping the CSV header names (except the first column) to
|
|
the corresponding row values.
|
|
|
|
|
|
Usage:
|
|
csv2json.py <source-file>
|
|
|
|
Example:
|
|
// RUN: %csv2json.py %t | FileCheck %s
|
|
"""
|
|
|
|
import csv
|
|
import sys
|
|
import json
|
|
|
|
|
|
def csv_to_json_dict(csv_filepath):
|
|
"""
|
|
Args:
|
|
csv_filepath: The path to the input CSV file.
|
|
|
|
Raises:
|
|
FileNotFoundError: If the CSV file does not exist.
|
|
csv.Error: If there is an error parsing the CSV file.
|
|
Exception: For any other unexpected errors.
|
|
"""
|
|
try:
|
|
with open(csv_filepath, "r", encoding="utf-8") as csvfile:
|
|
reader = csv.reader(csvfile, skipinitialspace=True)
|
|
|
|
# Read the header row (column names)
|
|
try:
|
|
header = next(reader)
|
|
except StopIteration: # Handle empty CSV file
|
|
json.dumps({}, indent=2) # write an empty dict
|
|
return
|
|
|
|
# handle a csv file that contains no rows, not even a header row.
|
|
if not header:
|
|
json.dumps({}, indent=2)
|
|
return
|
|
|
|
header_length = len(header)
|
|
other_column_names = header[1:]
|
|
|
|
data_dict = {}
|
|
|
|
for row in reader:
|
|
if len(row) != header_length:
|
|
raise csv.Error("Inconsistent CSV file")
|
|
exit(1)
|
|
|
|
key = row[0]
|
|
value_map = {}
|
|
|
|
for i, col_name in enumerate(other_column_names):
|
|
# +1 to skip the first column
|
|
value_map[col_name] = row[i + 1].strip()
|
|
|
|
data_dict[key] = value_map
|
|
|
|
return json.dumps(data_dict, indent=2)
|
|
|
|
except FileNotFoundError:
|
|
raise FileNotFoundError(f"Error: CSV file not found at {csv_filepath}")
|
|
except csv.Error as e:
|
|
raise csv.Error(f"Error parsing CSV file: {e}")
|
|
except Exception as e:
|
|
raise Exception(f"An unexpected error occurred: {e}")
|
|
|
|
|
|
def main():
|
|
"""Example usage with error handling."""
|
|
csv_file = sys.argv[1]
|
|
|
|
try:
|
|
print(csv_to_json_dict(csv_file))
|
|
except (FileNotFoundError, csv.Error, Exception) as e:
|
|
print(str(e))
|
|
except:
|
|
print("An error occurred")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|