-
Notifications
You must be signed in to change notification settings - Fork 4
adding merge script #138
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
Merged
+142
−21
Merged
adding merge script #138
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7eba313
adding merge script (untested)
CIGbalance e4ee7a0
Merge branch 'main' into feat/merge_script
CIGbalance 3535ab5
making tests not fail
CIGbalance 9763064
Merge branch 'feat/problem_check_cosmetics' into feat/merge_script
CIGbalance 4376e17
Apply suggestions from code review
CIGbalance c39e790
Change example problem format to YAML
CIGbalance 014b6e2
requested changes
CIGbalance 3479114
Merge branch 'main' into feat/merge_script
CIGbalance 35f90fc
follow new workflow
CIGbalance 88092bc
tested script now
CIGbalance aab7bae
remove from PR
CIGbalance 5e7af8a
remove unnecessary changes here
CIGbalance c8ac3b2
undoing changes
CIGbalance 7a3f931
removing additional changes
CIGbalance 9efc95f
Merge branch 'feat/problem_check_cosmetics' into feat/merge_script
CIGbalance 617971f
undoing changes
CIGbalance b9cd070
remove file again
CIGbalance b5a05e3
Merge branch 'main' into feat/merge_script
CIGbalance 27700d5
finishing merge
CIGbalance f6dc0df
Apply suggestions from code review
CIGbalance 4f5fac9
new_data None
CIGbalance 2e0ef4e
Merge branch 'feat/merge_script' of github.com:OpenOptimizationOrg/OP…
CIGbalance c65cdc9
imports
CIGbalance cadb19a
removing no changes
CIGbalance 894c9c1
add typing
CIGbalance c209260
change to manual mode
CIGbalance 3182de5
updated for new workflow
CIGbalance 779dded
Merge branch 'main' into feat/merge_script
CIGbalance 3d8bc58
Apply suggestions from code review
CIGbalance d332b7e
some additional review updates
CIGbalance e8f6ac6
Merge branch 'feat/merge_script' of github.com:OpenOptimizationOrg/OP…
CIGbalance f0352ec
check format fixes
CIGbalance 70361d4
do not write if failing
CIGbalance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,96 @@ | ||
| import yaml | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import List, Dict | ||
|
|
||
| # Add parent directory to sys.path | ||
| parent = Path(__file__).resolve().parent.parent | ||
| sys.path.insert(0, str(parent)) | ||
|
|
||
| from utils.validate_yaml import read_data, validate_data, validate_yaml | ||
|
|
||
|
|
||
| def write_data(filepath: str, data: List[Dict]) -> bool: | ||
| try: | ||
| with open(filepath, "w") as f: | ||
| yaml.safe_dump(data, f, sort_keys=False) | ||
| print(f"::notice::Wrote data to {filepath}.") | ||
| except FileNotFoundError: | ||
| print(f"::error::File not found: {filepath}") | ||
| return False | ||
| except OSError as e: | ||
| print(f"::error::Error writing file {filepath}: {e}") | ||
| return False | ||
| except yaml.YAMLError as e: | ||
| print(f"::error::YAML syntax error: {e}") | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def update_existing_data( | ||
| existing_data: List[Dict], new_data: List[Dict], out_file: str | ||
| ) -> bool: | ||
| existing_data.extend(new_data) | ||
| # validate merged data before writing | ||
| valid = validate_data(existing_data) | ||
| if not valid: | ||
| print(f"::error::Merged data is not valid, cannot write to {out_file}.") | ||
| return False | ||
| write_success = write_data(out_file, existing_data) | ||
| return write_success | ||
|
|
||
|
|
||
| def merge_new_problems(new_problems_yaml_path: str, big_yaml_path: str) -> bool: | ||
| # Read and validate new data | ||
| new_data_status, new_data = read_data(new_problems_yaml_path) | ||
| if new_data_status != 0 or new_data is None: | ||
| print( | ||
| f"::error::New problems data could not be read from {new_problems_yaml_path}." | ||
| ) | ||
| return False | ||
| valid = validate_data(new_data) | ||
| if not valid: | ||
| print(f"::error::New problems data in {new_problems_yaml_path} is not valid.") | ||
|
CIGbalance marked this conversation as resolved.
|
||
| return False | ||
|
CIGbalance marked this conversation as resolved.
|
||
|
|
||
| # Read existing data | ||
| existing_data_status, existing_data = read_data(big_yaml_path) | ||
| if existing_data_status != 0 or existing_data is None: | ||
| print( | ||
| f"::error::Existing problems data could not be read from {big_yaml_path}." | ||
| ) | ||
| return False | ||
|
|
||
| # All valid, we can now just merge the dicts | ||
| assert existing_data is not None | ||
| assert new_data is not None | ||
| updated = update_existing_data(existing_data, new_data, big_yaml_path) | ||
| if not updated: | ||
|
CIGbalance marked this conversation as resolved.
|
||
| print(f"::error::Failed to update existing problems data in {big_yaml_path}.") | ||
| return False | ||
|
|
||
| # Validate resulting data | ||
| final_status, final_data = validate_yaml(big_yaml_path) | ||
| if final_status != 0 or final_data is None: | ||
| print( | ||
| f"::error::Merged data in {big_yaml_path} is not valid after merging new problems." | ||
| ) | ||
| return False | ||
|
|
||
| print( | ||
| f"::notice::Merged {len(new_data)} new problems into {big_yaml_path}. {new_problems_yaml_path} can now be deleted." | ||
| ) | ||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 3: | ||
| print("Usage: python merge_yaml.py <new_problems.yaml> <big_yaml_path>") | ||
| sys.exit(1) | ||
| new_problems_yaml_path = sys.argv[1] | ||
| big_yaml_path = sys.argv[2] | ||
| status = merge_new_problems(new_problems_yaml_path, big_yaml_path) | ||
| if not status: | ||
| sys.exit(1) | ||
| else: | ||
| sys.exit(0) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.