From 954bf3f10ef408b5b16a7ad6761ef2997002f3c1 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Thu, 22 Feb 2024 18:10:22 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=8C=20Remove=20hard-coding=20of=20?= =?UTF-8?q?`completion`=20and=20`duration`=20need=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sphinx_needs/config.py | 2 ++ sphinx_needs/data.py | 26 +++++++++++++------------- sphinx_needs/defaults.py | 2 -- sphinx_needs/directives/need.py | 4 +--- sphinx_needs/needs.py | 23 +++++++++-------------- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/sphinx_needs/config.py b/sphinx_needs/config.py index cbfb9efa8..df26d2fe8 100644 --- a/sphinx_needs/config.py +++ b/sphinx_needs/config.py @@ -257,9 +257,11 @@ def __setattr__(self, name: str, value: Any) -> None: duration_option: str = field( default="duration", metadata={"rebuild": "html", "types": (str,)} ) + """Added to options on need directives, and key on need data items, for use by ``needgantt``""" completion_option: str = field( default="completion", metadata={"rebuild": "html", "types": (str,)} ) + """Added to options on need directives, and key on need data items, for use by ``needgantt``""" needextend_strict: bool = field( default=True, metadata={"rebuild": "html", "types": (bool,)} ) diff --git a/sphinx_needs/data.py b/sphinx_needs/data.py index f18cf2944..111af4d69 100644 --- a/sphinx_needs/data.py +++ b/sphinx_needs/data.py @@ -175,35 +175,35 @@ class NeedsInfoType(TypedDict): parent_need: str """Simply the first parent id""" - # default extra options - # TODO these all default to "" which I don't think is good - duration: str - completion: str - # options from `BaseService.options` get added to every need, - # via `ServiceManager.register`, which adds them to `extra_options`` - # GithubService + # Fields added dynamically by services: + # options from ``BaseService.options`` get added to ``NEEDS_CONFIG.extra_options``, + # via `ServiceManager.register`, + # which in turn means they are added to every need via ``add_need`` + # ``GithubService.options`` avatar: str closed_at: str created_at: str max_amount: str service: str specific: str - # _type: str # type is already set in create_need + ## type: str # although this is already an internal field updated_at: str user: str - # OpenNeedsService + # ``OpenNeedsService.options`` params: str prefix: str url_postfix: str - # shared GithubService and OpenNeedsService + # shared ``GithubService.options`` and ``OpenNeedsService.options`` max_content_lines: str id_prefix: str query: str url: str - # Note there are also: - # - dynamic default options that can be set by needs_extra_options config - # - dynamic global options that can be set by needs_global_options config + # Note there are also these dynamic keys: + # - items in ``needs_extra_options`` + ``needs_duration_option`` + ``needs_completion_option``, + # which get added to ``NEEDS_CONFIG.extra_options``, + # and in turn means they are added to every need via ``add_need`` + # - keys in ``needs_global_options`` config are added to every need via ``add_need`` class NeedsPartsInfoType(NeedsInfoType): diff --git a/sphinx_needs/defaults.py b/sphinx_needs/defaults.py index 5445e2572..5df8eddb4 100644 --- a/sphinx_needs/defaults.py +++ b/sphinx_needs/defaults.py @@ -219,8 +219,6 @@ "template": directives.unchanged_required, "pre_template": directives.unchanged_required, "post_template": directives.unchanged_required, - "duration": directives.unchanged_required, - "completion": directives.unchanged_required, "constraints": directives.unchanged_required, "constraints_passed": directives.unchanged_required, "constraints_results": directives.unchanged_required, diff --git a/sphinx_needs/directives/need.py b/sphinx_needs/directives/need.py index d9ba3b24e..eb400ec37 100644 --- a/sphinx_needs/directives/need.py +++ b/sphinx_needs/directives/need.py @@ -128,11 +128,9 @@ def run(self) -> Sequence[nodes.Node]: template = self.options.get("template") pre_template = self.options.get("pre_template") post_template = self.options.get("post_template") - duration = self.options.get("duration") - completion = self.options.get("completion") constraints = self.options.get("constraints", []) - need_extra_options = {"duration": duration, "completion": completion} + need_extra_options = {} for extra_link in self.needs_config.extra_links: need_extra_options[extra_link["option"]] = self.options.get( extra_link["option"], "" diff --git a/sphinx_needs/needs.py b/sphinx_needs/needs.py index c165cd4ad..9b802e5e4 100644 --- a/sphinx_needs/needs.py +++ b/sphinx_needs/needs.py @@ -364,9 +364,8 @@ def load_config(app: Sphinx, *_args: Any) -> None: "Sphinx-Needs 0.7.2 is list. Please see docs for details." ) - extra_options = NEEDS_CONFIG.extra_options for option in needs_config.extra_options: - if option in extra_options: + if option in NEEDS_CONFIG.extra_options: LOGGER.warning( f'extra_option "{option}" already registered. [needs.config]', type="needs", @@ -374,6 +373,11 @@ def load_config(app: Sphinx, *_args: Any) -> None: ) NEEDS_CONFIG.extra_options[option] = directives.unchanged + # ensure options for ``needgantt`` functionality are added to the extra options + for option in (needs_config.duration_option, needs_config.completion_option): + if option not in NEEDS_CONFIG.extra_options: + NEEDS_CONFIG.extra_options[option] = directives.unchanged_required + # Get extra links and create a dictionary of needed options. extra_links_raw = needs_config.extra_links extra_links = {} @@ -384,8 +388,8 @@ def load_config(app: Sphinx, *_args: Any) -> None: title_from_content = needs_config.title_from_content # Update NeedDirective to use customized options - NeedDirective.option_spec.update(extra_options) - NeedserviceDirective.option_spec.update(extra_options) + NeedDirective.option_spec.update(NEEDS_CONFIG.extra_options) + NeedserviceDirective.option_spec.update(NEEDS_CONFIG.extra_options) # Update NeedDirective to use customized links NeedDirective.option_spec.update(extra_links) @@ -426,7 +430,7 @@ def load_config(app: Sphinx, *_args: Any) -> None: "-links_back": directives.flag, } ) - for key, value in extra_options.items(): + for key, value in NEEDS_CONFIG.extra_options.items(): NeedextendDirective.option_spec.update( { key: value, @@ -512,15 +516,6 @@ def prepare_env(app: Sphinx, env: BuildEnvironment, _docname: str) -> None: for needs_func in needs_config.functions: register_func(needs_func) - # Own extra options - for option in [ - "duration", - "completion", - ]: - # Check if not already set by user - if option not in NEEDS_CONFIG.extra_options: - NEEDS_CONFIG.extra_options[option] = directives.unchanged - # The default link name. Must exist in all configurations. Therefore we set it here # for the user. common_links = [] From 5fb8fe1b5fe0f10590efc8157522c6070d743dc9 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Thu, 22 Feb 2024 18:15:56 +0100 Subject: [PATCH 2/2] Update data.py --- sphinx_needs/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_needs/data.py b/sphinx_needs/data.py index 111af4d69..bf5d407e2 100644 --- a/sphinx_needs/data.py +++ b/sphinx_needs/data.py @@ -202,7 +202,7 @@ class NeedsInfoType(TypedDict): # Note there are also these dynamic keys: # - items in ``needs_extra_options`` + ``needs_duration_option`` + ``needs_completion_option``, # which get added to ``NEEDS_CONFIG.extra_options``, - # and in turn means they are added to every need via ``add_need`` + # and in turn means they are added to every need via ``add_need`` (as strings) # - keys in ``needs_global_options`` config are added to every need via ``add_need``