urlyy opened a new issue, #2833: URL: https://github.com/apache/fory/issues/2833
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues. ### Version Latest ### Component(s) Java ### Minimal reproduce step Here is the code in ForyJava: ```java public static void verifyPyforyInstalled() { // Don't skip in CI, fail if something goes wrong instead if (System.getenv("FORY_CI") != null) { return; } try { if (executeCommand( Arrays.asList( "python", "-c", "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec(\"pyfory\") is None else 1)"), 10, Collections.emptyMap())) { throw new SkipException("pyfory not installed"); } } catch (RuntimeException e) { if (e.getCause() instanceof IOException && e.getMessage().contains("No such file or directory")) { throw new SkipException("Python not installed or not found in PATH"); } throw e; } } ``` So I write a same unit test: ```java @Test public void testVerifyPyfory() { boolean result = executeCommand( Arrays.asList("python", "-c", "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec(\"pyfory\") is None else 1)"), 10, Collections.emptyMap() ); System.out.println("executeCommand returned: " + result); if (result) { System.out.println("pyfory is NOT installed - would skip tests"); } else { System.out.println("pyfory is installed - would run tests"); } } ``` And I reinstalled my `Windows 11` OS, so I don’t have pyfory installed. I’m currently using PowerShell. And output: ```bash Executing command: python -c import importlib.util, sys; sys.exit(0 if importlib.util.find_spec("pyfory") is None else 1) Traceback (most recent call last): File "<string>", line 1, in <module> import importlib.util, sys; sys.exit(0 if importlib.util.find_spec(pyfory) is None else 1) ^^^^^^ NameError: name 'pyfory' is not defined executeCommand returned: false pyfory is installed - would run tests ``` It seems that `find_spec(\"pyfory\")` gets converted to `find_spec(pyfory)`, so it throws an error because it can’t find a variable named `pyfory`. Regarding the return value, a Python `syntax error` and `pyfory found` produce the `same` return value `1`, and that’s the problem here. You can change it to `find_spec('pyfory')`. This works on both my macOS and Windows 11. However, I don’t have pyfory installed, so I haven’t tested the case where pyfory is found. ### What did you expect to see? 1 ### What did you see instead? 1 ### Anything Else? _No response_ ### Are you willing to submit a PR? - [ ] I'm willing to submit a PR! -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
