kunwp1 commented on code in PR #9406:
URL: https://github.com/apache/texera/pull/9406#discussion_r4557855505


##########
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:
   `udf.conf` sets `python.path` from `UDF_PYTHON_PATH`, so `configuredPython` 
already tries the same override first and then the same PATH names. The only 
difference left is the trim, and trimming is what lets a padded override run at 
all. Pointing ImageVisualizer, Histogram2D and UrlViz at `configuredPython` 
drops `environmentPython` and the comment it needs.
   
   `UdfConfig.pythonPath` also already reads this key from `udf.conf`, so the 
lookup can be `Some(UdfConfig.pythonPath.trim).filter(_.nonEmpty)`. The 
`ConfigFactory.load()` fallback never runs, since `parseResources` returns an 
empty config for a missing file rather than failing.



##########
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:
   The removed helpers took with them the three-line comment that explains this 
test: the engine reads `Url` from a column `url` since Schema ignores case, and 
pandas would raise a KeyError. `SubstringSearchOpDescSpec` lost its `Body` twin 
the same way. In the other direction, `TypeCastingOpDescSpec` and 
`TextInputSourceOpDescSpec` keep the "Python resolution follows 
FilledAreaPlotOpDescSpec" comment with nothing under it now.



##########
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:
   Six specs outside the three the issue leaves out (Aggregate, 
SpecializedFilter and HuggingFaceParse, which have open PRs) still carry their 
own copy of this lookup and probe: `HashJoinOpDescSpec`, 
`IntervalJoinOpDescSpec`, `DifferenceOpDescSpec`, `IntersectOpDescSpec`, 
`SymmetricDifferenceOpDescSpec` and `HuggingFaceBinaryValueBehaviorSpec`. Each 
maps exactly onto `configuredPython` and `canImport`, and the first five also 
redeclare `NeedsPythonPackages`. `PythonCodeRawInvalidTextSpec` also still 
inlines the tag and its 60-second `import pandas, plotly` probe, which are 
`NeedsPythonPackages` and `canImport(python, "pandas", "plotly")`, with its 
fail-or-cancel `unavailable` kept as is.



-- 
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]

Reply via email to