Skip to content

Commit

Permalink
Update validate_coverity_credentials to use sets with walrus operator…
Browse files Browse the repository at this point in the history
… and use it in initialize_environment
  • Loading branch information
JokeWaumans committed Sep 9, 2024
1 parent ada21e4 commit a43c680
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions mlx/coverity/coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@

LOGGER = getLogger("mlx.coverity")

def validate_coverity_credentials(config):
"""Validate the configuration of coverity_credentials.
Args:
config (dict): The configuration `coverity_credentials`.
"""
if missing := {"hostname", "username", "password", "stream"}.difference(config):
LOGGER.error(f"Missing mandatory keys from configuration variable 'coverity_credentials' in conf.py: {missing}")


class SphinxCoverityConnector:
"""
Expand All @@ -47,6 +56,7 @@ def initialize_environment(self, app):
\\let\@noitemerr\\relax
\\makeatother"""

validate_coverity_credentials(app.config.coverity_credentials)
self.stream = app.config.coverity_credentials["stream"]
self.snapshot = app.config.coverity_credentials.get("snapshot", "")
# Login to Coverity and obtain stream information
Expand Down Expand Up @@ -162,17 +172,6 @@ def get_filtered_defects(self, node):
return defects


def validate_coverity_credentials(config):
"""Validate the configuration of coverity_credentials.
Args:
config (dict): The configuration `coverity_credentials`.
"""
for required_element in ["hostname", "username", "password", "stream"]:
if required_element not in config:
LOGGER.error(f"{required_element} is a required configuration in 'coverity_credentials' in conf.py")


# Extension setup
def setup(app):
"""Extension setup"""
Expand All @@ -189,8 +188,6 @@ def setup(app):
dict,
)

validate_coverity_credentials(app.config.coverity_credentials)

app.add_config_value("TRACEABILITY_ITEM_ID_REGEX", r"([A-Z_]+-[A-Z0-9_]+)", "env")
app.add_config_value("TRACEABILITY_ITEM_RELINK", {}, "env")

Expand Down

0 comments on commit a43c680

Please sign in to comment.