anoy 0.1.0__tar.gz

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.
anoy-0.1.0/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 masaniki.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
anoy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: anoy
3
+ Version: 0.1.0
4
+ Summary: This is a library that provides simple type checking for YAML.
5
+ Author-email: masaniki <masaniki.software@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/masaniki/annotation-yaml
8
+ Project-URL: Documentation, https://github.com/masaniki/annotation-yaml/tree/master/docs
9
+ Project-URL: Issues, https://github.com/masaniki/annotation-yaml/issues
10
+ Keywords: text,YAML,CLI,type,check
11
+ Classifier: Development Status :: 1 - Planning
12
+ Classifier: Environment :: Console
13
+ Classifier: Natural Language :: Japanese
14
+ Classifier: Natural Language :: English
15
+ Classifier: Topic :: Text Processing
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.txt
19
+ Requires-Dist: PyYAML
20
+ Dynamic: license-file
21
+
22
+ # fileの説明
23
+ # 原文
24
+ [Original README](docs/README_JP.md)
25
+
26
+ ## /docs
27
+ documentを格納するdirecotry.
28
+
29
+ ## /src
30
+ ここでmoduleを開発する。
31
+
32
+ ## testUnit
33
+ 単体testを行うdirectory。
34
+
35
+ ## testSystem
36
+ 結合testを行うdirectory。
37
+
38
+ ## sanbox.py
39
+ pythonの挙動を確認する。
40
+
41
+
42
+
anoy-0.1.0/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # fileの説明
2
+ # 原文
3
+ [Original README](docs/README_JP.md)
4
+
5
+ ## /docs
6
+ documentを格納するdirecotry.
7
+
8
+ ## /src
9
+ ここでmoduleを開発する。
10
+
11
+ ## testUnit
12
+ 単体testを行うdirectory。
13
+
14
+ ## testSystem
15
+ 結合testを行うdirectory。
16
+
17
+ ## sanbox.py
18
+ pythonの挙動を確認する。
19
+
20
+
21
+
@@ -0,0 +1,33 @@
1
+ # 変数の詳細は<>の中に記述する。
2
+ [build-system]
3
+ requires = ["setuptools >= 77.0.3"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "anoy"
8
+ version = "0.1.0"
9
+ authors = [
10
+ { name="masaniki", email="masaniki.software@gmail.com" }
11
+ ]
12
+ description = "This is a library that provides simple type checking for YAML."
13
+ dependencies = ["PyYAML"]
14
+ readme = "README.md"
15
+ requires-python = ">=3.9"
16
+ classifiers = [
17
+ "Development Status :: 1 - Planning",
18
+ "Environment :: Console",
19
+ "Natural Language :: Japanese",
20
+ "Natural Language :: English",
21
+ "Topic :: Text Processing"
22
+ ]
23
+ license = "MIT"
24
+ license-files = ["LICENSE.txt"]
25
+ keywords = ["text", "YAML", "CLI", "type", "check"]
26
+
27
+ [project.scripts]
28
+ anoy = "cli:main"
29
+
30
+ [project.urls]
31
+ Repository = "https://github.com/masaniki/annotation-yaml"
32
+ Documentation = "https://github.com/masaniki/annotation-yaml/tree/master/docs"
33
+ Issues = "https://github.com/masaniki/annotation-yaml/issues"
anoy-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: anoy
3
+ Version: 0.1.0
4
+ Summary: This is a library that provides simple type checking for YAML.
5
+ Author-email: masaniki <masaniki.software@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/masaniki/annotation-yaml
8
+ Project-URL: Documentation, https://github.com/masaniki/annotation-yaml/tree/master/docs
9
+ Project-URL: Issues, https://github.com/masaniki/annotation-yaml/issues
10
+ Keywords: text,YAML,CLI,type,check
11
+ Classifier: Development Status :: 1 - Planning
12
+ Classifier: Environment :: Console
13
+ Classifier: Natural Language :: Japanese
14
+ Classifier: Natural Language :: English
15
+ Classifier: Topic :: Text Processing
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.txt
19
+ Requires-Dist: PyYAML
20
+ Dynamic: license-file
21
+
22
+ # fileの説明
23
+ # 原文
24
+ [Original README](docs/README_JP.md)
25
+
26
+ ## /docs
27
+ documentを格納するdirecotry.
28
+
29
+ ## /src
30
+ ここでmoduleを開発する。
31
+
32
+ ## testUnit
33
+ 単体testを行うdirectory。
34
+
35
+ ## testSystem
36
+ 結合testを行うdirectory。
37
+
38
+ ## sanbox.py
39
+ pythonの挙動を確認する。
40
+
41
+
42
+
@@ -0,0 +1,12 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ src/anoyError.py
5
+ src/cli.py
6
+ src/dictTraversal.py
7
+ src/anoy.egg-info/PKG-INFO
8
+ src/anoy.egg-info/SOURCES.txt
9
+ src/anoy.egg-info/dependency_links.txt
10
+ src/anoy.egg-info/entry_points.txt
11
+ src/anoy.egg-info/requires.txt
12
+ src/anoy.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ anoy = cli:main
@@ -0,0 +1 @@
1
+ PyYAML
@@ -0,0 +1,4 @@
1
+ anoyError
2
+ cli
3
+ dictTraversal
4
+ unused
@@ -0,0 +1,29 @@
1
+
2
+ class AnnotationYamlError(Exception):
3
+ """
4
+ @Summ: annotation yaml上のError。
5
+ """
6
+ def __init__(self, *args):
7
+ super().__init__(*args)
8
+
9
+
10
+ class AnnotationYamlTypeError(Exception):
11
+ """
12
+ @Summ: annotation yaml上のdata型のError。
13
+ """
14
+ def __init__(self,type:str,path:list):
15
+ super().__init__()
16
+ self.type=type
17
+ self.path=path
18
+
19
+ def __str__(self):
20
+ return f"required {self.type} type at:\n {self.path}"
21
+
22
+
23
+ class ConfigurationYamlError(Exception):
24
+ """
25
+ @Summ: annotation yaml上のError。
26
+ """
27
+ def __init__(self, *args):
28
+ super().__init__(*args)
29
+
anoy-0.1.0/src/cli.py ADDED
@@ -0,0 +1,32 @@
1
+ import sys
2
+ from pathlib import Path
3
+ import argparse
4
+ import yaml
5
+
6
+ from .dictTraversal import DictTraversal
7
+
8
+ VERSION="v0.1.0"
9
+
10
+ def main():
11
+ """
12
+ "@Summ": CLIを処理するmain関数。
13
+ "@Desc": 引数は標準入力から渡される。
14
+ """
15
+ parser=argparse.ArgumentParser(prog="PROG")
16
+ parser.add_argument("-v","--version", action="version", version=f"anoy {VERSION}")
17
+ parser.add_argument("config", type=str, default=None, help="Put in configuration yaml.")
18
+ parser.add_argument("anoy", type=str, default=None, help="Put in annotation yaml.")
19
+ args=parser.parse_args()
20
+ configPath=Path(args.config)
21
+ anoyPath=Path(args.anoy)
22
+ with open(configPath,mode="r",encoding="utf-8") as f:
23
+ configDict=yaml.safe_load(f)
24
+ with open(anoyPath,mode="r",encoding="utf-8") as f:
25
+ anoyDict=yaml.safe_load(f)
26
+ print("loadEnd")
27
+ tree01=DictTraversal(configDict)
28
+ tree01.startBFS(anoyDict)
29
+
30
+ if(__name__=="__main__"):
31
+ main()
32
+
@@ -0,0 +1,187 @@
1
+ import yaml
2
+
3
+ from .anoyError import AnnotationYamlError,ConfigurationYamlError,AnnotationYamlTypeError
4
+
5
+ class DictTraversal():
6
+ """
7
+ @Summ: 辞書型の中身を探索するclass
8
+
9
+ @InsVars:
10
+ _configDict:
11
+ @Summ: configuration yamlの中身。
12
+ @Type: Dict
13
+ _configVisit:
14
+ @Summ: configuration yaml内のannotationKeyを使った否かを記録する変数。
15
+ @Desc: {annotationKey(str):訪れた⇒True(bool)}
16
+ @Type: Dict
17
+ _visitQueue:
18
+ @Summ: 探索queue
19
+ @Desc: BFSなのでFIFO。
20
+ @Type: List
21
+ _pathQueue:
22
+ @Summ: 探索する要素の相対pathを格納する。
23
+ @Desc:
24
+ - visitQueueと要素番号を共有する。
25
+ - []でroot要素を表す。
26
+ @Type: List
27
+ """
28
+ def __init__(self,configDict:dict):
29
+ """
30
+ @Summ: constructor.
31
+ """
32
+ self._configDict=configDict
33
+ self._visitQueue=[]
34
+ self._pathQueue=[]
35
+ self._configVisit={key:False for key in configDict.keys()}
36
+
37
+ def startBFS(self,anoyDict:dict):
38
+ """
39
+ @Summ: 幅優先探索を開始する関数。
40
+
41
+ @Desc:
42
+ - list型は単純に探索する。
43
+ - dict型は型確認しながら探索する。
44
+ - visitQueueには(key(str),value(any))のtupleを入れる。
45
+ - list型の時は、(key(int),value(any))になる。
46
+ @Args:
47
+ anoyDict:
48
+ @Summ: annotation yamlのdict型。
49
+ """
50
+ self._visitQueue=[(None,anoyDict)]
51
+ self._pathQueue=[[]]
52
+ while(True):
53
+ if(self._visitQueue==[]):
54
+ break
55
+ key,value=self._visitQueue.pop(0)
56
+ pathList=self._pathQueue.pop(0)
57
+ print(key,value)
58
+ print(pathList)
59
+ self.typeCheck(key,value,pathList)
60
+
61
+ def typeCheck(self,parentKey:str|None,childValue,path:list):
62
+ """
63
+ "@Summ": annoDict内を探索する関数。
64
+
65
+ "@Desc":
66
+ - 型確認は"!ParentKey"と"!ChildValue"の2つだ。
67
+ - annotationKeyが親でない時は、"!ParentKey"も"!ChildValue"も効力を発揮しないので無視。
68
+ - ただし、annoKeyがNoneの時は、"!ParentKey"が効力を発揮する場合がある。
69
+ - !ChildValueが無い時は何もしない。
70
+ - !ChildValueが無い時は、childValue=nullとして考える。
71
+ - valueがanoyDict型の時のみ、!ParentKeyの型確認が行われる。
72
+
73
+ "@Args":
74
+ parentKey:
75
+ "@Summ": 探索するdict型のkey。
76
+ "@Desc":
77
+ - nullは親要素が存在しないことを表す(つまりvalueがroot要素である)。
78
+ "@Type":
79
+ Union:
80
+ - Str
81
+ - null
82
+ childValue:
83
+ "@Summ": 探索するdict型のvalue。
84
+ "@Type": Any
85
+ path:
86
+ @Summ: 今まで経由したkeyのlist。
87
+ @Type: List
88
+ "@Error":
89
+ - AnnotationYamlError
90
+ - AnnotationYamlTypeError
91
+ - ConfigurationYamlError
92
+ """
93
+ if(parentKey is None):
94
+ confChildVal=None #confChild=Noneの時は型確認をしない。
95
+ elif(type(parentKey)!=str):
96
+ confChildVal=None
97
+ elif(parentKey[0]=="@"):
98
+ confChild=self._configDict.get(parentKey)
99
+ if(confChild is None):
100
+ raise ConfigurationYamlError(f"`{parentKey}` is not defined.")
101
+ confChildVal=confChild.get("!ChildValue")
102
+ else:
103
+ confChildVal=None
104
+ if(type(confChildVal)==dict):
105
+ #Enum型の型確認。
106
+ # config yaml側の型確認。
107
+ confKeyList=list(confChildVal.keys())
108
+ if(len(confKeyList)!=1 or confKeyList[0]!="Enum"):
109
+ raise ConfigurationYamlError(f"`{parentKey}` has invalid definition.")
110
+ confValueList=confChildVal["Enum"]
111
+ if(type(confValueList)!=list):
112
+ raise ConfigurationYamlError(f"`{parentKey}` has invalid definition.")
113
+ # annotaion yaml側の型確認。
114
+ for i in range(len(confValueList)):
115
+ if(childValue==confValueList[i]):
116
+ return
117
+ raise AnnotationYamlTypeError("Enum",path)
118
+ elif(type(childValue)==bool):
119
+ if((confChildVal is None) or confChildVal=="Bool"):
120
+ return
121
+ else:
122
+ raise AnnotationYamlTypeError("Bool",path)
123
+ elif(type(childValue)==str):
124
+ if((confChildVal is None or confChildVal=="Str")):
125
+ return
126
+ else:
127
+ raise AnnotationYamlTypeError("Str",path)
128
+ elif(type(childValue)==int):
129
+ if((confChildVal is None) or confChildVal=="Int"):
130
+ return
131
+ else:
132
+ raise AnnotationYamlTypeError("Int",path)
133
+ elif(type(childValue)==float):
134
+ if((confChildVal is None) or confChildVal=="Float"):
135
+ return
136
+ else:
137
+ raise AnnotationYamlTypeError("Float",path)
138
+ elif(type(childValue)==list):
139
+ if((confChildVal is None) or confChildVal=="List"):
140
+ for i in range(len(childValue)):
141
+ newPath=path+[i]
142
+ self._visitQueue.append((i,childValue[i]))
143
+ self._pathQueue.append(newPath)
144
+ return
145
+ else:
146
+ raise AnnotationYamlTypeError("List",path)
147
+ elif(type(childValue)==dict):
148
+ if(confChildVal is None):
149
+ for key,childValue in childValue.items():
150
+ newPath=path+[key]
151
+ self._visitQueue.append((key,childValue))
152
+ self._pathQueue.append(newPath)
153
+ return
154
+ elif(confChildVal=="FreeDict"):
155
+ for key,childValue in childValue.items():
156
+ newPath=path+[key]
157
+ self._visitQueue.append((key,childValue))
158
+ self._pathQueue.append(newPath)
159
+ if(key[0]=="@"):
160
+ raise AnnotationYamlTypeError("FreeDict",path)
161
+ return
162
+ elif(confChildVal=="AnnoDict"):
163
+ for key,childValue in childValue.items():
164
+ newPath=path+[key]
165
+ self._visitQueue.append((key,childValue))
166
+ self._pathQueue.append(newPath)
167
+ confParent=self._configDict[key].get("!ParentKey")
168
+ if(key[0]!="@"):
169
+ raise AnnotationYamlTypeError("AnnoDict",path)
170
+ if(confParent is None):
171
+ pass
172
+ elif(parentKey not in confParent):
173
+ raise AnnotationYamlTypeError("AnnoDict",path)
174
+ return
175
+ else:
176
+ raise AnnotationYamlError(f" invalid value is found at:\n `{path}`.")
177
+
178
+ if(__name__=="__main__"):
179
+ configPath=r"C:\Users\tomot\Backup\sourcecode\python\projects\annotation_yaml\tests\unit\case01\config01.yaml"
180
+ anoyPath=r"C:\Users\tomot\Backup\sourcecode\python\projects\annotation_yaml\tests\unit\case01\int_false.yaml"
181
+ with open(configPath,mode="r",encoding="utf-8") as f:
182
+ configDict=yaml.safe_load(f)
183
+ with open(anoyPath,mode="r",encoding="utf-8") as f:
184
+ anoyDict=yaml.safe_load(f)
185
+ tree01=DictTraversal(configDict)
186
+ tree01.startBFS(anoyDict)
187
+