bobbai00 commented on code in PR #9406: URL: https://github.com/apache/texera/pull/9406#discussion_r4569459229
########## 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: **Advisory:** This merges stderr into stdout and never reads the pipe. A child that prints more than the pipe holds blocks, and the probe reports it as failing after the full deadline. With the same calls on JDK 17 and macOS, 60,000 bytes of output passes and 70,000 times out. Nothing prints that much today and the removed copies did the same, so this is optional. I'd add `.redirectOutput(ProcessBuilder.Redirect.DISCARD)` before `.start()`. ########## 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: **Advisory:** `main` picked up a fourth private copy after this branch was cut. [`DistinctOpDescSpec`](https://github.com/apache/texera/blob/ed535316417ad9f17883c9456857d2a9ce3bbf34/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/distinct/DistinctOpDescSpec.scala#L174-L198) got one from #8975 on Nov 12. It is not one of the three specs #9401 leaves out, so the issue would close with a copy it did not exempt. It maps onto `configuredPython()` and `canImport(python, "pandas", "numpy")` as `HashJoinOpDescSpec` does. I'd merge `main` and convert it here. ########## 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: **Polish:** This message no longer matches what fails. `configuredPython()` is empty only when none of the configured path, `python3`, `python` and `py` runs. Nothing reads `application.conf` now that the `ConfigFactory.load()` fallback is gone with `loadPythonExeFromUdfConf`. ```suggestion "No runnable Python. Tried udf.conf python.path (UDF_PYTHON_PATH), python3, python and py." ``` ########## 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: **Polish:** Nothing states the lookup order any more. Fifteen of the removed copies carried a line like `udf.conf python.path (UDF_PYTHON_PATH), then python3 / python / py`. The name alone reads as config-only, while it falls back to the PATH names. The other test helpers in this module have a header comment (`SetRows.scala:29`, `PythonWorkerPool.scala:45`). ```suggestion /** The first interpreter that runs: `python.path` from udf.conf (set by `UDF_PYTHON_PATH`), then * python3, python and py from the PATH. */ def configuredPython(): Option[String] = { ``` -- 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]
