tchivs commented on code in PR #35803:
URL: https://github.com/apache/beam/pull/35803#discussion_r2264408107
##########
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:
You are right, just change it to this
```
def available(self):
# Directly use shutil.which to find the Java executable
cross-platform
java_path = shutil.which('java')
if java_path:
return True
# Return error message when not found (or handle according to
business logic)
return NotAvailableWithReason(f'Unable to locate java executable:
{str(e)}')
```
--
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]