aglinxinyuan commented on code in PR #9406: URL: https://github.com/apache/texera/pull/9406#discussion_r4578357188
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonTestSupport.scala: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.util + +import org.apache.texera.amber.operator.tags.IntegrationTest +import org.apache.texera.common.config.UdfConfig +import org.scalatest.Tag + +import java.util.concurrent.TimeUnit +import scala.util.Try + +private[amber] object PythonTestSupport { + val NeedsPythonPackages: Tag = Tag(classOf[IntegrationTest].getName) + private val PathCandidates = List("python3", "python", "py") + + def configuredPython(): Option[String] = { + val configured = Some(UdfConfig.pythonPath.trim).filter(_.nonEmpty) + (configured.toList ++ PathCandidates).distinct.find(runnable) + } + + def pathPython(): Option[String] = PathCandidates.find(runnable) + + def canImport(python: String, modules: String*): Boolean = + canImportWithin(python, 60, modules: _*) + + def canImportWithin(python: String, timeoutSeconds: Int, modules: String*): Boolean = + succeeds(Seq(python, "-c", "import " + modules.mkString(", ")), timeoutSeconds) + + private def runnable(executable: String): Boolean = + succeeds(Seq(executable, "--version"), 5) + + private def succeeds(command: Seq[String], timeoutSeconds: Int): Boolean = + Try(new ProcessBuilder(command: _*).redirectErrorStream(true).start()).toOption.exists { Review Comment: Good catch — the probe now adds `.redirectOutput(ProcessBuilder.Redirect.DISCARD)` in e9cbf96c4d. On Windows the old body already times out once a child prints 9,000 bytes, while the new one passes at 1,000,000 on either stream. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonTestSupport.scala: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.util + +import org.apache.texera.amber.operator.tags.IntegrationTest +import org.apache.texera.common.config.UdfConfig +import org.scalatest.Tag + +import java.util.concurrent.TimeUnit +import scala.util.Try + +private[amber] object PythonTestSupport { Review Comment: Agreed — merged `main`, and `DistinctOpDescSpec` now uses `configuredPython()` and `canImport(python, "pandas", "numpy")` without its local `NeedsPythonPackages`, in e9cbf96c4d. In workflow-operator's tests, only the three specs #9401 leaves out still carry a copy. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonCodeRawInvalidTextSpec.scala: ########## @@ -297,7 +261,7 @@ final class PythonCodeRawInvalidTextSpec extends AnyFunSuite { } test("PythonOperatorDescriptor.generatePythonCode should py_compile under isolated Python") { - val pythonExeOpt = loadPythonExeFromUdfConf() + val pythonExeOpt = configuredPython() if (pythonExeOpt.isEmpty) { fail( "python.path not found in udf.conf (or application.conf). Configure python.path to enable this test." Review Comment: Applied — the failure now reads `No runnable Python. Tried udf.conf python.path (UDF_PYTHON_PATH), python3, python and py.`, in e9cbf96c4d. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonTestSupport.scala: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.util + +import org.apache.texera.amber.operator.tags.IntegrationTest +import org.apache.texera.common.config.UdfConfig +import org.scalatest.Tag + +import java.util.concurrent.TimeUnit +import scala.util.Try + +private[amber] object PythonTestSupport { + val NeedsPythonPackages: Tag = Tag(classOf[IntegrationTest].getName) + private val PathCandidates = List("python3", "python", "py") + + def configuredPython(): Option[String] = { Review Comment: Thanks — `configuredPython` now carries that comment with its lookup order, in e9cbf96c4d. -- 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]
