sphinx-needs
sphinx-needs copied to clipboard
Internal handling of `extra_options` seems inconsistent
This issue arises from when I was looking into the code considering #1082 and #1119 (@danwos as we discussed this morning)
The use of the config variable needs_extra_options
and of the global variable NEEDS_CONFIG.extra_options
seem inconsistent, in that:
- Sometimes
needs_extra_options
is used, where it seems thatNEEDS_CONFIG.extra_options
should probably be used instead -
NEEDS_CONFIG.extra_options
is difficult to track, because at different stages it has new items added, which are obviously not taken into account in previous stages.
Below is a summary of their use in the code base:
Extra options are created by either:
- A user adds them via the
needs_extra_options
configuration, as alist[str]
- A user / extension uses
api.configuration.add_extra_option
to "programmatically" add aname
toNEEDS_CONFIG.extra_options
(raisesNeedsApiConfigWarning
if already added). For examplesphinx-test-reports
uses this in aconfig-inited
event
They are used in the following places (in this order):
-
In
load_config
(config-inited
event)-
needs_extra_options
are added toNEEDS_CONFIG.extra_options
object (a warning is raised if one already exists) -
needs_duration_option
(defaultduration
) +needs_completion_option
(defaultcompletion
) are also added if not present (as of #1127) - each
NEEDS_CONFIG.extra_options
is added as an option on:-
NeedDirective
-
NeedserviceDirective
-
NeedextendDirective
(and also as+<name> -> unchanged
and-<name> -> flag
)
-
-
-
In
check_configuration
(config-inited
event):-
needs_filter_data
keys are checked againstneeds_extra_options
names; matching keys cause aNeedsConfigException
-
needs_extra_options
names are checked againstINTERNALS
list; matching keys cause aNeedsConfigException
- link type names (and their corresponding
<name>_back
key) are checked againstneeds_extra_options
names; matching keys cause aNeedsConfigException
- ensure all
needs_variant_options
keys match aneeds_extra_options
name, or a link type, or a default option; if not, aNeedsConfigException
is raised
-
-
In
prepare_env
(env-before-read-docs
event):-
the
ServiceManager
is initialised and theGithubService
andOpenNeedsService
classes are registered viaServiceManager.register
. InServiceManager.register
, for alloptions
on the service class, the option is added toNEEDS_CONFIG.extra_options
(if not already present) -
additional "default" extra names are added to
NEEDS_CONFIG.extra_options
: ~~hidden
~~ (removed in #1124), ~~duration
,completion
~~ (removed #1127), ~~constraints
~~ (removed in #1123) (if not already present)
-
-
In
load_external_needs
(env-before-read-docs
event) for each loaded need, all fields inneeds_extra_options
are always kept (this data is then parsed on toadd_external_need -> add_need
) -
In
NeedDirective.run
(called during read) for all names inNEEDS_CONFIG.extra_options
gather passkwargs
toadd_need
, i.e.kwarks[name] = self.options.get(name, "")
- It is of note that
duration
andcompletion
are specifically gathered, but then surely must be overridden, since these are both added as defaults above (inprepare_env
)
- It is of note that
-
In
NeedimportDirective.run
,NEEDS_CONFIG.extra_options
are added to theknown_options
list then, for each import need item, if a field is not inknown_options
it is dropped, the rest are passed toadd_need
- This is similar to the logic in
load_external_needs
, BUT that usesneeds_extra_options
instead ofNEEDS_CONFIG.extra_options
- This is similar to the logic in
-
In
add_need
(called before/during read)NEEDS_CONFIG.extra_options
is passed to_merge_extra_options
, as well as thekwargs
passed toadd_need
:-
All
kwargs
passed toadd_need
must either be inNEEDS_CONFIG.extra_options
or inneeds_extra_links
(or aNeedsInvalidOption
is raised) -
In
_merge_extra_options
, for all theNEEDS_CONFIG.extra_options
keys:- if the key is in
kwargs
, but not already set byadd_need
(i.e. is not an internal key), its value is set tokwargs[key]
, or - if the key is not already set by
add_need
(i.e. is not an internal key), it is set to a default value of""
- if the key is in
-
-
In
NeedReportDirective
, if required,need_extra_options
are listed
One thing else I note @danwos:
I see now that the duration
and completion
fields are added for use by the needgantt
directive.
For this there are also needs_duration_option
and needs_completion_option
configuration options, to change the name of these fiels.
However, since duration
and completion
are hard-coded in the code base in a number of places,
I think if users were to use these configurations options to change the names, this would not work very well