-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removing dummy parser * fix typing * fixes * fixes * fixes * tests refactoring * moving example JSON to tests resources * tests fixing * fixing TOPAS * fixing tests * missing files added * refactor: Autofix issues in 4 files Resolved issues in the following files with DeepSource Autofix: 1. tests/shieldhit/test_shieldhit_converter.py 2. tests/shieldhit/test_zones.py 3. tests/topas/conftest.py 4. tests/topas/test_topas_converter.py * readme added * fixes * fixes * fixes * refactor: Autofix issues in 1 file Resolved issues in converter/topas/parser.py with DeepSource Autofix * deepsource * Apply suggestions from code review Co-authored-by: Dominik Hendzel <[email protected]> * review * review * Apply suggestions from code review Co-authored-by: Mateusz Wronka <[email protected]> * Apply suggestions from code review Co-authored-by: Mateusz Wronka <[email protected]> --------- Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> Co-authored-by: Dominik Hendzel <[email protected]> Co-authored-by: Mateusz Wronka <[email protected]>
- Loading branch information
1 parent
2a1ff47
commit 7a12210
Showing
38 changed files
with
275 additions
and
1,269 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
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
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
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
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 |
---|---|---|
@@ -1,24 +1,38 @@ | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
|
||
|
||
class Parser(ABC): | ||
class Parser: | ||
"""Abstract parser, the template for implementing other parsers.""" | ||
|
||
@abstractmethod | ||
def __init__(self) -> None: | ||
self.info = { | ||
"version": "", | ||
"label": "", | ||
"simulator": "", | ||
} | ||
|
||
def parse_configs(self, json: dict) -> None: | ||
"""Convert the json dict to the 4 config dataclasses.""" | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def save_configs(self, target_dir: Path) -> None: | ||
def save_configs(self, target_dir: str): | ||
""" | ||
Save the configs as text files in the target_dir. | ||
The files are: beam.dat, mat.dat, detect.dat and geo.dat. | ||
""" | ||
if not Path(target_dir).exists(): | ||
raise ValueError("Target directory does not exist.") | ||
|
||
for file_name, content in self.get_configs_json().items(): | ||
with open(Path(target_dir, file_name), 'w') as conf_f: | ||
conf_f.write(content) | ||
|
||
@abstractmethod | ||
def get_configs_json(self) -> dict: | ||
""" | ||
Return a dict representation of the config files. Each element has | ||
the config files name as key and its content as value. | ||
""" | ||
configs_json = { | ||
"info.json": str(self.info), | ||
} | ||
return configs_json |
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
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
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
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
Oops, something went wrong.