-
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.
feature: implemented json and yaml parser
- Loading branch information
Showing
25 changed files
with
588 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,12 @@ | |
.. include:: ../README.md | ||
""" | ||
from importlib.metadata import version | ||
from configen.configen import cli | ||
from configen.base_parser import Parser | ||
from configen.json_parser import JsonParser | ||
from configen.yaml_parser import YamlParser | ||
|
||
__author__ = "Ling" | ||
__email__ = "[email protected]" | ||
__version__ = version("configen") | ||
__all__ = [cli, Parser, JsonParser, YamlParser] |
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,2 +1,11 @@ | ||
"""Entry point for program""" | ||
print("Entry point") | ||
|
||
|
||
def cli(): | ||
"""Command line interface entry point. | ||
Example: | ||
configen config.json | ||
""" | ||
# TODO:: function should be able to read a mixture of config types | ||
pass |
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,27 +1,23 @@ | ||
import json | ||
from ruamel.yaml import YAML | ||
from configen.base_parser import Parser | ||
|
||
_yaml = YAML() | ||
_yaml.indent(mapping=2, sequence=4, offset=2) | ||
|
||
|
||
class JsonParser(Parser): | ||
"""Json parser.""" | ||
extension = "json" | ||
|
||
def _write_method(self, filename: str) -> Parser: | ||
filename = self.check_extension(filename) | ||
filename = self._append_extension(filename) | ||
|
||
with open(filename, "w") as file: | ||
json.dump(self.config, file, indent=4) | ||
|
||
return self | ||
|
||
def _load_method(self, filename: str) -> dict: | ||
filename = self.check_extension(filename) | ||
filename = self._append_extension(filename) | ||
|
||
with open(filename, "r") as json_config: | ||
config = json.load(json_config) | ||
config = json.loads(json_config.read()) | ||
|
||
return config |
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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"function1": { | ||
"name": "transform", | ||
"param": "col1" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"function2": { | ||
"name": "load", | ||
"param": "col2" | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"name": "config-01", | ||
"training": true, | ||
"parameters": { | ||
"num_nodes": 200, | ||
"num_samples": 100, | ||
"max_time": 40 | ||
} | ||
} |
Oops, something went wrong.