rawwar commented on code in PR #37165:
URL: https://github.com/apache/airflow/pull/37165#discussion_r1477293181


##########
airflow/utils/file.py:
##########
@@ -379,3 +382,12 @@ def iter_airflow_imports(file_path: str) -> Generator[str, 
None, None]:
     for m in _find_imported_modules(parsed):
         if m.startswith("airflow."):
             yield m
+
+
+def get_unique_dag_module_name(file_path: str) -> str:
+    """Returns a unique module name in the format unusual_prefix_{sha1 of 
module's file path}_{original module name}."""
+    if isinstance(file_path, str):
+        path_hash = hashlib.sha1(file_path.encode("utf-8")).hexdigest()
+        org_mod_name = Path(file_path).stem
+        return MODIFIED_DAG_MODULE_NAME.format(path_hash=path_hash, 
module_name=org_mod_name)
+    raise ValueError("file_path should be a string to generate unique module 
name")

Review Comment:
   I think, there's no way to get `file_path` as anything other than a string 
here. But, assuming it was used incorrectly, I am not sure what kind of 
exception I should be raising. `ValueError` feels good enough. But, please do 
suggest



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