From d8cbe287b9c8888e323b0023ad5ba51bf2853868 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Tue, 8 Oct 2024 16:03:06 +0200 Subject: [PATCH] Reduce indentation --- src/pyobo/api/utils.py | 54 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/pyobo/api/utils.py b/src/pyobo/api/utils.py index 5cbb5fa5..afd2a4d8 100644 --- a/src/pyobo/api/utils.py +++ b/src/pyobo/api/utils.py @@ -55,8 +55,7 @@ def get_version(prefix: str) -> Optional[str]: @lru_cache(1) def get_version_pins() -> dict[str, str]: - """ - Retrieve user-defined resource version pins. + """Retrieve user-defined resource version pins. To set your own resource pins, set your machine's environmental variable "PYOBO_VERSION_PINS" to a JSON string containing string resource prefixes @@ -69,32 +68,29 @@ def get_version_pins() -> dict[str, str]: """ version_pins_str = os.getenv("PYOBO_VERSION_PINS") if not version_pins_str: - version_pins = {} - else: - try: - version_pins = json.loads(version_pins_str) - except ValueError as e: - logger.error( - "The value for the environment variable PYOBO_VERSION_PINS " - "must be a valid JSON string: %s" % e - ) - version_pins = {} - invalid_prefixes = [] - for prefix, version in version_pins.items(): - if not isinstance(prefix, str) or not isinstance(version, str): - logger.error(f"The prefix:{prefix} and version:{version} name must both be strings") - invalid_prefixes.append(prefix) - for prefix in invalid_prefixes: - version_pins.pop(prefix) - - if version_pins: - logger.debug( - f"These are the resource versions that are pinned.\n" - f"{version_pins}. " - f"\nPyobo will download the latest version of a resource if it's " - f"not pinned.\nIf you want to use a specific version of a " - f"resource, edit your PYOBO_VERSION_PINS environmental " - f"variable which is a JSON string to include a prefix and version " - f"name." + return {} + + try: + version_pins = json.loads(version_pins_str) + except ValueError as e: + logger.error( + "The value for the environment variable PYOBO_VERSION_PINS " + "must be a valid JSON string: %s" % e ) + return {} + + for prefix, version in list(version_pins.items()): + if not isinstance(prefix, str) or not isinstance(version, str): + logger.error(f"The prefix:{prefix} and version:{version} name must both be strings") + del version_pins[prefix] + + logger.debug( + f"These are the resource versions that are pinned.\n" + f"{version_pins}. " + f"\nPyobo will download the latest version of a resource if it's " + f"not pinned.\nIf you want to use a specific version of a " + f"resource, edit your PYOBO_VERSION_PINS environmental " + f"variable which is a JSON string to include a prefix and version " + f"name." + ) return version_pins