fury icon indicating copy to clipboard operation
fury copied to clipboard

[Java] The pre-check for CrossLanguageTest.java was written incorrectly for Windows11

Open urlyy opened this issue 2 months ago • 0 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Version

Latest

Component(s)

Java

Minimal reproduce step

Here is the code in ForyJava:

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:

@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");
    }
}

I just reinstalled my Windows 11 OS, so I don’t have pyfory installed. I’m currently using PowerShell. And output:

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 why not skip unit tests.

My solution

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.

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR!

urlyy avatar Oct 25 '25 02:10 urlyy