Skip to content

Commit eeada5b

Browse files
committed
🧪 Reset SN for testing
1 parent c25df13 commit eeada5b

15 files changed

+297
-106
lines changed

‎sphinx_needs/directives/need.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ class NeedDirective(SphinxDirective):
5050

5151
required_arguments = 1
5252
optional_arguments = 0
53-
option_spec = NEED_DEFAULT_OPTIONS
53+
option_spec = NEED_DEFAULT_OPTIONS.copy()
5454

5555
final_argument_whitespace = True
5656

57+
@classmethod
58+
def reset(cls) -> None:
59+
"""Reset the directive to its initial state."""
60+
cls.option_spec = NEED_DEFAULT_OPTIONS
61+
5762
@measure_time("need")
5863
def run(self) -> Sequence[nodes.Node]:
5964
if self.options.get("delete"):

‎sphinx_needs/directives/needbar.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hashlib
44
import math
55
from collections.abc import Sequence
6+
from typing import Any, Callable
67

78
from docutils import nodes
89
from docutils.parsers.rst import directives
@@ -26,6 +27,27 @@ class Needbar(nodes.General, nodes.Element):
2627
pass
2728

2829

30+
OPTION_SPEC_DEFAULT = {
31+
"style": directives.unchanged_required,
32+
"colors": directives.unchanged_required,
33+
"text_color": directives.unchanged_required,
34+
"x_axis_title": directives.unchanged_required,
35+
"xlabels": directives.unchanged_required,
36+
"xlabels_rotation": directives.unchanged_required,
37+
"y_axis_title": directives.unchanged_required,
38+
"ylabels": directives.unchanged_required,
39+
"ylabels_rotation": directives.unchanged_required,
40+
"separator": directives.unchanged_required,
41+
"legend": directives.flag,
42+
"stacked": directives.flag,
43+
"show_sum": directives.flag,
44+
"show_top_sum": directives.flag,
45+
"sum_rotation": directives.unchanged_required,
46+
"transpose": directives.flag,
47+
"horizontal": directives.flag,
48+
}
49+
50+
2951
class NeedbarDirective(FilterBase):
3052
"""
3153
Directive to plot diagrams with the help of matplotlib
@@ -39,25 +61,12 @@ class NeedbarDirective(FilterBase):
3961
optional_arguments = 1
4062
final_argument_whitespace = True
4163

42-
option_spec = {
43-
"style": directives.unchanged_required,
44-
"colors": directives.unchanged_required,
45-
"text_color": directives.unchanged_required,
46-
"x_axis_title": directives.unchanged_required,
47-
"xlabels": directives.unchanged_required,
48-
"xlabels_rotation": directives.unchanged_required,
49-
"y_axis_title": directives.unchanged_required,
50-
"ylabels": directives.unchanged_required,
51-
"ylabels_rotation": directives.unchanged_required,
52-
"separator": directives.unchanged_required,
53-
"legend": directives.flag,
54-
"stacked": directives.flag,
55-
"show_sum": directives.flag,
56-
"show_top_sum": directives.flag,
57-
"sum_rotation": directives.unchanged_required,
58-
"transpose": directives.flag,
59-
"horizontal": directives.flag,
60-
}
64+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
65+
66+
@classmethod
67+
def reset(cls) -> None:
68+
"""Reset the directive to its initial state."""
69+
cls.option_spec = OPTION_SPEC_DEFAULT
6170

6271
# Algorithm:
6372
# 1. define constants

‎sphinx_needs/directives/needextend.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class Needextend(nodes.General, nodes.Element):
2222
pass
2323

2424

25+
OPTION_SPEC_DEFAULT = {
26+
"strict": directives.unchanged_required,
27+
}
28+
29+
2530
class NeedextendDirective(SphinxDirective):
2631
"""
2732
Directive to modify existing needs
@@ -32,9 +37,12 @@ class NeedextendDirective(SphinxDirective):
3237
optional_arguments = 0
3338
final_argument_whitespace = True
3439

35-
option_spec: dict[str, Callable[[str], Any]] = {
36-
"strict": directives.unchanged_required,
37-
}
40+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
41+
42+
@classmethod
43+
def reset(cls) -> None:
44+
"""Reset the directive to its initial state."""
45+
cls.option_spec = OPTION_SPEC_DEFAULT
3846

3947
def run(self) -> Sequence[nodes.Node]:
4048
env = self.env

‎sphinx_needs/directives/needextract.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44
from collections.abc import Sequence
5+
from typing import Any, Callable
56

67
from docutils import nodes
78
from docutils.parsers.rst import directives
@@ -30,6 +31,13 @@ class Needextract(nodes.General, nodes.Element):
3031
pass
3132

3233

34+
OPTION_SPEC_DEFAULT = {
35+
"layout": directives.unchanged_required,
36+
"style": directives.unchanged_required,
37+
"show_filters": directives.flag,
38+
}
39+
40+
3341
class NeedextractDirective(FilterBase):
3442
"""
3543
Directive to filter needs and present them as normal needs with given layout and style.
@@ -38,14 +46,17 @@ class NeedextractDirective(FilterBase):
3846
optional_arguments = 1
3947
final_argument_whitespace = True
4048

41-
option_spec = {
42-
"layout": directives.unchanged_required,
43-
"style": directives.unchanged_required,
44-
"show_filters": directives.flag,
45-
}
49+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
50+
4651
# Update the options_spec with values defined in the FilterBase class
4752
option_spec.update(FilterBase.base_option_spec)
4853

54+
@classmethod
55+
def reset(cls) -> None:
56+
"""Reset the directive to its initial state."""
57+
cls.option_spec = OPTION_SPEC_DEFAULT
58+
cls.option_spec.update(FilterBase.base_option_spec)
59+
4960
def run(self) -> Sequence[nodes.Node]:
5061
env = self.env
5162

‎sphinx_needs/directives/needgantt.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
from collections.abc import Sequence
66
from datetime import datetime
7+
from typing import Any, Callable
78

89
from docutils import nodes
910
from docutils.parsers.rst import directives
@@ -34,29 +35,40 @@ class Needgantt(nodes.General, nodes.Element):
3435
pass
3536

3637

38+
OPTION_SPEC_DEFAULT = {
39+
"starts_with_links": directives.unchanged,
40+
"starts_after_links": directives.unchanged,
41+
"ends_with_links": directives.unchanged,
42+
"milestone_filter": directives.unchanged,
43+
"start_date": directives.unchanged,
44+
"timeline": directives.unchanged,
45+
"duration_option": directives.unchanged,
46+
"completion_option": directives.unchanged,
47+
"no_color": directives.flag,
48+
}
49+
50+
3751
class NeedganttDirective(FilterBase, DiagramBase):
3852
"""
3953
Directive to get gantt diagrams.
4054
"""
4155

4256
optional_arguments = 1
4357
final_argument_whitespace = True
44-
option_spec = {
45-
"starts_with_links": directives.unchanged,
46-
"starts_after_links": directives.unchanged,
47-
"ends_with_links": directives.unchanged,
48-
"milestone_filter": directives.unchanged,
49-
"start_date": directives.unchanged,
50-
"timeline": directives.unchanged,
51-
"duration_option": directives.unchanged,
52-
"completion_option": directives.unchanged,
53-
"no_color": directives.flag,
54-
}
58+
59+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
5560

5661
# Update the options_spec with values defined in the FilterBase class
5762
option_spec.update(FilterBase.base_option_spec)
5863
option_spec.update(DiagramBase.base_option_spec)
5964

65+
@classmethod
66+
def reset(cls) -> None:
67+
"""Reset the directive to its initial state."""
68+
cls.option_spec = OPTION_SPEC_DEFAULT
69+
cls.option_spec.update(FilterBase.base_option_spec)
70+
cls.option_spec.update(DiagramBase.base_option_spec)
71+
6072
def run(self) -> Sequence[nodes.Node]:
6173
env = self.env
6274
needs_config = NeedsSphinxConfig(env.config)

‎sphinx_needs/directives/needimport.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
from collections.abc import Sequence
7+
from typing import Any, Callable
78
from urllib.parse import urlparse
89

910
import requests
@@ -27,29 +28,37 @@ class Needimport(nodes.General, nodes.Element):
2728
pass
2829

2930

31+
OPTION_SPEC_DEFAULT = {
32+
"version": directives.unchanged_required,
33+
"hide": directives.flag,
34+
"collapse": string_to_boolean,
35+
"ids": directives.unchanged_required,
36+
"filter": directives.unchanged_required,
37+
"id_prefix": directives.unchanged_required,
38+
"tags": directives.unchanged_required,
39+
"style": directives.unchanged_required,
40+
"layout": directives.unchanged_required,
41+
"template": directives.unchanged_required,
42+
"pre_template": directives.unchanged_required,
43+
"post_template": directives.unchanged_required,
44+
}
45+
46+
3047
class NeedimportDirective(SphinxDirective):
3148
has_content = False
3249

3350
required_arguments = 1
3451
optional_arguments = 0
3552

36-
option_spec = {
37-
"version": directives.unchanged_required,
38-
"hide": directives.flag,
39-
"collapse": string_to_boolean,
40-
"ids": directives.unchanged_required,
41-
"filter": directives.unchanged_required,
42-
"id_prefix": directives.unchanged_required,
43-
"tags": directives.unchanged_required,
44-
"style": directives.unchanged_required,
45-
"layout": directives.unchanged_required,
46-
"template": directives.unchanged_required,
47-
"pre_template": directives.unchanged_required,
48-
"post_template": directives.unchanged_required,
49-
}
53+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
5054

5155
final_argument_whitespace = True
5256

57+
@classmethod
58+
def reset(cls) -> None:
59+
"""Reset the directive to its initial state."""
60+
cls.option_spec = OPTION_SPEC_DEFAULT
61+
5362
@measure_time("needimport")
5463
def run(self) -> Sequence[nodes.Node]:
5564
needs_config = NeedsSphinxConfig(self.config)

‎sphinx_needs/directives/needlist.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Sequence
4+
from typing import Any, Callable
45

56
from docutils import nodes
67
from docutils.parsers.rst import directives
@@ -24,20 +25,29 @@ class Needlist(nodes.General, nodes.Element):
2425
pass
2526

2627

28+
OPTION_SPEC_DEFAULT = option_spec = {
29+
"show_status": directives.flag,
30+
"show_tags": directives.flag,
31+
"show_filters": directives.flag,
32+
}
33+
34+
2735
class NeedlistDirective(FilterBase):
2836
"""
2937
Directive to filter needs and present them inside a list
3038
"""
3139

32-
option_spec = {
33-
"show_status": directives.flag,
34-
"show_tags": directives.flag,
35-
"show_filters": directives.flag,
36-
}
40+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
3741

3842
# Update the options_spec with values defined in the FilterBase class
3943
option_spec.update(FilterBase.base_option_spec)
4044

45+
@classmethod
46+
def reset(cls) -> None:
47+
"""Reset the directive to its initial state."""
48+
cls.option_spec = OPTION_SPEC_DEFAULT
49+
cls.option_spec.update(FilterBase.base_option_spec)
50+
4151
def run(self) -> Sequence[nodes.Node]:
4252
env = self.env
4353

‎sphinx_needs/directives/needpie.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import hashlib
44
from collections.abc import Iterable, Sequence
5+
from typing import Any, Callable
56

67
from docutils import nodes
78
from docutils.parsers.rst import directives
@@ -29,6 +30,17 @@ class Needpie(nodes.General, nodes.Element):
2930
pass
3031

3132

33+
OPTION_SPEC_DEFAULT = {
34+
"legend": directives.flag,
35+
"explode": directives.unchanged_required,
36+
"labels": directives.unchanged_required,
37+
"style": directives.unchanged_required,
38+
"colors": directives.unchanged_required,
39+
"text_color": directives.unchanged_required,
40+
"shadow": directives.flag,
41+
}
42+
43+
3244
class NeedpieDirective(FilterBase):
3345
"""
3446
Directive to plot diagrams with the help of matplotlib
@@ -42,17 +54,26 @@ class NeedpieDirective(FilterBase):
4254
optional_arguments = 1
4355
final_argument_whitespace = True
4456

45-
option_spec = {
46-
"legend": directives.flag,
47-
"explode": directives.unchanged_required,
48-
"labels": directives.unchanged_required,
49-
"style": directives.unchanged_required,
50-
"colors": directives.unchanged_required,
51-
"text_color": directives.unchanged_required,
52-
"shadow": directives.flag,
53-
"filter-func": FilterBase.base_option_spec["filter-func"],
54-
"filter_warning": FilterBase.base_option_spec["filter_warning"],
55-
}
57+
option_spec: dict[str, Callable[[str], Any]] = OPTION_SPEC_DEFAULT.copy()
58+
59+
# Update the options_spec with values defined in the FilterBase class
60+
option_spec.update(
61+
{
62+
"filter-func": FilterBase.base_option_spec["filter-func"],
63+
"filter_warning": FilterBase.base_option_spec["filter_warning"],
64+
}
65+
)
66+
67+
@classmethod
68+
def reset(cls) -> None:
69+
"""Reset the directive to its initial state."""
70+
cls.option_spec = OPTION_SPEC_DEFAULT
71+
cls.option_spec.update(
72+
{
73+
"filter-func": FilterBase.base_option_spec["filter-func"],
74+
"filter_warning": FilterBase.base_option_spec["filter_warning"],
75+
}
76+
)
5677

5778
# Update the options_spec only with value filter-func defined in the FilterBase class
5879

0 commit comments

Comments
 (0)