potiuk commented on code in PR #50446:
URL: https://github.com/apache/airflow/pull/50446#discussion_r2083638124


##########
providers/standard/src/airflow/providers/standard/operators/python.py:
##########
@@ -848,10 +852,39 @@ def execute_callable(self):
 
     def _iter_serializable_context_keys(self):
         yield from self.BASE_SERIALIZABLE_CONTEXT_KEYS
-        if self.system_site_packages or "apache-airflow" in self.requirements:
+
+        found_airflow = found_pendulum = False
+
+        if self.system_site_packages:
+            # If we're using system packages, assume both are present
+            found_airflow = found_pendulum = True
+        else:
+            for raw_str in self.requirements:
+                line = raw_str.strip()
+                # Skip blank lines and full‐line comments
+                if not line or line.startswith("#"):
+                    continue
+
+                # Strip off any inline comment
+                # e.g. turn "foo==1.2.3  # comment" → "foo==1.2.3"
+                req_str = re.sub(r"#.*$", "", line).strip()
+
+                try:
+                    req = Requirement(req_str)
+                except (InvalidRequirement, InvalidSpecifier, InvalidVersion) 
as e:
+                    raise ValueError(f"Invalid requirement '{raw_str}': {e}") 
from e
+
+                name = req.name.lower()

Review Comment:
   NIT. I think Requirement already normalizes package name - which covers 
replacement of ".", "_" with "-" and lowercasing the name: 
   
   https://packaging.python.org/en/latest/specifications/name-normalization/



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to