8000 Raise RuntimeError if java is not available by seal6363 · Pull Request #1856 · allenai/allennlp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Raise RuntimeError if java is not available #1856

Merged
merged 4 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion allennlp/common/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import logging

import subprocess
from torch import cuda

logger = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down Expand Up @@ -43,3 +43,10 @@ def check_for_gpu(device_id: int):
raise ConfigurationError("Experiment specified a GPU but none is available;"
" if you want to run on CPU use the override"
" 'trainer.cuda_device=-1' in the json config file.")

def check_for_java() -> bool:
try:
java_version = subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
return 'version' in java_version.decode()
except FileNotFoundError:
return False
3 changes: 3 additions & 0 deletions allennlp/predictors/wikitables_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from allennlp.data import DatasetReader, Instance
from allennlp.models import Model
from allennlp.predictors.predictor import Predictor
from allennlp.common.checks import check_for_java

# TODO(mattg): We should merge how this works with how the `WikiTablesAccuracy` metric works, maybe
# just removing the need for adding this stuff at all, because the parser already runs the java
Expand Down Expand Up @@ -106,6 +107,8 @@ def _execute_logical_form_on_table(logical_form: str, table: str):
# TODO(matt): The jar that we have isn't optimal for this use case - we're using a
# script designed for computing accuracy, and just pulling out a piece of it. Writing
# a new entry point to the jar that's tailored for this use would be cleaner.
if not check_for_java():
raise RuntimeError('Java is not installed properly.')
command = ' '.join(['java',
'-jar',
cached_path(DEFAULT_EXECUTOR_JAR),
Expand Down
9F78 3 changes: 3 additions & 0 deletions allennlp/semparse/executors/wikitables_sempre_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess

from allennlp.common.file_utils import cached_path
from allennlp.common.checks import check_for_java

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -81,6 +82,8 @@ def _create_sempre_executor(self) -> None:
subprocess.run(f'wget {GROW_FILE}', shell=True)
subprocess.run(f'mv wikitables-grow.grammar {grammar_path}', shell=True)

if not check_for_java():
raise RuntimeError('Java is not installed properly.')
args = ['java', '-jar', cached_path(SEMPRE_EXECUTOR_JAR), 'serve', self._table_directory]
self._executor_process = subprocess.Popen(args,
stdin=subprocess.PIPE,
Expand Down
0