anoy 0.2.1a1__py3-none-any.whl → 0.3.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anoy
3
- Version: 0.2.1a1
3
+ Version: 0.3.1
4
4
  Summary: This is a library that provides simple type checking for YAML.
5
5
  Author-email: masaniki <masaniki.software@gmail.com>
6
6
  License-Expression: MIT
@@ -76,16 +76,16 @@ library_config.yaml
76
76
  ```
77
77
  "@Books":
78
78
  "@Summary": List the book titles.
79
- "!ChildValue": FreeDict
79
+ "!Child": "!FreeMap"
80
80
  "@Author":
81
81
  "@Summary": Author of the book.
82
- "!ChildValue": Str
82
+ "!Child": "!Str"
83
83
  "@PublishYear":
84
84
  "@Summary": The year of the publishment.
85
- "!ChildValue": Int
85
+ "!Child": "!Int"
86
86
  "@Country":
87
87
  "@Summary": The author's native language.
88
- "!ChildValue": Str
88
+ "!Child": "!Str"
89
89
  ```
90
90
 
91
91
  valid_library.yaml:
@@ -141,7 +141,7 @@ When there is an issue with the annotation YAML, `anoy` outputs as follows.
141
141
  >>> anoy library_config.yaml library.yaml
142
142
  >>> Traceback (most recent call last):
143
143
  ... (omission) ...
144
- src.anoyModule.anoyErrors.ConfigurationYamlError: `@Auther` is not defined.
144
+ src.anoyModule.anoyErrors.ConfigYamlError: `@Auther` is not defined.
145
145
  ```
146
146
  # For Developers
147
147
 
@@ -155,10 +155,7 @@ If you want to test, put in following command.
155
155
 
156
156
  ## Next To Do
157
157
 
158
- - [ ] test caseを全てのdata型に拡大。
159
- - [ ] `!Float`のtest.
160
- - [ ] `!AnnoMap`のtest.
161
- - [ ] `!FreeMap`のtest.
158
+ - [x] READMEの詳細documentの更新。
162
159
 
163
160
  ## Ideas
164
161
 
@@ -0,0 +1,10 @@
1
+ cli.py,sha256=C1fgYhoZ1vvcBgfsZF1CCtcJSNlT4YVS_qZZ5QVkdc0,912
2
+ anoy-0.3.1.dist-info/licenses/LICENSE.txt,sha256=nsHvySI1U7YZgAX4K3rJsWli_GfXy2syPI-MtGPwjlo,1062
3
+ modules/__init__.py,sha256=WSvUse7H-6ConliG5plmNLGHjeHWXqHR9t901plrWM0,133
4
+ modules/dictTraversal.py,sha256=5xMEe1jfhA4ZnjABfUPkWk2u3OuW3Toaq50Tsed4m74,28228
5
+ modules/errors.py,sha256=P9KwBhPdPGdujCMA00Ep37RvPLwGYsNip4RidT7oMdg,2091
6
+ anoy-0.3.1.dist-info/METADATA,sha256=hliKmzPvY0WX86yif_GGF3nrkCA1lVY7sxA1jaWbwzs,3873
7
+ anoy-0.3.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ anoy-0.3.1.dist-info/entry_points.txt,sha256=_lpL6R97giGseZcV0r5QwdX4zRwoZLzRHUxyBZl_iYI,34
9
+ anoy-0.3.1.dist-info/top_level.txt,sha256=jfF8JYDvxB66wJSH2sWhdDiR0GGzxt5x-1k2vxwZKqA,12
10
+ anoy-0.3.1.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ cli
2
+ modules
cli.py CHANGED
@@ -3,9 +3,9 @@ from pathlib import Path
3
3
  import argparse
4
4
  import yaml
5
5
 
6
- from anoyModule import DictTraversal
6
+ from modules import DictTraversal
7
7
 
8
- VERSION="v0.2.1a1"
8
+ VERSION="v0.3.1"
9
9
 
10
10
  def main():
11
11
  """
modules/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+
2
+ from .dictTraversal import DictTraversal
3
+ from .errors import AnoyError, AnnotationKeyError, AnnotationTypeError, ConfigYamlError
@@ -1,7 +1,7 @@
1
1
  import yaml
2
2
  from pathlib import Path
3
3
 
4
- from .anoyErrors import AnoyError,ConfigYamlError,AnoyTypeError
4
+ from .errors import AnnotationKeyError,AnnotationTypeError,ConfigYamlError
5
5
 
6
6
  class DictTraversal():
7
7
  """
@@ -28,13 +28,12 @@ class DictTraversal():
28
28
  - visitQueueと要素番号を共有する。
29
29
  - []でroot要素を表す。
30
30
  @Type: List
31
- _curFile:
31
+ _curAnoy:
32
32
  @Summ: 現在探索中のANOY file名。
33
- @ComeFrom: current file.
33
+ @ComeFrom: current ANOY.
34
34
  @Type: Str
35
- _curPath:
36
- @Summ: _curFile内での現在地。
37
- @ComeFrom: current path/
35
+ _anoyPath:
36
+ @Summ: _curAnoy内での現在地。
38
37
  @Type: List
39
38
  """
40
39
 
@@ -43,11 +42,11 @@ class DictTraversal():
43
42
  @Summ: constructor.
44
43
  """
45
44
  self._configDict=self.checkConfig(configDict)
46
- print(self._configDict)
45
+ # print(self._configDict)
47
46
  self._visitQueue=[]
48
47
  self._pathQueue=[]
49
- self._curFile=""
50
- self._curPath=[]
48
+ self._curAnoy=""
49
+ self._anoyPath=[]
51
50
 
52
51
  def checkConfig(self,configDict:dict)->dict:
53
52
  """
@@ -68,12 +67,16 @@ class DictTraversal():
68
67
  newConfigDict={} # 整形されたconfigDict
69
68
  for annoKey in configDict.keys():
70
69
  newAnnoValue={} #annotation keyに対応する値。
71
- if(annoKey[0]!="@"):
72
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
70
+ if(type(annoKey)!=str):
71
+ raise ConfigYamlError([annoKey],"Annotaion key should start with `@`.")
72
+ elif(annoKey[0]!="@"):
73
+ raise ConfigYamlError([annoKey],"Annotaion key should start with `@`.")
73
74
  valueDict=configDict[annoKey]
74
75
  if(type(valueDict)!=dict):
75
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
76
+ raise ConfigYamlError([annoKey])
76
77
  for key,value in valueDict.items():
78
+ if(type(key)!=str):
79
+ raise ConfigYamlError([annoKey,key], "Invalid value as !Parent.")
77
80
  if(key[0]=="@"):
78
81
  continue
79
82
  elif(key=="!Parent"):
@@ -83,7 +86,7 @@ class DictTraversal():
83
86
  validConfChild=self.checkChild(annoKey,value)
84
87
  newAnnoValue["!Child"]=validConfChild
85
88
  else:
86
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
89
+ raise ConfigYamlError([annoKey,key], "Invalid value as !Parent.")
87
90
  # isVisit keyの追加。
88
91
  newAnnoValue["isVisit"]=False
89
92
  newConfigDict[annoKey]=newAnnoValue
@@ -106,12 +109,12 @@ class DictTraversal():
106
109
  @Type: List
107
110
  """
108
111
  if(type(confParent)!=list):
109
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
112
+ raise ConfigYamlError([annoKey,"!Parent"])
110
113
  for item in confParent:
111
114
  if(item is None):
112
115
  continue
113
116
  if(item[0]!="@"):
114
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
117
+ raise ConfigYamlError([annoKey,"!Parent"])
115
118
  return confParent.copy()
116
119
 
117
120
  @classmethod
@@ -147,17 +150,17 @@ class DictTraversal():
147
150
  case "!AnnoMap":
148
151
  return {"!AnnoMap":[]}
149
152
  case _:
150
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
153
+ raise ConfigYamlError([annoKey,"!Child"])
151
154
  elif(type(confChild)==dict):
152
155
  confChildKey=list(confChild.keys())
153
156
  if(len(confChildKey)!=1):
154
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
157
+ raise ConfigYamlError([annoKey,"!Child"])
155
158
  typeStr=confChildKey[0]
156
159
  typeOption=confChild[typeStr]
157
160
  match typeStr:
158
161
  case "!Str":
159
162
  if(type(typeOption)!=dict):
160
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
163
+ raise ConfigYamlError([annoKey,"!Child","!Str"])
161
164
  strLength=None
162
165
  strMin=None
163
166
  strMax=None
@@ -167,23 +170,23 @@ class DictTraversal():
167
170
  if(strMin is None and strMax is None):
168
171
  strLength=strVal
169
172
  else:
170
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
173
+ raise ConfigYamlError([annoKey,"!Child","!Str","length"])
171
174
  case "min":
172
175
  if(strLength is None):
173
176
  strMin=strVal
174
177
  else:
175
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
178
+ raise ConfigYamlError([annoKey,"!Child","!Str","min"])
176
179
  case "max":
177
180
  if(strLength is None):
178
181
  strMax=strVal
179
182
  else:
180
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
183
+ raise ConfigYamlError([annoKey,"!Child","!Str","max"])
181
184
  case _:
182
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
185
+ raise ConfigYamlError([annoKey,"!Child","!Str"])
183
186
  return {"!Str":{"length":strLength,"min":strMin,"max":strMax}}
184
187
  case "!Int":
185
188
  if(type(typeOption)!=dict):
186
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
189
+ raise ConfigYamlError([annoKey,"!Child","!Str"], "Required `!Map` type.")
187
190
  intMin=None
188
191
  intMax=None
189
192
  for intKey,intVal in typeOption.items():
@@ -193,40 +196,44 @@ class DictTraversal():
193
196
  case "max":
194
197
  intMax=intVal
195
198
  case _:
196
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
199
+ raise ConfigYamlError([annoKey,"!Child","!Int"])
197
200
  return {"!Int":{"min":intMin,"max":intMax}}
198
201
  case "!Float":
199
202
  if(type(typeOption)!=dict):
200
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
203
+ raise ConfigYamlError([annoKey,"!Child","!Float"], "Required `!Map` type.")
201
204
  floatMin=None
202
205
  floatMax=None
203
206
  for floatKey,floatVal in typeOption.items():
204
207
  match floatKey:
205
208
  case "min":
209
+ if(type(floatVal)!=int and type(floatVal)!=float):
210
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
206
211
  floatMin=floatVal
207
212
  case "max":
213
+ if(type(floatVal)!=int and type(floatVal)!=float):
214
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
208
215
  floatMax=floatVal
209
216
  case _:
210
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
217
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
211
218
  return {"!Float":{"min":floatMin,"max":floatMax}}
212
219
  case "!Enum":
213
220
  if(type(typeOption)!=list):
214
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
221
+ raise ConfigYamlError([annoKey,"!Child","!Enum"])
215
222
  enumOption=[]
216
223
  for item in typeOption:
217
224
  if(type(item)==list):
218
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
225
+ raise ConfigYamlError([annoKey,"!Child","!Enum",item])
219
226
  elif(type(item)==dict):
220
227
  keyList=list(item.keys())
221
228
  if(len(keyList)!=1):
222
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
229
+ raise ConfigYamlError([annoKey,"!Child","!Enum",item])
223
230
  enumOption.append(keyList[0])
224
231
  else:
225
232
  enumOption.append(item)
226
233
  return {"!Enum":enumOption}
227
234
  case "!List":
228
235
  if(type(typeOption)!=dict):
229
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
236
+ raise ConfigYamlError([annoKey,"!Child","!List"])
230
237
  listType=None
231
238
  listLength=None
232
239
  for listKey,listVal in typeOption.items():
@@ -236,20 +243,22 @@ class DictTraversal():
236
243
  case "length":
237
244
  listLength=listVal
238
245
  case _:
239
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
246
+ raise ConfigYamlError([annoKey,"!Child","!List",listKey])
240
247
  return {"!List":{"type":listType,"length":listLength}}
241
- case "!AnnoDict":
248
+ case "!AnnoMap":
242
249
  if(type(typeOption)!=list):
243
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
244
- for i in len(typeOption):
250
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap"])
251
+ for i in range(len(typeOption)):
245
252
  item=typeOption[i]
246
- if(item[0]!="@"):
247
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
248
- return {"!AnnoDict":typeOption}
253
+ if(type(item)!=str):
254
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap",item])
255
+ elif(item[0]!="@"):
256
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap",item])
257
+ return {"!AnnoMap":typeOption}
249
258
  case _:
250
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
259
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap",item], "Unknown data type string.")
251
260
  else:
252
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
261
+ raise ConfigYamlError([annoKey,"!Child"])
253
262
 
254
263
 
255
264
  def dirDFS(self,anoyPath:Path):
@@ -270,7 +279,7 @@ class DictTraversal():
270
279
  if(suffix==".yaml" or suffix==".yml" or suffix==".anoy"):
271
280
  with open(anoyPath, mode="r", encoding="utf-8") as f:
272
281
  anoyDict=yaml.safe_load(f)
273
- self._curFile=anoyPath
282
+ self._curAnoy=anoyPath
274
283
  self.dictBFS(anoyDict)
275
284
  else:
276
285
  for childPath in anoyPath.iterdir():
@@ -296,9 +305,9 @@ class DictTraversal():
296
305
  if(self._visitQueue==[]):
297
306
  break
298
307
  key,value=self._visitQueue.pop(0)
299
- self._curPath=self._pathQueue.pop(0)
308
+ self._anoyPath=self._pathQueue.pop(0)
300
309
  print(key,value)
301
- print(self._curPath)
310
+ print(self._anoyPath)
302
311
  self.checkAnoy(key,value)
303
312
 
304
313
  def checkAnoy(self,parentKey:str|None,childValue):
@@ -337,22 +346,40 @@ class DictTraversal():
337
346
  elif(parentKey[0]=="@"):
338
347
  confDictVal=self._configDict.get(parentKey)
339
348
  if(confDictVal is None):
340
- raise AnoyError(f"{parentKey} is not found.")
349
+ raise AnnotationKeyError(self._curAnoy, self._anoyPath,parentKey)
341
350
  confChild=confDictVal.get("!Child")
342
351
  else:
343
352
  confChild=None
344
353
  # anoyの型確認
345
- if(confChild is None): #Noneの処理方法は不明。
354
+ if(confChild is None):
346
355
  # nestになるlistとdictだけ対処する。
347
356
  if(type(childValue)==list):
348
357
  for i in range(len(childValue)):
349
358
  element=childValue[i]
350
- newPath=self._curPath+[i]
359
+ newPath=self._anoyPath+[i]
351
360
  self._visitQueue.append((i,element))
352
361
  self._pathQueue.append(newPath)
353
362
  elif(type(childValue)==dict):
363
+ # !Child=nullであってもfree keyとannotation keyの混合は許さない。
364
+ # keyがstr型でない時は!FreeMapとして扱う。
365
+ isAnnoMap=None
354
366
  for key,value in childValue.items():
355
- newPath=self._curPath+[key]
367
+ if(type(key)!=str):
368
+ if(isAnnoMap is None):
369
+ isAnnoMap=False
370
+ elif(isAnnoMap==True):
371
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!AnnoMap")
372
+ elif(key[0]=="@"):
373
+ if(isAnnoMap is None):
374
+ isAnnoMap=True
375
+ elif(isAnnoMap==False):
376
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!FreeMap")
377
+ else:
378
+ if(isAnnoMap is None):
379
+ isAnnoMap=False
380
+ elif(isAnnoMap==True):
381
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!AnnoMap")
382
+ newPath=self._anoyPath+[key]
356
383
  self._visitQueue.append((key,value))
357
384
  self._pathQueue.append(newPath)
358
385
  return
@@ -376,7 +403,7 @@ class DictTraversal():
376
403
  case "!Enum":
377
404
  self.checkEnum(childValue,typeOption)
378
405
  case _:
379
- raise ConfigYamlError(f"{parentKey} is invalid definition.")
406
+ raise ConfigYamlError([parentKey,"!Child"])
380
407
 
381
408
  def checkStr(self,anoyValue,length=None,min=None,max=None):
382
409
  """
@@ -408,17 +435,17 @@ class DictTraversal():
408
435
  if(len(anoyValue)==length):
409
436
  return
410
437
  else:
411
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
438
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str",)
412
439
  else:
413
440
  if(min is not None):
414
441
  if(len(anoyValue)<min):
415
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
442
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
416
443
  if(max is not None):
417
444
  if(max<len(anoyValue)):
418
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
445
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
419
446
  return
420
447
  else:
421
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
448
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
422
449
 
423
450
  def checkBool(self,anoyValue):
424
451
  """
@@ -429,7 +456,7 @@ class DictTraversal():
429
456
  @Summ: 型確認する値。
430
457
  """
431
458
  if(type(anoyValue)!=bool):
432
- raise AnoyTypeError("!Bool",self._curFile,self._curPath)
459
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Bool")
433
460
 
434
461
  def checkInt(self,anoyValue,min=None,max=None):
435
462
  """
@@ -446,13 +473,13 @@ class DictTraversal():
446
473
  if(type(anoyValue)==int):
447
474
  if(min is not None):
448
475
  if(anoyValue<min):
449
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
476
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
450
477
  if(max is not None):
451
478
  if(max<anoyValue):
452
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
479
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
453
480
  return
454
481
  else:
455
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
482
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
456
483
 
457
484
  def checkFloat(self,anoyValue,min=None,max=None):
458
485
  """
@@ -463,19 +490,25 @@ class DictTraversal():
463
490
  @Summ: 型確認する値。
464
491
  min:
465
492
  @Summ: 最小値。
493
+ @Desc:
494
+ - `min<=annoyValue`の時にtrue.
495
+ @SemType: Int|Float
466
496
  max:
467
497
  @Summ: 最大値。
498
+ @Desc:
499
+ - `annoyValue<=max`の時にtrue.
500
+ @SemType: Int|Float
468
501
  """
469
- if(type(anoyValue)==float):
502
+ if(type(anoyValue)==int or type(anoyValue)==float):
470
503
  if(min is not None):
471
504
  if(anoyValue<min):
472
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
505
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
473
506
  if(max is not None):
474
507
  if(max<anoyValue):
475
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
508
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
476
509
  return
477
510
  else:
478
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
511
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
479
512
 
480
513
  def checkFreeMap(self,anoyValue):
481
514
  """
@@ -487,13 +520,14 @@ class DictTraversal():
487
520
  """
488
521
  if(type(anoyValue)==dict):
489
522
  for key,value in anoyValue.items():
490
- newPath=self._curPath+[key]
523
+ newPath=self._anoyPath+[key]
491
524
  self._visitQueue.append((key,value))
492
525
  self._pathQueue.append(newPath)
493
- if(key[0]=="@"):
494
- raise AnoyTypeError("!FreeMap",self._curFile,newPath)
526
+ if(type(key)==str):
527
+ if(key[0]=="@"):
528
+ raise AnnotationTypeError(self._curAnoy,newPath,"!FreeMap")
495
529
  else:
496
- raise AnoyTypeError("!FreeMap",self._curFile,self._curPath)
530
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!FreeMap")
497
531
 
498
532
  def checkAnnoMap(self,parentKey,anoyValue,annoKeyList:list=[]):
499
533
  """
@@ -510,28 +544,31 @@ class DictTraversal():
510
544
  anoyValue:
511
545
  @Summ: 型確認する値。
512
546
  annoKeyList:
513
- @Summ: annotation keyのlist。
547
+ @Summ: 子要素になれるannotation keyのlist。
548
+ @Desc:
549
+ - 空lsitの時は任意のannotation keyを受け入れる。
550
+ - これは全てのannotation keyが入ったlist型と同じ挙動をする。
514
551
  @Type: List
515
552
  @Default: []
516
553
  """
517
554
  if(type(anoyValue)==dict):
518
555
  for key,value in anoyValue.items():
519
- newPath=self._curPath+[key]
556
+ newPath=self._anoyPath+[key]
520
557
  self._visitQueue.append((key,value))
521
558
  self._pathQueue.append(newPath)
522
559
  # !Parentの確認。
523
560
  configValue=self._configDict.get(key)
524
561
  if(configValue is None):
525
- raise AnoyError(f"{parentKey} is not found.")
562
+ raise AnnotationKeyError(self._curAnoy,newPath,key)
526
563
  confParent=configValue.get("!Parent")
527
564
  if(confParent is not None):
528
565
  if(parentKey not in confParent):
529
- raise AnoyTypeError("!Parent",self._curFile,newPath)
566
+ raise AnnotationTypeError(self._curAnoy,newPath,"!Parent")
530
567
  if(annoKeyList!=[]):
531
568
  if(key not in annoKeyList):
532
- raise AnoyTypeError("!AnnoMap",self._curFile,self._curPath)
569
+ raise AnnotationTypeError(self._curAnoy,newPath,"!AnnoMap")
533
570
  else:
534
- raise AnoyTypeError("!AnnoMap",self._curFile,self._curPath)
571
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!AnnoMap")
535
572
 
536
573
  def checkList(self,parentKey,anoyValue,elementType:str=None,length:int=None):
537
574
  """
@@ -560,30 +597,30 @@ class DictTraversal():
560
597
  if(type(anoyValue)==list):
561
598
  if(length is not None):
562
599
  if(length!=len(anoyValue)):
563
- raise AnoyTypeError("!List",self._curFile,self._curPath)
600
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!List")
564
601
  for i in range(len(anoyValue)):
565
602
  element=anoyValue[i]
566
- newPath=self._curPath+[i]
603
+ newPath=self._anoyPath+[i]
567
604
  if(elementType is not None):
568
605
  match elementType:
569
606
  case "!Str":
570
607
  if(type(element)!=str):
571
- raise AnoyTypeError("!List",self._curFile,newPath)
608
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
572
609
  case "!Bool":
573
610
  if(type(element)!=bool):
574
- raise AnoyTypeError("!List",self._curFile,newPath)
611
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
575
612
  case "!Int":
576
613
  if(type(element)!=int):
577
- raise AnoyTypeError("!List",self._curFile,newPath)
614
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
578
615
  case "!Float":
579
616
  if(type(element)!=float):
580
- raise AnoyTypeError("!List",self._curFile,newPath)
617
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
581
618
  case _:
582
- raise ConfigYamlError(f"{parentKey} is invalid definition.")
619
+ raise ConfigYamlError([parentKey,"!Child"])
583
620
  self._visitQueue.append((i,element))
584
621
  self._pathQueue.append(newPath)
585
622
  else:
586
- raise AnoyTypeError("!List",self._curFile,self._curPath)
623
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!List")
587
624
 
588
625
  def checkEnum(self,anoyValue,optionList:list):
589
626
  """
@@ -627,7 +664,7 @@ class DictTraversal():
627
664
  case _:
628
665
  if(anoyValue==option):
629
666
  return
630
- raise AnoyTypeError("!Enum",self._curFile,self._curPath)
667
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Enum")
631
668
 
632
669
 
633
670
  if(__name__=="__main__"):
modules/errors.py ADDED
@@ -0,0 +1,89 @@
1
+
2
+ class AnoyError(Exception):
3
+ """
4
+ @Summ: ANOYによる例外の基底class.
5
+
6
+ @InsVars:
7
+ fileName:
8
+ @Summ: 例外を発したanoyのfile名。
9
+ @Type: Str
10
+ yamlPath:
11
+ @Summ: 例外を発生した位置。
12
+ @SemType: Str型List
13
+ msg:
14
+ @Summ: 例外message.
15
+ @ComeFrom: message.
16
+ @Type: Str
17
+ """
18
+ def __init__(self,fileName:str,yamlPath:list,msg:str):
19
+ super().__init__()
20
+ self.fileName=fileName
21
+ self.yamlPath=yamlPath
22
+ self.msg=msg
23
+
24
+ def __str__(self):
25
+ return f"\n {self.fileName}: {self.yamlPath}:\n {self.msg}"
26
+
27
+ class AnnotationKeyError(AnoyError):
28
+ """
29
+ @Summ: annotation keyが存在しないことによるANOYの例外。
30
+
31
+ @Parent: AnoyError
32
+ """
33
+ def __init__(self,fileName:str,yamlPath:list,annoKey:str):
34
+ """
35
+ @Args:
36
+ fileName:
37
+ @Summ: pass
38
+ yamlPath:
39
+ @Summ: pass
40
+ annoKey:
41
+ @Summ: 例外の原因となったannotation key.
42
+ @Type: Str
43
+ """
44
+ msg=f"{annoKey} is not found."
45
+ super().__init__(fileName,yamlPath,msg)
46
+
47
+ class AnnotationTypeError(AnoyError):
48
+ """
49
+ @Summ: data型によるANOYの例外。
50
+
51
+ @Parent: AnoyError
52
+ """
53
+ def __init__(self,fileName:str,yamlPath:list,annoType:str):
54
+ """
55
+ @Args:
56
+ fileName:
57
+ @Summ: pass
58
+ yamlPath:
59
+ @Summ: pass
60
+ annoType:
61
+ @Summ: 例外の原因となったdata型名。
62
+ @Type: Str
63
+ """
64
+ msg=f"{annoType} contradiction."
65
+ super().__init__(fileName,yamlPath,msg)
66
+
67
+ class ConfigYamlError(Exception):
68
+ """
69
+ @Summ: config yamlによる例外の基底class.
70
+
71
+ @InsVars:
72
+ configPath:
73
+ @Summ: config yaml内のpath。
74
+ @Type: List
75
+ msg:
76
+ @Summ: 例外message.
77
+ @ComeFrom: message.
78
+ @Type: Str
79
+ @Default: ""
80
+ """
81
+ def __init__(self,configPath:list,msg:str=""):
82
+ super().__init__()
83
+ self.configPath=configPath
84
+ self.msg=msg
85
+
86
+ def __str__(self):
87
+ return f"\n {self.configPath}\n {self.msg}"
88
+
89
+
@@ -1,10 +0,0 @@
1
- cli.py,sha256=oMt-TZf7AtPXMKdrbZ2zaO-aaXpgxYdHMo9lFq9-iac,917
2
- anoy-0.2.1a1.dist-info/licenses/LICENSE.txt,sha256=nsHvySI1U7YZgAX4K3rJsWli_GfXy2syPI-MtGPwjlo,1062
3
- anoyModule/__init__.py,sha256=iWletkxm7jDc7oFqp4yDS_4fUYZBny04q2VxkTpIDHo,111
4
- anoyModule/anoyErrors.py,sha256=2DST9_IenRIyXsABl6vWhMU0D5wqJ2aSs7zkm0DABm4,646
5
- anoyModule/dictTraversal.py,sha256=LF8T1ZIcWzzpUiBL6ewlvlYCHLttaFjXMdo5kSZB_sA,26055
6
- anoy-0.2.1a1.dist-info/METADATA,sha256=-uj9Hpl2Gf0GnzScaAHZI4FoD41HHEjMsOfGzTcqJvs,3972
7
- anoy-0.2.1a1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
- anoy-0.2.1a1.dist-info/entry_points.txt,sha256=_lpL6R97giGseZcV0r5QwdX4zRwoZLzRHUxyBZl_iYI,34
9
- anoy-0.2.1a1.dist-info/top_level.txt,sha256=QExj2OlPPcJU_7B1gwNcL2iYOcgYJBpDZsUArRCaXJw,15
10
- anoy-0.2.1a1.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- anoyModule
2
- cli
anoyModule/__init__.py DELETED
@@ -1,3 +0,0 @@
1
-
2
- from .dictTraversal import DictTraversal
3
- from .anoyErrors import AnoyError, AnoyTypeError, ConfigYamlError
anoyModule/anoyErrors.py DELETED
@@ -1,29 +0,0 @@
1
-
2
- class AnoyError(Exception):
3
- """
4
- @Summ: annotation yaml上のError。
5
- """
6
- def __init__(self, *args):
7
- super().__init__(*args)
8
-
9
-
10
- class AnoyTypeError(Exception):
11
- """
12
- @Summ: annotation yaml上のdata型のError。
13
- """
14
- def __init__(self,type:str,fileName:str,path:list):
15
- super().__init__()
16
- self.type=type
17
- self.fileName=fileName
18
- self.path=path
19
-
20
- def __str__(self):
21
- return f"{self.type} contradiction:\n {self.fileName}: {self.path}"
22
-
23
- class ConfigYamlError(Exception):
24
- """
25
- @Summ: annotation yaml上のError。
26
- """
27
- def __init__(self, *args):
28
- super().__init__(*args)
29
-
File without changes