Abacn commented on code in PR #35803:
URL: https://github.com/apache/beam/pull/35803#discussion_r2263262196
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -383,23 +384,41 @@ def __init__(
self._jar_provider = jar_provider
self._classpath = classpath
+
def available(self):
# pylint: disable=subprocess-run-check
- trial = subprocess.run(['which', subprocess_server.JavaHelper.get_java()],
- capture_output=True)
- if trial.returncode == 0:
- return True
- else:
-
def try_decode(bs):
- try:
- return bs.decode()
- except UnicodeError:
- return bs
-
- return NotAvailableWithReason(
- f'Unable to locate java executable: '
- f'{try_decode(trial.stdout)}{try_decode(trial.stderr)}')
+ try:
+ return bs.decode()
+ except UnicodeError:
+ return bs
+ java = subprocess_server.JavaHelper.get_java()
+ try:
+ if platform.system() == 'Windows':
+ trial = subprocess.run(['where', java], capture_output=True)
+ else:
+ trial = subprocess.run(['which', java], capture_output=True)
+ if trial.returncode == 0:
+ return True
+ else:
+ return NotAvailableWithReason(
+ f'Unable to locate java executable: '
+ f'{try_decode(trial.stdout)}{try_decode(trial.stderr)}'
+ )
+ except (FileNotFoundError, OSError):
+ try:
+ java_path = shutil.which(java)
Review Comment:
We can simple use shutil.which(java) no need try expect here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]