yamer 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
yamer/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .convert import *
2
+
3
+ __version__ = "1.0.0"
yamer/cli.py ADDED
@@ -0,0 +1,50 @@
1
+ """
2
+ Usage:
3
+ yamer (-h|--help)
4
+ yamer [-f <file_name>] [-d <dir_name>] [-t <file_type>] [-e <name_list>] [-n <notice>]
5
+
6
+ Arguments:
7
+ -f, --file File path to be converted [default: null],
8
+ this must come with a valid YAML/JSON name.
9
+ If the file is missing [at default],
10
+ entire working folder will be processed.
11
+ -d, --dir Files directory [default: working folder].
12
+ -t, --type Files type, can be yaml [at default] or json,
13
+ used when [--file] is not set.
14
+ -e, --exclude List of excluded files [default: null],
15
+ comes without files extension.
16
+ -n, --notice Print notice to stdout [default: no].
17
+ <file_name> The input file path, eg. "./some.yaml".
18
+ <dir_name> The input dir path, eg. "./data".
19
+ <file_type> The input file extension, eg. "json".
20
+ <name_list> The file names list, eg. "some,one,two".
21
+ <notice> Should be any string, eg. "yes" or "1".
22
+ """
23
+
24
+ from .convert import *
25
+
26
+ def main():
27
+ import argparse
28
+ parser = argparse.ArgumentParser(description='YAML/JSON File Conversion')
29
+ parser.add_argument('-f', '--file', type=str, default='', help=f'single file path to be converted')
30
+ parser.add_argument('-d', '--dir', type=str, default='./', help=f'files directory to be processed')
31
+ parser.add_argument('-t', '--type', type=str, default='yaml', help=f'file type setting: yaml/json')
32
+ parser.add_argument('-e', '--exclude', type=str, default='', help=f'excluded files list')
33
+ parser.add_argument('-n', '--notice', type=str, default='', help=f'print notice to stdout')
34
+ args = parser.parse_args()
35
+ excludes = args.exclude.split(",")
36
+ notice = True if args.notice else False
37
+ file = args.file if args.file.startswith(args.dir) else (args.dir + args.file if args.file else None)
38
+ try:
39
+ if file:
40
+ Yaml(file).convert(notice=notice)
41
+ print("Converting done")
42
+ elif args.dir:
43
+ convert_full_folder(args.dir, args.type.lower(), excludes=excludes, notice=notice)
44
+ else:
45
+ print("Nothing done, unknown reason")
46
+ except Exception as e:
47
+ print(f"Error: {e}")
48
+
49
+ if __name__ == '__main__':
50
+ main()
yamer/convert.py ADDED
@@ -0,0 +1,47 @@
1
+ """
2
+ source_path: must be a valid YAML/JSON file, eg. "./data/some.yaml"
3
+ target_path: can be specified or got from source_path automatically
4
+ Sample usage:
5
+ > Yaml("./some.yaml").convert()
6
+ > Yaml("./more.json").convert()
7
+ > convert_full_folder(excludes=["some", "more"])
8
+ """
9
+
10
+ import yaml, json
11
+ from pathlib import Path
12
+
13
+ ENCODINGSIG = 'utf-8-sig'
14
+
15
+ YAML = "yaml"
16
+ JSON = "json"
17
+ CONVERTS = {YAML: JSON, JSON: YAML}
18
+
19
+ class Yaml:
20
+ def __init__(self, source_path: str, target_path: str=None):
21
+ self.source = source_path
22
+ source_file = Path(source_path)
23
+ self.type = source_file.suffix.lstrip(".").lower()
24
+ self.target = target_path if target_path else str(source_file.with_suffix(f".{CONVERTS[self.type]}"))
25
+ def read(self) -> any:
26
+ with open(self.source, encoding=ENCODINGSIG) as file:
27
+ if self.type == YAML:
28
+ data = yaml.load(file, yaml.Loader)
29
+ else:
30
+ data = json.load(file)
31
+ return data
32
+ def write(self, data, indent=2, notice: bool=True):
33
+ with open(self.target, "w", encoding=ENCODINGSIG) as file:
34
+ if self.type == YAML:
35
+ json.dump(data, file, indent=2, ensure_ascii=False)
36
+ else:
37
+ yaml.dump(data, file, default_flow_style=False, sort_keys=False)
38
+ if notice: print(f"Writing: {self.target}")
39
+ def convert(self, indent=2, notice: bool=True):
40
+ self.write(self.read(), indent=indent, notice=notice)
41
+
42
+ def convert_full_folder(folder_path: str="./", source_type: str=YAML, excludes: list=[], notice=False):
43
+ folder = Path(folder_path)
44
+ for file in folder.glob(f"*.{source_type}"):
45
+ if file.is_file() and file.name not in [f"{item}.{source_type}" for item in excludes]:
46
+ Yaml(str(file)).convert(notice=notice)
47
+ print("All convertings done")
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: yamer
3
+ Version: 1.0.0
4
+ Summary: YAML to/from JSON File Conversion Tool
5
+ Home-page: https://github.com/asinerum/yamer
6
+ Author: Asinerum Conlang Project
7
+ Author-email: asinerum.com@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: formatize>=1.0.19
16
+ Dynamic: license-file
17
+
18
+ # YAML vs JSON File Conversion Tool
19
+
20
+ ## Installation
21
+ ```bash
22
+ pip install yamer
23
+ ```
24
+
25
+ ## Sample Usage [Nov 25, 2026]
26
+ ```bash
27
+ yamer -f some_file.yaml
28
+ yamer -f another_file.json
29
+ yamer -e some_file,another_file
30
+ yamer -d ./data -t json
31
+ yamer -t json
32
+ yamer -n yes
33
+ ```
34
+
35
+ Detailed tips, tricks, and examples, can be found at project's repository
36
+ https://github.com/asinerum/yamer
37
+
38
+ (C)2026 Asinerum Conlang Project
@@ -0,0 +1,9 @@
1
+ yamer/__init__.py,sha256=r3CWQ-95mN_9XCGffIlX2Tj-LElpWbAK6-Bxhcx7cHM,49
2
+ yamer/cli.py,sha256=FNf4LXgzONd6U-tfeyxEgC8hCnd0o5w0a57oWxDwue0,2153
3
+ yamer/convert.py,sha256=sbG9DFQ4cm9g-u7l8rENUvZyh0jf8bBg7RqKO_n2My0,1719
4
+ yamer-1.0.0.dist-info/licenses/LICENSE,sha256=4npUbkrpgB6lqMiYYeUxZAP4SOkjVSwK8-7jW60mxvw,1081
5
+ yamer-1.0.0.dist-info/METADATA,sha256=1F5BX6-eJ6T0KQsjrdNeOs1Dhv90x9pDVQg6VeoasQ0,954
6
+ yamer-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ yamer-1.0.0.dist-info/entry_points.txt,sha256=7PmJUfQjS9l5ePJMuz1GiWtz16MZ3kmyJ5bjNNI_h7E,41
8
+ yamer-1.0.0.dist-info/top_level.txt,sha256=z7SvpzgP3UGO5S3k-SgUdmHU_TA8Hwf8GF8r2hCmowk,6
9
+ yamer-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ yamer = yamer.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asinerum Conlang Project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ yamer