Skip to content

Commit

Permalink
Improve availability check (#15)
Browse files Browse the repository at this point in the history
* Improve availability check

* Update robot.py
  • Loading branch information
cthoyt authored Sep 11, 2023
1 parent cba7501 commit 489124a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/bioontologies/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,35 @@

def is_available() -> bool:
"""Check if ROBOT is available."""
# suggested in https://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script
from shutil import which

return which("robot") is not None
if which("java") is None:
# suggested in https://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script
logger.error("java is not on the PATH")
return False

try:
check_output(["java", "--help"]) # noqa:S607
except Exception:
logger.error(
"java --help failed - this means the java runtime environment (JRE) "
"might not be configured properly"
)
return False

if not ROBOT_PATH.is_file():
logger.error("ROBOT was not successfully downloaded to %s", ROBOT_PATH)
# ROBOT was unsuccessfully downloaded
return False

try:
# Check
check_output([*ROBOT_COMMAND, "--help"])
except Exception:
logger.error("ROBOT was downloaded to %s but could not be run with --help", ROBOT_PATH)
return False

return True


@dataclass
Expand Down

0 comments on commit 489124a

Please sign in to comment.