tchivs opened a new pull request, #35618:
URL: https://github.com/apache/beam/pull/35618

   # Fix Windows compatibility for YAML JavaJarProvider
   
   ## Description
   
   This PR fixes a cross-platform compatibility issue in the YAML provider 
where the `JavaJarProvider.available()` method fails on Windows systems due to 
the use of the Unix-specific `which` command.
   
   ### Problem
   The original implementation uses `subprocess.run(['which', 
java_executable])` which works on Unix/Linux systems but fails on Windows with 
`FileNotFoundError: [WinError 2] The system cannot find the file specified` 
because Windows doesn't have a `which` command.
   
   ### Solution
   - **Platform detection**: Use `platform.system()` to detect the operating 
system
   - **Windows compatibility**: Use `where` command on Windows instead of 
`which`
   - **Unix/Linux compatibility**: Keep existing `which` command behavior 
unchanged
   - **Fallback mechanism**: Add `shutil.which()` as a cross-platform fallback 
for edge cases
   - **Error handling**: Improved error handling for `FileNotFoundError` and 
`OSError`
   
   ### Changes Made
   - Modified `JavaJarProvider.available()` method in 
`apache_beam/yaml/yaml_provider.py`
   - Use platform-specific commands (`where` on Windows, `which` on Unix/Linux) 
for Java detection  
   - Add `shutil.which` fallback for cross-platform compatibility
   - Maintain backward compatibility with existing Unix/Linux behavior
   
   ### Testing
   - ✅ Tested on Windows 10/11
   - ✅ Tested on Linux Ubuntu
   
   
   ### Backward Compatibility
   - ✅ **Fully backward compatible** - no breaking changes
   - ✅ **Unix/Linux behavior unchanged** - existing functionality preserved
   - ✅ **Same return types** - maintains `bool` or `NotAvailableWithReason`
   - ✅ **Same error messages** - consistent user experience
   
   ### Code Quality
   - ✅ Follows existing code style and conventions
   - ✅ Includes proper error handling for all edge cases
   - ✅ Maintains the same method signature and return types
   - ✅ Added appropriate inline comments
   - ✅ Preserves existing pylint disable comments
   
   ## Impact
   This change enables Windows users to use Apache Beam's YAML functionality 
without requiring workarounds, manual patches, or Unix-like environments (WSL, 
Git Bash, etc.).
   
   **Before**: Windows users encounter `FileNotFoundError` when using YAML 
providers
   **After**: YAML providers work seamlessly across all supported platforms
   
   ------------------------
   - [x] fixes  [#35617](https://github.com/apache/beam/issues/35617)
   - [x] Update `CHANGES.md` with noteworthy changes.
   
   
   ### Additional Notes
   - This is a small, focused fix that addresses a specific cross-platform 
compatibility issue
   - No ICLA required as this is a minor bugfix
   - Ready for review and testing on multiple platforms


-- 
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: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to