WeichenXu123 commented on code in PR #40954:
URL: https://github.com/apache/spark/pull/40954#discussion_r1177557772


##########
python/pyspark/pythonenv/pip_req_parser.py:
##########
@@ -0,0 +1,191 @@
+# -*- coding: utf-8 -*-
+#
+# 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.
+#
+
+import json
+import sys
+import subprocess
+from threading import Timer
+import tempfile
+import os
+import pkg_resources
+import importlib_metadata
+from itertools import filterfalse, chain
+from collections import namedtuple
+import logging
+import re
+from typing import NamedTuple, Optional
+from pathlib import Path
+
+
+# Represents a pip requirement.
+#
+# :param req_str: A requirement string (e.g. "scikit-learn == 0.24.2").
+# :param is_constraint: A boolean indicating whether this requirement is a 
constraint.
+_Requirement = namedtuple("_Requirement", ["req_str", "is_constraint"])
+
+
+def _is_comment(line):
+    return line.startswith("#")
+
+
+def _is_empty(line):
+    return line == ""
+
+
+def _strip_inline_comment(line):
+    return line[: line.find(" #")].rstrip() if " #" in line else line
+
+
+def _is_requirements_file(line):
+    return line.startswith("-r ") or line.startswith("--requirement ")
+
+
+def _is_constraints_file(line):
+    return line.startswith("-c ") or line.startswith("--constraint ")
+
+
+def _join_continued_lines(lines):
+    """
+    Joins lines ending with '\\'.
+    >>> _join_continued_lines["a\\", "b\\", "c"]
+    >>> 'abc'
+    """
+    continued_lines = []
+
+    for line in lines:
+        if line.endswith("\\"):
+            continued_lines.append(line.rstrip("\\"))
+        else:
+            continued_lines.append(line)
+            yield "".join(continued_lines)
+            continued_lines.clear()
+
+    # The last line ends with '\'
+    if continued_lines:
+        yield "".join(continued_lines)
+
+
+_req_line_regex = re.compile(r'^([a-z-_][0-9a-z-_]*).*', re.IGNORECASE)
+
+
+def _verify_req_line(line):
+    match = _req_line_regex.match(line)
+    if match is None:
+        raise ValueError(f"This pip requirement line is invalid: '{line}'")
+    if match.group(1).lower() == "pyspark":
+        raise ValueError(
+            "pyspark dependency or constraint is disallowed to set for pyspark 
UDF, "
+            "pyspark UDF worker python environment always install pyspark 
package with "
+            "exactly the same version with server side spark."
+        )
+
+
+def _parse_requirements(requirements, is_constraint, base_dir=None):

Review Comment:
   I feel it is unsafe to call `pip._internal` that is not public interface



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to