Skip to content

Commit

Permalink
Tell type checkers that the config options are strings. (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer authored Apr 11, 2024
1 parent 0395b25 commit d013548
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _is_configuration_valid(self) -> Tuple[bool, str]:
Tuple containing as first element whether the configuration is valid.
and a string with the error, if any, as second element.
"""
site_url = self.config["site_url"]
site_url = typing.cast(str, self.config["site_url"])
if site_url and not urlparse(site_url).hostname:
return False, "Configuration option site_url is not valid"
return True, ""
Expand All @@ -160,7 +160,7 @@ def _get_external_hostname(self) -> str:
Returns:
The site URL defined as part of the site_url configuration or a default value.
"""
site_url = self.config["site_url"]
site_url = typing.cast(str, self.config["site_url"])
if not site_url or not (hostname := urlparse(site_url).hostname):
return f"{self.app.name}.local"
return hostname
Expand All @@ -171,7 +171,7 @@ def _get_external_scheme(self) -> str:
Returns:
The HTTP schema.
"""
site_url = self.config["site_url"]
site_url = typing.cast(str, self.config["site_url"])
return urlparse(site_url).scheme if site_url else "http"

def _get_external_port(self) -> Optional[int]:
Expand All @@ -180,7 +180,7 @@ def _get_external_port(self) -> Optional[int]:
Returns:
The port number.
"""
site_url = self.config["site_url"]
site_url = typing.cast(str, self.config["site_url"])
return urlparse(site_url).port

def _are_relations_ready(self, _) -> bool:
Expand Down Expand Up @@ -220,7 +220,7 @@ def _config_pebble(self, container: Container) -> None:
self.unit.status = MaintenanceStatus(f"Adding {container.name} layer to pebble")
if container.name == "indico":
plugins = (
self.config["external_plugins"].split(",")
typing.cast(str, self.config["external_plugins"]).split(",")
if self.config["external_plugins"]
else []
)
Expand Down Expand Up @@ -712,7 +712,13 @@ def _download_customization_changes(self, container: Container) -> None:
self.config["customization_sources_url"],
)
self._exec_cmd_in_custom_dir(
container, ["git", "clone", self.config["customization_sources_url"], "."]
container,
[
"git",
"clone",
typing.cast(str, self.config["customization_sources_url"]),
".",
],
)

def _refresh_external_resources(self, _) -> Dict:
Expand All @@ -739,7 +745,7 @@ def _refresh_external_resources(self, _) -> Dict:
results["customization-changes"] = True
if self.config["external_plugins"]:
logging.debug("Upgrading external plugins %s", self.config["external_plugins"])
plugins = self.config["external_plugins"].split(",")
plugins = typing.cast(str, self.config["external_plugins"]).split(",")
self._install_plugins(container, plugins)
results["plugin-updates"] = plugins
return results
Expand Down

0 comments on commit d013548

Please sign in to comment.