@@ -37,35 +37,6 @@ def __init__(self, directive: str, name: str, prefix: str, color, style):
37
37
self .style = style
38
38
39
39
40
- def split_tags (
41
- tags_string : Optional [str ], need_id : str , allowed_tags : Optional [List [str ]]
42
- ) -> List [str ]:
43
-
44
- if not tags_string :
45
- return []
46
-
47
- def is_valid (tag : str ) -> bool :
48
- if len (tag ) == 0 or tag .isspace ():
49
- logger .warning (
50
- "Scruffy tag definition found in need {}. "
51
- "Defined tag contains spaces only." .format (need_id )
52
- )
53
- return False
54
-
55
- if allowed_tags and tag not in allowed_tags :
56
- raise NeedsTagNotAllowed (
57
- "Tag {0} of need id {1} is not allowed "
58
- "by config value 'needs_tags'." .format (tag , need_id )
59
- )
60
-
61
- return True
62
-
63
- raw_tags = (tag .strip () for tag in re .split (";|," , tags_string ))
64
- tags = filter (is_valid , raw_tags )
65
-
66
- return utils .fix_list_dyn_func (tags )
67
-
68
-
69
40
def add_need (
70
41
app : Sphinx ,
71
42
state ,
@@ -214,11 +185,11 @@ def run():
214
185
"by config value 'needs_statuses'." .format (status , need_id )
215
186
)
216
187
217
- allowed_tags : Optional [ List [ str ]] = None
188
+ allowed_tags = None
218
189
if config .needs_tags :
219
190
allowed_tags = [tag ["name" ] for tag in config .needs_tags ]
220
191
221
- tag_list = split_tags (tags , need_id , allowed_tags )
192
+ tag_list = _split_tags (tags , need_id , allowed_tags )
222
193
223
194
####################################################################################
224
195
# Add need to global need list
@@ -398,26 +369,33 @@ def run():
398
369
return return_nodes
399
370
400
371
401
- def make_hashed_id (
402
- prefix : str ,
403
- content : str ,
404
- id_length : Optional [int ] = None ,
405
- ) -> str :
406
- """
407
- Creates an ID based on title or need.
372
+ def _split_tags (
373
+ tags_string : Optional [str ], need_id : str , allowed_tags : Optional [List [str ]]
374
+ ) -> List [str ]:
408
375
409
- Also cares about the correct prefix, which is specified for each need type.
376
+ if not tags_string :
377
+ return []
410
378
411
- :param prefix: the prefix of the id of every need of this type
412
- :param content: the content to be hashed
413
- :param id_length: maximum length of the generated ID
414
- :return: ID as string
415
- """
379
+ def is_valid (tag : str ) -> bool :
380
+ if len (tag ) == 0 or tag .isspace ():
381
+ logger .warning (
382
+ "Scruffy tag definition found in need {}. "
383
+ "Defined tag contains spaces only." .format (need_id )
384
+ )
385
+ return False
416
386
417
- return "{}{}" .format (
418
- prefix ,
419
- hashlib .sha1 (content .encode ("UTF-8" )).hexdigest ().upper ()[:id_length ],
420
- )
387
+ if allowed_tags and tag not in allowed_tags :
388
+ raise NeedsTagNotAllowed (
389
+ "Tag {0} of need id {1} is not allowed "
390
+ "by config value 'needs_tags'." .format (tag , need_id )
391
+ )
392
+
393
+ return True
394
+
395
+ raw_tags = (tag .strip () for tag in re .split (";|," , tags_string ))
396
+ tags = filter (is_valid , raw_tags )
397
+
398
+ return utils .fix_list_dyn_func (tags )
421
399
422
400
423
401
def _prepare_template (app : Sphinx , needs_info , template_key ) -> str :
@@ -455,6 +433,26 @@ def _render_template(content: str, docname: str, lineno: int, state) -> nodes.El
455
433
return node_need_content
456
434
457
435
436
+ def make_hashed_id (
437
+ prefix : str ,
438
+ content : str ,
439
+ id_length : Optional [int ] = None ,
440
+ ) -> str :
441
+ """
442
+ Creates an ID based on title or need.
443
+ Also cares about the correct prefix, which is specified for each need type.
444
+ :param prefix: the prefix of the id of every need of this type
445
+ :param content: the content to be hashed
446
+ :param id_length: maximum length of the generated ID
447
+ :return: ID as string
448
+ """
449
+
450
+ return "{}{}" .format (
451
+ prefix ,
452
+ hashlib .sha1 (content .encode ("UTF-8" )).hexdigest ().upper ()[:id_length ],
453
+ )
454
+
455
+
458
456
def _merge_extra_options (needs_info , needs_kwargs , needs_extra_options ):
459
457
"""Add any extra options introduced via options_ext to needs_info"""
460
458
extra_keys = set (needs_kwargs .keys ()).difference (set (needs_info .keys ()))
0 commit comments