anoy 0.1.1__py3-none-any.whl → 0.1.3__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.
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.4
2
+ Name: anoy
3
+ Version: 0.1.3
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
+ # Index
23
+
24
+ - **English Document**
25
+
26
+ English Document <- Here
27
+
28
+ - **Japanese Document**
29
+
30
+ [Japanese Document](docs/README_JP.md)
31
+
32
+ - **Annotation YAML(ANOY)**
33
+
34
+ A YAML file that allows type checking for Map types.
35
+
36
+ More about [ANOY](about_anoy.md)
37
+
38
+ - **Configuration YAML(Config YAML)**
39
+
40
+ A YAML file that defines the data types usable in Annotation YAML.
41
+
42
+ More about [Config YAML](about_config.md)
43
+
44
+ - **ANOY CLI**
45
+
46
+ A CLI application that verifies whether Annotation YAML adheres to the data type defined in Configuration YAML.
47
+
48
+ More about [ANOY CLI](about_anoycli.md)
49
+
50
+ # Introduction
51
+
52
+ YAML maps often become nested and complex.
53
+
54
+ And these requests have come up.
55
+
56
+ - Detecting typos in map keys.
57
+ - Verifying the data type of map values.
58
+ - Ensuring the map's nested structure is appropriate.
59
+
60
+ This library satisfies these requests.
61
+
62
+ # Installing
63
+
64
+ `pip install anoy`
65
+
66
+ ## Package Dependencies
67
+
68
+ The following packages may not work properly if they are not installed:
69
+
70
+ - [PyYAML](https://pypi.org/project/PyYAML/): Most popular YAML parser for Python.
71
+
72
+ # Usage
73
+
74
+ library_config.yaml
75
+
76
+ ```
77
+ "@Books":
78
+ "@Summary": List the book titles.
79
+ "!ChildValue": FreeDict
80
+ "@Author":
81
+ "@Summary": Author of the book.
82
+ "!ChildValue": Str
83
+ "@PublishYear":
84
+ "@Summary": The year of the publishment.
85
+ "!ChildValue": Int
86
+ "@Country":
87
+ "@Summary": The author's native language.
88
+ "!ChildValue": Str
89
+ ```
90
+
91
+ valid_library.yaml:
92
+
93
+ ```
94
+ "@Books":
95
+ "Alice's Adventures in Wonderland":
96
+ "@Author": Lewis Carroll
97
+ "@PublishYear": 1865
98
+ "@Country": UK
99
+ "The Little Prince":
100
+ "@Author": Antonie de Saint-Exupéry
101
+ "@PublishYear": 1945
102
+ "@Country": France
103
+ "Harry Potter":
104
+ "@Author": J.K.Rowling
105
+ "@PublishYear": 1997
106
+ "@Country": UK
107
+ ```
108
+
109
+ Use the `anoy` command to verify data types.
110
+
111
+ If data type issues are not found, it outputs nothing.
112
+
113
+ ```
114
+ >>> anoy library_config.yaml library.yaml
115
+ >>>
116
+ ```
117
+
118
+ If you mistyped `@Auther` as `@Auther`.
119
+
120
+ invalid_library.yaml:
121
+
122
+ ```
123
+ "@Books":
124
+ "Alice's Adventures in Wonderland":
125
+ "@Auther": Lewis Carroll
126
+ "@PublishYear": 1865
127
+ "@Country": UK
128
+ "The Little Prince":
129
+ "@Auther": Antonie de Saint-Exupéry
130
+ "@PublishYear": 1945
131
+ "@Country": France
132
+ "Harry Potter":
133
+ "@Auther": J.K.Rowling
134
+ "@PublishYear": 1997
135
+ "@Country": UK
136
+ ```
137
+
138
+ When there is an issue with the annotation YAML, `anoy` outputs as follows.
139
+
140
+ ```
141
+ >>> anoy library_config.yaml library.yaml
142
+ >>> Traceback (most recent call last):
143
+ ... (omission) ...
144
+ src.anoyModule.anoyErrors.ConfigurationYamlError: `@Auther` is not defined.
145
+ ```
146
+ # For Developpers
147
+
148
+ ## Testing
149
+
150
+ This project uses `pytest`.
151
+
152
+ If you want to test, put in following command.
153
+
154
+ `pytest tests\unit\test_dictTraversal.py`
@@ -0,0 +1,10 @@
1
+ cli.py,sha256=MtIL8GzwIX4aAY-gSFQpQBNTrc7N6nAm3fNduRyLGsk,915
2
+ anoy-0.1.3.dist-info/licenses/LICENSE.txt,sha256=nsHvySI1U7YZgAX4K3rJsWli_GfXy2syPI-MtGPwjlo,1062
3
+ anoyModule/__init__.py,sha256=5IrwCaYeugSDOmdYH4DMHqqeIQw86-Vkn46s29JZSww,138
4
+ anoyModule/anoyErrors.py,sha256=QvjhIVhSGMO5YMHxMmTw4LxtwwUWd4H8dxHDnbckawU,676
5
+ anoyModule/dictTraversal.py,sha256=yovTO6BAtxh2WwWgzmLK23IDY8HBkdfbx2WJo4Dl9zY,9086
6
+ anoy-0.1.3.dist-info/METADATA,sha256=ZOawgugs08QQMVK-S-sSycxQzXvoiRQ_r9CjNTNdOo0,3664
7
+ anoy-0.1.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ anoy-0.1.3.dist-info/entry_points.txt,sha256=_lpL6R97giGseZcV0r5QwdX4zRwoZLzRHUxyBZl_iYI,34
9
+ anoy-0.1.3.dist-info/top_level.txt,sha256=QExj2OlPPcJU_7B1gwNcL2iYOcgYJBpDZsUArRCaXJw,15
10
+ anoy-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ anoyModule
2
+ cli
anoyModule/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+
2
+ from .dictTraversal import DictTraversal
3
+ from .anoyErrors import AnnotationYamlError, AnnotationYamlTypeError, ConfigurationYamlError
@@ -11,14 +11,14 @@ class AnnotationYamlTypeError(Exception):
11
11
  """
12
12
  @Summ: annotation yaml上のdata型のError。
13
13
  """
14
- def __init__(self,type:str,path:list):
14
+ def __init__(self,fileName:str,type:str,path:list):
15
15
  super().__init__()
16
+ self.fileName=fileName
16
17
  self.type=type
17
18
  self.path=path
18
19
 
19
20
  def __str__(self):
20
- return f"required {self.type} type at:\n {self.path}"
21
-
21
+ return f"required {self.type} type at:\n {self.fileName}: {self.path}"
22
22
 
23
23
  class ConfigurationYamlError(Exception):
24
24
  """
@@ -1,6 +1,7 @@
1
1
  import yaml
2
+ from pathlib import Path
2
3
 
3
- from .anoyError import AnnotationYamlError,ConfigurationYamlError,AnnotationYamlTypeError
4
+ from .anoyErrors import AnnotationYamlError,ConfigurationYamlError,AnnotationYamlTypeError
4
5
 
5
6
  class DictTraversal():
6
7
  """
@@ -24,6 +25,10 @@ class DictTraversal():
24
25
  - visitQueueと要素番号を共有する。
25
26
  - []でroot要素を表す。
26
27
  @Type: List
28
+ _curAnoy:
29
+ @Summ: 現在探索中のANOY file.
30
+ @ComeFrom: current ANOY.
31
+ @Type: Str
27
32
  """
28
33
  def __init__(self,configDict:dict):
29
34
  """
@@ -33,10 +38,37 @@ class DictTraversal():
33
38
  self._visitQueue=[]
34
39
  self._pathQueue=[]
35
40
  self._configVisit={key:False for key in configDict.keys()}
41
+ self._curAnoy=""
36
42
 
37
- def startBFS(self,anoyDict:dict):
43
+
44
+ def dirDFS(self,anoyPath:Path):
45
+ """
46
+ @Summ: directory内を深さ優先探索する関数。
47
+
48
+ @Desc:
49
+ - fileならばYAMLかどうかを確認して、内部のdict型を探索する。
50
+ - directoryならば、子要素を再帰的に探索する。
51
+
52
+ @Args:
53
+ anoyPath:
54
+ @Summ: 探索するfileやdirectoryのpath名。
55
+ @Type: Path
56
+ """
57
+ if(anoyPath.is_file()):
58
+ suffix=anoyPath.suffix
59
+ if(suffix==".yaml" or suffix==".yml" or suffix==".anoy"):
60
+ with open(anoyPath, mode="r", encoding="utf-8") as f:
61
+ anoyDict=yaml.safe_load(f)
62
+ self._curAnoy=anoyPath
63
+ self.dictBFS(anoyDict)
64
+ else:
65
+ for childPath in anoyPath.iterdir():
66
+ self.dirDFS(childPath)
67
+
68
+
69
+ def dictBFS(self,anoyDict:dict):
38
70
  """
39
- @Summ: 幅優先探索を開始する関数。
71
+ @Summ: anoyDictの中を幅優先探索を開始する関数。
40
72
 
41
73
  @Desc:
42
74
  - list型は単純に探索する。
@@ -54,8 +86,8 @@ class DictTraversal():
54
86
  break
55
87
  key,value=self._visitQueue.pop(0)
56
88
  pathList=self._pathQueue.pop(0)
57
- print(key,value)
58
- print(pathList)
89
+ # print(key,value)
90
+ # print(pathList)
59
91
  self.typeCheck(key,value,pathList)
60
92
 
61
93
  def typeCheck(self,parentKey:str|None,childValue,path:list):
@@ -114,27 +146,27 @@ class DictTraversal():
114
146
  for i in range(len(confValueList)):
115
147
  if(childValue==confValueList[i]):
116
148
  return
117
- raise AnnotationYamlTypeError("Enum",path)
149
+ raise AnnotationYamlTypeError(str(self._curAnoy),"Enum",path)
118
150
  elif(type(childValue)==bool):
119
151
  if((confChildVal is None) or confChildVal=="Bool"):
120
152
  return
121
153
  else:
122
- raise AnnotationYamlTypeError("Bool",path)
154
+ raise AnnotationYamlTypeError(str(self._curAnoy),"Bool",path)
123
155
  elif(type(childValue)==str):
124
156
  if((confChildVal is None or confChildVal=="Str")):
125
157
  return
126
158
  else:
127
- raise AnnotationYamlTypeError("Str",path)
159
+ raise AnnotationYamlTypeError(str(self._curAnoy),type="Str",path=path)
128
160
  elif(type(childValue)==int):
129
161
  if((confChildVal is None) or confChildVal=="Int"):
130
162
  return
131
163
  else:
132
- raise AnnotationYamlTypeError("Int",path)
164
+ raise AnnotationYamlTypeError(str(self._curAnoy),"Int",path)
133
165
  elif(type(childValue)==float):
134
166
  if((confChildVal is None) or confChildVal=="Float"):
135
167
  return
136
168
  else:
137
- raise AnnotationYamlTypeError("Float",path)
169
+ raise AnnotationYamlTypeError(str(self._curAnoy),"Float",path)
138
170
  elif(type(childValue)==list):
139
171
  if((confChildVal is None) or confChildVal=="List"):
140
172
  for i in range(len(childValue)):
@@ -143,7 +175,7 @@ class DictTraversal():
143
175
  self._pathQueue.append(newPath)
144
176
  return
145
177
  else:
146
- raise AnnotationYamlTypeError("List",path)
178
+ raise AnnotationYamlTypeError(str(self._curAnoy),"List",path)
147
179
  elif(type(childValue)==dict):
148
180
  if(confChildVal is None):
149
181
  for key,childValue in childValue.items():
@@ -157,7 +189,7 @@ class DictTraversal():
157
189
  self._visitQueue.append((key,childValue))
158
190
  self._pathQueue.append(newPath)
159
191
  if(key[0]=="@"):
160
- raise AnnotationYamlTypeError("FreeDict",path)
192
+ raise AnnotationYamlTypeError(str(self._curAnoy),"FreeDict",path)
161
193
  return
162
194
  elif(confChildVal=="AnnoDict"):
163
195
  for key,childValue in childValue.items():
@@ -166,14 +198,14 @@ class DictTraversal():
166
198
  self._pathQueue.append(newPath)
167
199
  confParent=self._configDict[key].get("!ParentKey")
168
200
  if(key[0]!="@"):
169
- raise AnnotationYamlTypeError("AnnoDict",path)
201
+ raise AnnotationYamlTypeError(str(self._curAnoy),"AnnoDict",path)
170
202
  if(confParent is None):
171
203
  pass
172
204
  elif(parentKey not in confParent):
173
- raise AnnotationYamlTypeError("AnnoDict",path)
205
+ raise AnnotationYamlTypeError(str(self._curAnoy),"AnnoDict",path)
174
206
  return
175
207
  else:
176
- raise AnnotationYamlError(f" invalid value is found at:\n `{path}`.")
208
+ raise AnnotationYamlError(f" invalid value is found at:\n {str(self._curAnoy)}: `{path}`.")
177
209
 
178
210
  if(__name__=="__main__"):
179
211
  configPath=r"C:\Users\tomot\Backup\sourcecode\python\projects\annotation_yaml\tests\unit\case01\config01.yaml"
@@ -183,5 +215,5 @@ if(__name__=="__main__"):
183
215
  with open(anoyPath,mode="r",encoding="utf-8") as f:
184
216
  anoyDict=yaml.safe_load(f)
185
217
  tree01=DictTraversal(configDict)
186
- tree01.startBFS(anoyDict)
218
+ tree01.dictBFS(anoyDict)
187
219
 
cli.py CHANGED
@@ -3,9 +3,9 @@ from pathlib import Path
3
3
  import argparse
4
4
  import yaml
5
5
 
6
- from dictTraversal import DictTraversal
6
+ from anoyModule import DictTraversal
7
7
 
8
- VERSION="v0.1.1"
8
+ VERSION="v0.1.3"
9
9
 
10
10
  def main():
11
11
  """
@@ -21,11 +21,9 @@ def main():
21
21
  anoyPath=Path(args.anoy)
22
22
  with open(configPath,mode="r",encoding="utf-8") as f:
23
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
24
  tree01=DictTraversal(configDict)
28
- tree01.startBFS(anoyDict)
25
+ # configのload終了。
26
+ tree01.dirDFS(anoyPath)
29
27
 
30
28
  if(__name__=="__main__"):
31
29
  main()
@@ -1,42 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: anoy
3
- Version: 0.1.1
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
-
@@ -1,9 +0,0 @@
1
- anoyError.py,sha256=4smZo02X8YOv407FRyc12ADXW8foNrFr0pv0pRoQUxo,620
2
- cli.py,sha256=1NdYRb7UFGEctKSRCyh5UOlxM3UGLwVequtkybgYZoA,1005
3
- dictTraversal.py,sha256=KI4YH_XwUmydF-29-kasUbkOLqc6fthBdEavYsc9H8I,7794
4
- anoy-0.1.1.dist-info/licenses/LICENSE.txt,sha256=nsHvySI1U7YZgAX4K3rJsWli_GfXy2syPI-MtGPwjlo,1062
5
- anoy-0.1.1.dist-info/METADATA,sha256=jk0XCGbGl8vmc35RN937a_On9DzAgPNeoN3vELjV3PA,1130
6
- anoy-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
7
- anoy-0.1.1.dist-info/entry_points.txt,sha256=_lpL6R97giGseZcV0r5QwdX4zRwoZLzRHUxyBZl_iYI,34
8
- anoy-0.1.1.dist-info/top_level.txt,sha256=Ml0_35nDdV_uFyw0sUsvSho29qLH9ppoSOUQKuInsA4,28
9
- anoy-0.1.1.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- anoyError
2
- cli
3
- dictTraversal
File without changes