anoy 0.2.1a1__py3-none-any.whl → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anoy
3
- Version: 0.2.1a1
3
+ Version: 0.3.0
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=7_Lb8t4A3aGUnVXCkQJIKknz8L4zYo3Oy-1BsKxWi1w,912
2
+ anoy-0.3.0.dist-info/licenses/LICENSE.txt,sha256=nsHvySI1U7YZgAX4K3rJsWli_GfXy2syPI-MtGPwjlo,1062
3
+ modules/__init__.py,sha256=WSvUse7H-6ConliG5plmNLGHjeHWXqHR9t901plrWM0,133
4
+ modules/dictTraversal.py,sha256=6195pQMghpjbLNzdDNit3_FBYQ4dPykhRwRTmf8Vv5c,27455
5
+ modules/errors.py,sha256=P9KwBhPdPGdujCMA00Ep37RvPLwGYsNip4RidT7oMdg,2091
6
+ anoy-0.3.0.dist-info/METADATA,sha256=YZyydL2kbJcoHrppESmwaTtKKJkB4LhI56qbxfwCIdg,3873
7
+ anoy-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ anoy-0.3.0.dist-info/entry_points.txt,sha256=_lpL6R97giGseZcV0r5QwdX4zRwoZLzRHUxyBZl_iYI,34
9
+ anoy-0.3.0.dist-info/top_level.txt,sha256=jfF8JYDvxB66wJSH2sWhdDiR0GGzxt5x-1k2vxwZKqA,12
10
+ anoy-0.3.0.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.0"
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
  """
@@ -69,10 +68,10 @@ class DictTraversal():
69
68
  for annoKey in configDict.keys():
70
69
  newAnnoValue={} #annotation keyに対応する値。
71
70
  if(annoKey[0]!="@"):
72
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
71
+ raise ConfigYamlError([annoKey],"Annotaion key should start with `@`.")
73
72
  valueDict=configDict[annoKey]
74
73
  if(type(valueDict)!=dict):
75
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
74
+ raise ConfigYamlError([annoKey])
76
75
  for key,value in valueDict.items():
77
76
  if(key[0]=="@"):
78
77
  continue
@@ -83,7 +82,7 @@ class DictTraversal():
83
82
  validConfChild=self.checkChild(annoKey,value)
84
83
  newAnnoValue["!Child"]=validConfChild
85
84
  else:
86
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
85
+ raise ConfigYamlError([annoKey], "Unknown config key is found.")
87
86
  # isVisit keyの追加。
88
87
  newAnnoValue["isVisit"]=False
89
88
  newConfigDict[annoKey]=newAnnoValue
@@ -106,12 +105,12 @@ class DictTraversal():
106
105
  @Type: List
107
106
  """
108
107
  if(type(confParent)!=list):
109
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
108
+ raise ConfigYamlError([annoKey,"!Parent"])
110
109
  for item in confParent:
111
110
  if(item is None):
112
111
  continue
113
112
  if(item[0]!="@"):
114
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
113
+ raise ConfigYamlError([annoKey,"!Parent"])
115
114
  return confParent.copy()
116
115
 
117
116
  @classmethod
@@ -147,17 +146,17 @@ class DictTraversal():
147
146
  case "!AnnoMap":
148
147
  return {"!AnnoMap":[]}
149
148
  case _:
150
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
149
+ raise ConfigYamlError([annoKey,"!Child"])
151
150
  elif(type(confChild)==dict):
152
151
  confChildKey=list(confChild.keys())
153
152
  if(len(confChildKey)!=1):
154
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
153
+ raise ConfigYamlError([annoKey,"!Child"])
155
154
  typeStr=confChildKey[0]
156
155
  typeOption=confChild[typeStr]
157
156
  match typeStr:
158
157
  case "!Str":
159
158
  if(type(typeOption)!=dict):
160
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
159
+ raise ConfigYamlError([annoKey,"!Child","!Str"])
161
160
  strLength=None
162
161
  strMin=None
163
162
  strMax=None
@@ -167,23 +166,23 @@ class DictTraversal():
167
166
  if(strMin is None and strMax is None):
168
167
  strLength=strVal
169
168
  else:
170
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
169
+ raise ConfigYamlError([annoKey,"!Child","!Str","length"])
171
170
  case "min":
172
171
  if(strLength is None):
173
172
  strMin=strVal
174
173
  else:
175
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
174
+ raise ConfigYamlError([annoKey,"!Child","!Str","min"])
176
175
  case "max":
177
176
  if(strLength is None):
178
177
  strMax=strVal
179
178
  else:
180
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
179
+ raise ConfigYamlError([annoKey,"!Child","!Str","max"])
181
180
  case _:
182
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
181
+ raise ConfigYamlError([annoKey,"!Child","!Str"])
183
182
  return {"!Str":{"length":strLength,"min":strMin,"max":strMax}}
184
183
  case "!Int":
185
184
  if(type(typeOption)!=dict):
186
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
185
+ raise ConfigYamlError([annoKey,"!Child","!Str"], "Required `!Map` type.")
187
186
  intMin=None
188
187
  intMax=None
189
188
  for intKey,intVal in typeOption.items():
@@ -193,40 +192,44 @@ class DictTraversal():
193
192
  case "max":
194
193
  intMax=intVal
195
194
  case _:
196
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
195
+ raise ConfigYamlError([annoKey,"!Child","!Int"])
197
196
  return {"!Int":{"min":intMin,"max":intMax}}
198
197
  case "!Float":
199
198
  if(type(typeOption)!=dict):
200
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
199
+ raise ConfigYamlError([annoKey,"!Child","!Float"], "Required `!Map` type.")
201
200
  floatMin=None
202
201
  floatMax=None
203
202
  for floatKey,floatVal in typeOption.items():
204
203
  match floatKey:
205
204
  case "min":
205
+ if(type(floatVal)!=int and type(floatVal)!=float):
206
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
206
207
  floatMin=floatVal
207
208
  case "max":
209
+ if(type(floatVal)!=int and type(floatVal)!=float):
210
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
208
211
  floatMax=floatVal
209
212
  case _:
210
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
213
+ raise ConfigYamlError([annoKey,"!Child","!Float"])
211
214
  return {"!Float":{"min":floatMin,"max":floatMax}}
212
215
  case "!Enum":
213
216
  if(type(typeOption)!=list):
214
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
217
+ raise ConfigYamlError([annoKey,"!Child","!Enum"])
215
218
  enumOption=[]
216
219
  for item in typeOption:
217
220
  if(type(item)==list):
218
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
221
+ raise ConfigYamlError([annoKey,"!Child","!Enum",item])
219
222
  elif(type(item)==dict):
220
223
  keyList=list(item.keys())
221
224
  if(len(keyList)!=1):
222
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
225
+ raise ConfigYamlError([annoKey,"!Child","!Enum",item])
223
226
  enumOption.append(keyList[0])
224
227
  else:
225
228
  enumOption.append(item)
226
229
  return {"!Enum":enumOption}
227
230
  case "!List":
228
231
  if(type(typeOption)!=dict):
229
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
232
+ raise ConfigYamlError([annoKey,"!Child","!List"])
230
233
  listType=None
231
234
  listLength=None
232
235
  for listKey,listVal in typeOption.items():
@@ -236,20 +239,20 @@ class DictTraversal():
236
239
  case "length":
237
240
  listLength=listVal
238
241
  case _:
239
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
242
+ raise ConfigYamlError([annoKey,"!Child","!List",listKey])
240
243
  return {"!List":{"type":listType,"length":listLength}}
241
- case "!AnnoDict":
244
+ case "!AnnoMap":
242
245
  if(type(typeOption)!=list):
243
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
244
- for i in len(typeOption):
246
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap"])
247
+ for i in range(len(typeOption)):
245
248
  item=typeOption[i]
246
249
  if(item[0]!="@"):
247
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
248
- return {"!AnnoDict":typeOption}
250
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap",item])
251
+ return {"!AnnoMap":typeOption}
249
252
  case _:
250
- raise ConfigYamlError(f"`{annoKey}` has invalid definition.")
253
+ raise ConfigYamlError([annoKey,"!Child","!AnnoMap",item], "Unknown data type string.")
251
254
  else:
252
- raise ConfigYamlError(f"{annoKey} is invalid definition.")
255
+ raise ConfigYamlError([annoKey,"!Child"])
253
256
 
254
257
 
255
258
  def dirDFS(self,anoyPath:Path):
@@ -270,7 +273,7 @@ class DictTraversal():
270
273
  if(suffix==".yaml" or suffix==".yml" or suffix==".anoy"):
271
274
  with open(anoyPath, mode="r", encoding="utf-8") as f:
272
275
  anoyDict=yaml.safe_load(f)
273
- self._curFile=anoyPath
276
+ self._curAnoy=anoyPath
274
277
  self.dictBFS(anoyDict)
275
278
  else:
276
279
  for childPath in anoyPath.iterdir():
@@ -296,9 +299,9 @@ class DictTraversal():
296
299
  if(self._visitQueue==[]):
297
300
  break
298
301
  key,value=self._visitQueue.pop(0)
299
- self._curPath=self._pathQueue.pop(0)
302
+ self._anoyPath=self._pathQueue.pop(0)
300
303
  print(key,value)
301
- print(self._curPath)
304
+ print(self._anoyPath)
302
305
  self.checkAnoy(key,value)
303
306
 
304
307
  def checkAnoy(self,parentKey:str|None,childValue):
@@ -337,22 +340,34 @@ class DictTraversal():
337
340
  elif(parentKey[0]=="@"):
338
341
  confDictVal=self._configDict.get(parentKey)
339
342
  if(confDictVal is None):
340
- raise AnoyError(f"{parentKey} is not found.")
343
+ raise AnnotationKeyError(self._curAnoy, self._anoyPath,parentKey)
341
344
  confChild=confDictVal.get("!Child")
342
345
  else:
343
346
  confChild=None
344
347
  # anoyの型確認
345
- if(confChild is None): #Noneの処理方法は不明。
348
+ if(confChild is None):
346
349
  # nestになるlistとdictだけ対処する。
347
350
  if(type(childValue)==list):
348
351
  for i in range(len(childValue)):
349
352
  element=childValue[i]
350
- newPath=self._curPath+[i]
353
+ newPath=self._anoyPath+[i]
351
354
  self._visitQueue.append((i,element))
352
355
  self._pathQueue.append(newPath)
353
356
  elif(type(childValue)==dict):
357
+ # !Child=nullであってもfree keyとannotation keyの混合は許さない。
358
+ isAnnoMap=None
354
359
  for key,value in childValue.items():
355
- newPath=self._curPath+[key]
360
+ if(isAnnoMap is None):
361
+ if(key[0]=="@"):
362
+ isAnnoMap=True
363
+ else:
364
+ isAnnoMap=False
365
+ else:
366
+ if(isAnnoMap==True and key[0]!="@"):
367
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!AnnoMap")
368
+ elif(isAnnoMap==False and key[0]=="@"):
369
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!FreeMap")
370
+ newPath=self._anoyPath+[key]
356
371
  self._visitQueue.append((key,value))
357
372
  self._pathQueue.append(newPath)
358
373
  return
@@ -376,7 +391,7 @@ class DictTraversal():
376
391
  case "!Enum":
377
392
  self.checkEnum(childValue,typeOption)
378
393
  case _:
379
- raise ConfigYamlError(f"{parentKey} is invalid definition.")
394
+ raise ConfigYamlError([parentKey,"!Child"])
380
395
 
381
396
  def checkStr(self,anoyValue,length=None,min=None,max=None):
382
397
  """
@@ -408,17 +423,17 @@ class DictTraversal():
408
423
  if(len(anoyValue)==length):
409
424
  return
410
425
  else:
411
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
426
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str",)
412
427
  else:
413
428
  if(min is not None):
414
429
  if(len(anoyValue)<min):
415
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
430
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
416
431
  if(max is not None):
417
432
  if(max<len(anoyValue)):
418
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
433
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
419
434
  return
420
435
  else:
421
- raise AnoyTypeError("!Str",self._curFile,self._curPath)
436
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Str")
422
437
 
423
438
  def checkBool(self,anoyValue):
424
439
  """
@@ -429,7 +444,7 @@ class DictTraversal():
429
444
  @Summ: 型確認する値。
430
445
  """
431
446
  if(type(anoyValue)!=bool):
432
- raise AnoyTypeError("!Bool",self._curFile,self._curPath)
447
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Bool")
433
448
 
434
449
  def checkInt(self,anoyValue,min=None,max=None):
435
450
  """
@@ -446,13 +461,13 @@ class DictTraversal():
446
461
  if(type(anoyValue)==int):
447
462
  if(min is not None):
448
463
  if(anoyValue<min):
449
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
464
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
450
465
  if(max is not None):
451
466
  if(max<anoyValue):
452
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
467
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
453
468
  return
454
469
  else:
455
- raise AnoyTypeError("!Int",self._curFile,self._curPath)
470
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Int")
456
471
 
457
472
  def checkFloat(self,anoyValue,min=None,max=None):
458
473
  """
@@ -463,19 +478,25 @@ class DictTraversal():
463
478
  @Summ: 型確認する値。
464
479
  min:
465
480
  @Summ: 最小値。
481
+ @Desc:
482
+ - `min<=annoyValue`の時にtrue.
483
+ @SemType: Int|Float
466
484
  max:
467
485
  @Summ: 最大値。
486
+ @Desc:
487
+ - `annoyValue<=max`の時にtrue.
488
+ @SemType: Int|Float
468
489
  """
469
- if(type(anoyValue)==float):
490
+ if(type(anoyValue)==int or type(anoyValue)==float):
470
491
  if(min is not None):
471
492
  if(anoyValue<min):
472
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
493
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
473
494
  if(max is not None):
474
495
  if(max<anoyValue):
475
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
496
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
476
497
  return
477
498
  else:
478
- raise AnoyTypeError("!Float",self._curFile,self._curPath)
499
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Float")
479
500
 
480
501
  def checkFreeMap(self,anoyValue):
481
502
  """
@@ -487,13 +508,13 @@ class DictTraversal():
487
508
  """
488
509
  if(type(anoyValue)==dict):
489
510
  for key,value in anoyValue.items():
490
- newPath=self._curPath+[key]
511
+ newPath=self._anoyPath+[key]
491
512
  self._visitQueue.append((key,value))
492
513
  self._pathQueue.append(newPath)
493
514
  if(key[0]=="@"):
494
- raise AnoyTypeError("!FreeMap",self._curFile,newPath)
515
+ raise AnnotationTypeError(self._curAnoy,newPath,"!FreeMap")
495
516
  else:
496
- raise AnoyTypeError("!FreeMap",self._curFile,self._curPath)
517
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!FreeMap")
497
518
 
498
519
  def checkAnnoMap(self,parentKey,anoyValue,annoKeyList:list=[]):
499
520
  """
@@ -510,28 +531,31 @@ class DictTraversal():
510
531
  anoyValue:
511
532
  @Summ: 型確認する値。
512
533
  annoKeyList:
513
- @Summ: annotation keyのlist。
534
+ @Summ: 子要素になれるannotation keyのlist。
535
+ @Desc:
536
+ - 空lsitの時は任意のannotation keyを受け入れる。
537
+ - これは全てのannotation keyが入ったlist型と同じ挙動をする。
514
538
  @Type: List
515
539
  @Default: []
516
540
  """
517
541
  if(type(anoyValue)==dict):
518
542
  for key,value in anoyValue.items():
519
- newPath=self._curPath+[key]
543
+ newPath=self._anoyPath+[key]
520
544
  self._visitQueue.append((key,value))
521
545
  self._pathQueue.append(newPath)
522
546
  # !Parentの確認。
523
547
  configValue=self._configDict.get(key)
524
548
  if(configValue is None):
525
- raise AnoyError(f"{parentKey} is not found.")
549
+ raise AnnotationKeyError(self._curAnoy,newPath,key)
526
550
  confParent=configValue.get("!Parent")
527
551
  if(confParent is not None):
528
552
  if(parentKey not in confParent):
529
- raise AnoyTypeError("!Parent",self._curFile,newPath)
553
+ raise AnnotationTypeError(self._curAnoy,newPath,"!Parent")
530
554
  if(annoKeyList!=[]):
531
555
  if(key not in annoKeyList):
532
- raise AnoyTypeError("!AnnoMap",self._curFile,self._curPath)
556
+ raise AnnotationTypeError(self._curAnoy,newPath,"!AnnoMap")
533
557
  else:
534
- raise AnoyTypeError("!AnnoMap",self._curFile,self._curPath)
558
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!AnnoMap")
535
559
 
536
560
  def checkList(self,parentKey,anoyValue,elementType:str=None,length:int=None):
537
561
  """
@@ -560,30 +584,30 @@ class DictTraversal():
560
584
  if(type(anoyValue)==list):
561
585
  if(length is not None):
562
586
  if(length!=len(anoyValue)):
563
- raise AnoyTypeError("!List",self._curFile,self._curPath)
587
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!List")
564
588
  for i in range(len(anoyValue)):
565
589
  element=anoyValue[i]
566
- newPath=self._curPath+[i]
590
+ newPath=self._anoyPath+[i]
567
591
  if(elementType is not None):
568
592
  match elementType:
569
593
  case "!Str":
570
594
  if(type(element)!=str):
571
- raise AnoyTypeError("!List",self._curFile,newPath)
595
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
572
596
  case "!Bool":
573
597
  if(type(element)!=bool):
574
- raise AnoyTypeError("!List",self._curFile,newPath)
598
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
575
599
  case "!Int":
576
600
  if(type(element)!=int):
577
- raise AnoyTypeError("!List",self._curFile,newPath)
601
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
578
602
  case "!Float":
579
603
  if(type(element)!=float):
580
- raise AnoyTypeError("!List",self._curFile,newPath)
604
+ raise AnnotationTypeError(self._curAnoy,newPath,"!List")
581
605
  case _:
582
- raise ConfigYamlError(f"{parentKey} is invalid definition.")
606
+ raise ConfigYamlError([parentKey,"!Child"])
583
607
  self._visitQueue.append((i,element))
584
608
  self._pathQueue.append(newPath)
585
609
  else:
586
- raise AnoyTypeError("!List",self._curFile,self._curPath)
610
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!List")
587
611
 
588
612
  def checkEnum(self,anoyValue,optionList:list):
589
613
  """
@@ -627,7 +651,7 @@ class DictTraversal():
627
651
  case _:
628
652
  if(anoyValue==option):
629
653
  return
630
- raise AnoyTypeError("!Enum",self._curFile,self._curPath)
654
+ raise AnnotationTypeError(self._curAnoy,self._anoyPath,"!Enum")
631
655
 
632
656
 
633
657
  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