Skip to content

Commit 10d8d12

Browse files
committed
reorder methods (closer to original)
1 parent 5633b95 commit 10d8d12

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

sphinxcontrib/needs/api/need.py

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,6 @@ def __init__(self, directive: str, name: str, prefix: str, color, style):
3737
self.style = style
3838

3939

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-
6940
def add_need(
7041
app: Sphinx,
7142
state,
@@ -214,11 +185,11 @@ def run():
214185
"by config value 'needs_statuses'.".format(status, need_id)
215186
)
216187

217-
allowed_tags: Optional[List[str]] = None
188+
allowed_tags = None
218189
if config.needs_tags:
219190
allowed_tags = [tag["name"] for tag in config.needs_tags]
220191

221-
tag_list = split_tags(tags, need_id, allowed_tags)
192+
tag_list = _split_tags(tags, need_id, allowed_tags)
222193

223194
####################################################################################
224195
# Add need to global need list
@@ -398,26 +369,33 @@ def run():
398369
return return_nodes
399370

400371

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]:
408375

409-
Also cares about the correct prefix, which is specified for each need type.
376+
if not tags_string:
377+
return []
410378

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
416386

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)
421399

422400

423401
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
455433
return node_need_content
456434

457435

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+
458456
def _merge_extra_options(needs_info, needs_kwargs, needs_extra_options):
459457
"""Add any extra options introduced via options_ext to needs_info"""
460458
extra_keys = set(needs_kwargs.keys()).difference(set(needs_info.keys()))

0 commit comments

Comments
 (0)