-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Special Formatter Issue and YAML File Implementation for Additional User Input #28
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
Open
nayera16
wants to merge
35
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3361216
separating out a glob function from the parse function, doesn't work …
nayera16 fe4fcb3
Updated core.py file with the debug issue fixed along with the latest…
rm1771 46fee32
Merge 'origin/main' into formatting_issue after package publishing ch…
nayera16 ba70f39
finalizing glob/parse method split, setting glob up for testing
nayera16 c978132
added first glob method unit test
nayera16 9bfaf29
additional glob/parse method separation unit testing
nayera16 940f836
added pytest fixtures and three xfail tests for formatter testing wit…
nayera16 9a1063a
skeleton build of a string.Formatter subclass with logic not yet impl…
nayera16 4863ea0
Updated core file with new_fmt to allow for strings in the input fmt.…
HaydenMarchinek 1c80b76
added the first helper function
HaydenMarchinek 3b0d597
added unit test for yaml loader helper function. fixed yaml file spel…
nayera16 cc34749
Updated core file with encoding map and removed pre-processing idea
HaydenMarchinek 552a21c
added new version of yaml file that allows multiple fmt's
HaydenMarchinek 1810fd4
updated the core file, encodings yaml file, and helper functions to a…
HaydenMarchinek 7b36db0
Updated core file to allow integer and floats in parse. Added PyTOML …
HaydenMarchinek 1d0a0f2
adapting tests and yaml file for updates to core
nayera16 8d8df5c
Started updating tests to match with the current Paraframe indexing m…
rm1771 21bed1b
Added documentation to the helper_functions.py file and made test_par…
704ba84
updated current spin format unit tests with correct formatter solutio…
nayera16 8a26a08
Merge branch 'formatting_issue_prototype' of github.com:l6a/hallmark …
nayera16 80564e0
added unit tests for "m" formatting of spin types. fixed encodings re…
nayera16 d0d82f7
revert paraframe creation back to using just fmt and no index
nayera16 01a8569
Attempted to revert back to fmt as an argument with test modifications
rm1771 5ab3089
Attempted to make a cleaner version for the encoding map
rm1771 3245925
Added code to the core file that carries out regex sub to only the cu…
7c97b75
Updated hallmark to allow an absolute fmt string to be input for fmt …
HaydenMarchinek 2802ed6
Updated conftest with a method to back up whats currently stored in y…
HaydenMarchinek b75cd6e
Changed the way that the yaml file gets overwritten to allow new temp…
HaydenMarchinek e827434
Changed the encodings.yaml to consider case when no encoding specifie…
93d0422
cleaning up yaml and core files to get ready for PR
nayera16 ec709bd
made changes to entire parsing process so that yaml file can be in th…
nayera16 d166582
Updated conftest such that a new temporary yaml file gets created in …
HaydenMarchinek 925ccf4
fixing linter errors for PR
nayera16 8bdf0fa
fixing linter errors for PR 2
nayera16 6d7bd57
fixing linter errors for PR 3
nayera16 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 @@ | ||
| data: | ||
| - fmt: /{mag:d}a{aspin}_w{win:d}.h5 | ||
| # path_to_fmt: m5/data | ||
| encoding: | ||
| aspin: m([0-9]+(\.[0-9]+)?|\.[0-9]+) | ||
|
|
||
| - fmt: /a_{a:d}/b_{b:d}.txt | ||
| # path_to_fmt: data | ||
|
|
||
| - fmt: /a{aspin}/b_{b:d}.txt | ||
| # path_to_fmt: data | ||
| encoding: | ||
| aspin: '' |
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
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,63 @@ | ||
| from pathlib import Path | ||
| import yaml | ||
| import re | ||
|
|
||
| _user_yaml_path = None | ||
|
|
||
| def set_rel_yaml_path(path): | ||
| global _user_yaml_path | ||
| _user_yaml_path = Path(path).resolve() | ||
|
|
||
| def get_rel_yaml_path(): | ||
| if _user_yaml_path is not None: | ||
| return _user_yaml_path | ||
| return Path(__file__).parent / ".hallmark.yaml" | ||
|
|
||
| def load_encodings_yaml(): | ||
| path = get_rel_yaml_path() | ||
| yaml_path = Path(path).resolve() | ||
| f = path.open("r", encoding="utf-8") | ||
| yaml_file = yaml.safe_load(f) | ||
| encodings = yaml_file["data"] | ||
| # Resolve path_to_fmt relative to the yaml file's directory | ||
| for entry in encodings: | ||
| if "path_to_fmt" in entry: | ||
| entry["path_to_fmt"] = str( | ||
| (yaml_path.parent / entry["path_to_fmt"]).resolve() | ||
| ) | ||
|
|
||
| return encodings | ||
|
|
||
| def find_spec_by_fmt(fmt): | ||
| path = get_rel_yaml_path() | ||
| f = path.open("r", encoding="utf-8") | ||
| yaml_file = yaml.safe_load(f) | ||
| encodings = yaml_file["data"] | ||
| for spec in encodings: | ||
| if spec.get("fmt") == fmt: | ||
| return spec | ||
| return None | ||
|
|
||
| def regex_sub(f, yaml_encodings): | ||
|
|
||
| fmt = f | ||
|
|
||
| if yaml_encodings is None: | ||
| return fmt | ||
|
|
||
| enc = yaml_encodings.get("encoding", None) | ||
| if not enc: | ||
| return fmt | ||
|
|
||
| regex = enc.get("aspin", "") | ||
| if not regex: | ||
| return fmt | ||
|
|
||
| if re.search(regex, fmt): | ||
| matches = re.finditer(regex, fmt) | ||
| for match in matches: | ||
| k = match.group(0) | ||
| k_num = "-" + str(match.group(1)) | ||
| fmt = re.sub(k, k_num, fmt) | ||
|
|
||
| return fmt | ||
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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ dependencies =[ | |
| "numpy", | ||
| "pandas", | ||
| "parse", | ||
| "PyYAML", | ||
| ] | ||
|
|
||
| [tool.setuptools.packages.find] | ||
|
|
||
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 |
|---|---|---|
| @@ -1,11 +1,73 @@ | ||
| import pytest | ||
| import shutil | ||
| import yaml | ||
| from pathlib import Path | ||
| import hallmark | ||
|
|
||
| ORIGINAL_YAML = Path("demos/data/.hallmark.yaml") | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def encodings_yaml(tmp_path): | ||
| tmp_yaml = tmp_path / ".hallmark.yaml" | ||
| shutil.copy2(ORIGINAL_YAML, tmp_yaml) | ||
| hallmark.set_rel_yaml_path(tmp_yaml) | ||
| return tmp_yaml | ||
|
|
||
| @pytest.fixture(scope="function", autouse=True) | ||
| def _append_tmp_path_entries_to_encodings_yaml(tmp_path, encodings_yaml): | ||
| encodings_yaml.write_text("data: []\n", encoding="utf-8") | ||
| y = yaml.safe_load(encodings_yaml.read_text(encoding="utf-8")) or {} | ||
| y.setdefault("data", []) | ||
| fmts = [ | ||
| "/a_{a:d}/b_{b:d}.txt", | ||
| "/a{aspin}/b_{b:d}.txt", | ||
| "/{mag:d}_mag{aspin}_w{win:d}.h5", | ||
| ] | ||
| for fmt in fmts: | ||
| y["data"].append( | ||
| { | ||
| "fmt": fmt, | ||
| "encoding": {"aspin": r"m([0-9]+(\.[0-9]+)?|\.[0-9]+)"}, | ||
| } | ||
| ) | ||
| encodings_yaml.write_text(yaml.safe_dump(y, sort_keys=False), encoding="utf-8") | ||
| yield | ||
|
|
||
| def spin_format(val): | ||
| if val == 0: | ||
| return "0" | ||
| return f"{val:+g}" | ||
|
|
||
| @pytest.fixture(scope = "function") | ||
| def create_temp_data(tmp_path): | ||
| data_dir = tmp_path / "data" | ||
| data_dir = tmp_path | ||
| print(data_dir) | ||
| for a in range(10): | ||
| subdir = data_dir / f"a_{a}" | ||
| subdir.mkdir(parents=True) | ||
| for b in range(10, 20): | ||
| (subdir / f"b_{b}.txt").touch() | ||
| return data_dir | ||
|
|
||
| @pytest.fixture(scope = "function") | ||
| def create_temp_data_spin(tmp_path): | ||
| data_dir = tmp_path | ||
| spins = [-0.5, 0.0, 0.5] | ||
| for a in spins: | ||
| subdir = data_dir / f"a{spin_format(a)}" | ||
| subdir.mkdir(parents=True) | ||
| for b in range(10, 20): | ||
| (subdir / f"b_{b}.txt").touch() | ||
| return data_dir | ||
|
|
||
| @pytest.fixture(scope = "function") | ||
| def create_temp_data_spin_with_m(tmp_path): | ||
| data_dir = tmp_path | ||
| spins = ["m0.5", "0", "0.5"] | ||
|
|
||
| for mag in range(0, 2): | ||
| for aspin in spins: | ||
| for win in range(10, 20): | ||
| file_name = f"{mag}_mag{aspin}_w{win}.h5" | ||
| (data_dir / file_name).touch() | ||
| return data_dir |
Oops, something went wrong.
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.
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.
Add an attribute of ParaFrame that stores _user_yaml_path when a ParaFrame is instantiated. That way, the user can set the path with this function between creating different ParaFrames.