Skip to content

Commit

Permalink
Reduce indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Oct 8, 2024
1 parent 0d7e422 commit d8cbe28
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/pyobo/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d8cbe28

Please sign in to comment.