-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ILC/CLIC-theory-predictions
- Loading branch information
Showing
961 changed files
with
686,004 additions
and
685,873 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
import sys | ||
|
||
|
||
def format_json_file(file_path): | ||
""" | ||
Formats a JSON file to ensure consistent indentation and readability. | ||
This function reads a JSON file, checks if it is valid JSON, and then | ||
reformats the file with 2-space indentation and each array element on a | ||
separate line for better readability. If the JSON is invalid, an error message | ||
is printed, and the function returns False. | ||
Parameters: | ||
----------- | ||
file_path : str | ||
The path to the JSON file that needs to be formatted. | ||
Returns: | ||
-------- | ||
bool | ||
Returns True if the JSON file was formatted successfully. | ||
Returns False if the file contains invalid JSON. | ||
Raises: | ||
------- | ||
json.JSONDecodeError | ||
Raised when the JSON file is invalid, though it is handled within the function. | ||
""" | ||
with open(file_path, "r") as f: | ||
try: | ||
data = json.load(f) | ||
except json.JSONDecodeError as e: | ||
print(f"Error: {file_path} is not valid JSON. {e}") | ||
return False | ||
|
||
# Reformat the data by ensuring arrays have their elements on separate lines | ||
formatted_data = json.dumps(data, indent=2, separators=(",", ": ")) | ||
|
||
# Write the reformatted JSON back to the file | ||
with open(file_path, "w") as f: | ||
f.write(formatted_data + "\n") # Adding a newline at the end of the file | ||
|
||
print(f"Formatted {file_path} successfully.") | ||
return True | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
Main function that processes command-line arguments. | ||
This block allows the script to be run directly from the command line. It | ||
iterates over each argument passed to the script, checking if the file has a | ||
.json extension. If so, it attempts to format the JSON file. If the file does | ||
not have a .json extension, a message is printed indicating it is skipped. | ||
Usage: | ||
------ | ||
python script_name.py <file1.json> <file2.json> ... | ||
Example: | ||
-------- | ||
$ python format_json.py data1.json data2.json | ||
""" | ||
# Loop over all files passed as arguments | ||
for file in sys.argv[1:]: | ||
if file.endswith(".json"): | ||
format_json_file(file) | ||
else: | ||
print(f"Skipping non-JSON file: {file}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties":{ | ||
"best_sm":{ | ||
"type":"array", | ||
"items":{ | ||
"type":"number" | ||
} | ||
}, | ||
"scales":{ | ||
"type":"array", | ||
"items":{ | ||
"type":"number" | ||
} | ||
}, | ||
"theory_cov":{ | ||
"type": "array", | ||
"items": { | ||
"type": "array", | ||
"items": { | ||
"type": "number" | ||
} | ||
} | ||
}, | ||
"LO":{ | ||
"type":"object", | ||
"additionalProperties":{ | ||
"type":"array", | ||
"items":{ | ||
"type":"number" | ||
} | ||
} | ||
}, | ||
"NLO":{ | ||
"type":"object", | ||
"additionalProperties":{ | ||
"type":"array", | ||
"items":{ | ||
"type":"number" | ||
} | ||
} | ||
} | ||
}, | ||
"required": ["best_sm", "scales", "theory_cov", "LO"], | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# .github/workflows/pre-commit.yml | ||
name: Pre-commit | ||
on: [push] | ||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: pre-commit/[email protected] | ||
with: | ||
extra_args: '--all-files' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 23.1.0 # Replace with the latest Black version | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
- repo: https://github.com/python-jsonschema/check-jsonschema | ||
rev: 0.29.4 | ||
hooks: | ||
- id: check-jsonschema | ||
files: ^theory/.*\.json$ | ||
args: ["--schemafile", ".github/theory_scheme.json"] | ||
- repo: local | ||
hooks: | ||
- id: format-json | ||
name: Format JSON Files | ||
entry: python .github/format_json.py | ||
language: python | ||
types: [json] | ||
files: ^theory/.*\.json$ | ||
- repo: https://github.com/google/yamlfmt | ||
rev: v0.8.0 # Replace with the latest version of yamlfmt | ||
hooks: | ||
- id: yamlfmt | ||
name: Format YAML with yamlfmt |
Oops, something went wrong.