Skip to content

Commit

Permalink
cleanup publish debug options (format/presentation)
Browse files Browse the repository at this point in the history
Updating the configuration handling of publish debugging options to
promote the uses of dashes of underscores (e.g. `headers-and-data` over
`headers_and_data`). Both values are still accepted, but the dash
variant will be the value shown in documentation.

This commit also adjusts the configuration check to explicitly list
supported options. The previous use of populating values from the
enumeration does not work for all desired entries. Best to list the
explicit values we want to inform a user on.

Signed-off-by: James Knight <james.d.knight@live.com>
  • Loading branch information
jdknight committed Jul 1, 2024
1 parent 54b1fea commit ea28688
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions sphinxcontrib/confluencebuilder/config/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,13 @@ def conf_translate(value):
# ##################################################################

# confluence_publish_debug
opts = PublishDebug._member_names_ # pylint: disable=no-member
try:
validator.conf('confluence_publish_debug').bool() # deprecated
except ConfluenceConfigError:
try:
validator.conf('confluence_publish_debug').enum(PublishDebug)
except ConfluenceConfigError as ex:
opts_str = '\n - '.join(opts)
raise ConfluencePublishDebugConfigError(ex, opts_str) from ex
raise ConfluencePublishDebugConfigError(ex) from ex

# ##################################################################

Expand Down
3 changes: 2 additions & 1 deletion sphinxcontrib/confluencebuilder/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def apply_defaults(builder):
if publish_debug is True:
conf.confluence_publish_debug = PublishDebug.urllib3
elif isinstance(publish_debug, str) and publish_debug:
conf.confluence_publish_debug = PublishDebug[publish_debug.lower()]
raw_debug = publish_debug.replace('-', '_').lower()
conf.confluence_publish_debug = PublishDebug[raw_debug]
else:
conf.confluence_publish_debug = PublishDebug.none

Expand Down
7 changes: 5 additions & 2 deletions sphinxcontrib/confluencebuilder/config/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,18 @@ def __init__(self):


class ConfluencePublishDebugConfigError(ConfluenceConfigError):
def __init__(self, msg, opts):
def __init__(self, msg):
super().__init__(f'''\
{msg}
The option 'confluence_publish_debug' has been configured to enable publish
debugging. Accepted values include:
- all
- {opts}
- deprecated
- headers
- headers-and-data
- urllib3
''')


Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/config/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def enum(self, etype):

if value is not None and not isinstance(value, etype):
try:
value = etype[value.lower()]
value = etype[value.replace('-', '_').lower()]
except (AttributeError, KeyError) as ex:
msg = f'{self.key} is not an enumeration ({etype.__name__})'
raise ConfluenceConfigError(msg) from ex
Expand Down

0 comments on commit ea28688

Please sign in to comment.