aglinxinyuan commented on code in PR #9406: URL: https://github.com/apache/texera/pull/9406#discussion_r4558927473
########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonTestSupport.scala: ########## @@ -0,0 +1,68 @@ +/* + * 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 com.typesafe.config.ConfigFactory +import org.apache.texera.amber.operator.tags.IntegrationTest +import org.scalatest.Tag + +import java.util.concurrent.TimeUnit +import scala.util.Try + +private[amber] object PythonTestSupport { Review Comment: Good catch — `HashJoinOpDescSpec`, `IntervalJoinOpDescSpec`, `DifferenceOpDescSpec`, `IntersectOpDescSpec`, `SymmetricDifferenceOpDescSpec` and `HuggingFaceBinaryValueBehaviorSpec` now use `configuredPython` and `canImport` (each probe keeps its own modules) without their local `NeedsPythonPackages`. `PythonCodeRawInvalidTextSpec` now takes `NeedsPythonPackages` and `canImport(python, "pandas", "plotly")` and keeps its `unavailable` as is, all in 4793a64b34. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonTestSupport.scala: ########## @@ -0,0 +1,68 @@ +/* + * 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 com.typesafe.config.ConfigFactory +import org.apache.texera.amber.operator.tags.IntegrationTest +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 = Try(ConfigFactory.parseResources("udf.conf").resolve()).toOption + .orElse(Try(ConfigFactory.load()).toOption) + .flatMap(c => Try(c.getConfig("python").getString("path")).toOption) + .map(_.trim) + .filter(_.nonEmpty) + (configured.toList ++ PathCandidates).distinct.find(runnable) + } + + // Preserve the env-first callers' untrimmed override; config-first callers trim it. + def environmentPython(): Option[String] = { + val configured = sys.env.get("UDF_PYTHON_PATH").filter(_.nonEmpty) + (configured.toList ++ PathCandidates).distinct.find(runnable) + } Review Comment: Agreed — `configuredPython` now reads `Some(UdfConfig.pythonPath.trim).filter(_.nonEmpty)` with no `ConfigFactory.load()` fallback. `environmentPython` and its comment are gone, and ImageVisualizer, Histogram2D and UrlViz call `configuredPython`, in 4793a64b34. ########## common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/regex/RegexOpDescSpec.scala: ########## @@ -182,35 +181,6 @@ class RegexOpDescSpec extends AnyFlatSpec with Matchers { } } - private def resolvePython(): Option[String] = { - def fromConfig: Option[String] = - Try(ConfigFactory.parseResources("udf.conf").resolve()).toOption - .orElse(Try(ConfigFactory.load()).toOption) - .flatMap(c => Try(c.getConfig("python").getString("path")).toOption) - .map(_.trim) - .filter(_.nonEmpty) - - def runnable(exe: String): Boolean = - Try(new ProcessBuilder(exe, "--version").redirectErrorStream(true).start()).toOption - .exists { p => - if (!p.waitFor(5, TimeUnit.SECONDS)) { p.destroyForcibly(); false } - else p.exitValue() == 0 - } - - (fromConfig.toList ++ List("python3", "python", "py")).distinct.find(runnable) - } - - private def canImportPandas(python: String): Boolean = - Try( - new ProcessBuilder(python, "-c", "import pandas").redirectErrorStream(true).start() - ).toOption.exists { p => - if (!p.waitFor(60, TimeUnit.SECONDS)) { p.destroyForcibly(); false } - else p.exitValue() == 0 - } - - // The engine reads `Url` from a column `url`, since Schema ignores case. pandas - // would raise a KeyError on `Url`, so the script reads the column as the table - // spells it. "RegexOpDesc.generateStandaloneCode" should Review Comment: Thanks — restored the `Url` comment here and its `Body` twin in `SubstringSearchOpDescSpec`, and dropped the two orphaned "Python resolution follows FilledAreaPlotOpDescSpec" comments in `TypeCastingOpDescSpec` and `TextInputSourceOpDescSpec`, in 4793a64b34. -- 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]
