bolkedebruin commented on code in PR #34729:
URL: https://github.com/apache/airflow/pull/34729#discussion_r1347480793


##########
airflow/io/fs/__init__.py:
##########
@@ -0,0 +1,969 @@
+# 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.
+from __future__ import annotations
+
+import functools
+import os.path
+import uuid
+from typing import cast
+from urllib.parse import urlparse
+from dataclasses import dataclass
+from os import PathLike
+
+from fsspec import AbstractFileSystem
+from fsspec.callbacks import NoOpCallback
+
+from airflow.io.fsspec import SCHEME_TO_FS
+
+
+@dataclass
+class Mount(PathLike):
+    source: str
+    mount_point: str
+
+    fs: AbstractFileSystem
+
+    conn_id: str | None = None
+
+    def wrap(self, method: str, *args, **kwargs):
+        """
+        Wrap a filesystem method to replace the mount point with the original 
source.
+
+        :param method: the method to wrap
+        :type method: str
+        :param args: the arguments to pass to the method
+        :type args: tuple
+        :param kwargs: the keyword arguments to pass to the method
+        :type kwargs: dict
+        :return: the result of the method
+        :rtype: Any
+        """
+        path = kwargs.pop("path") if "path" in kwargs else args[0]
+        path = self.replace_mount_point(cast(str, path))
+
+        return getattr(self.fs, method)(path, *args[1:], **kwargs)
+
+    def __fspath__(self):
+        return self.mount_point
+
+    def __str__(self):
+        return self.mount_point
+
+    def __truediv__(self, other):
+        return os.path.join(self.mount_point, other.lstrip(os.sep))
+
+    def __getattr__(self, item):
+        return functools.partial(self.wrap, item)

Review Comment:
   Mount is a thin wrapper over AbstractFilesystem with some path rewriting 
logic and Airflow Metadata added. I'd like users to treat it the same way as an 
Filesystem (e.g. Mnt.ls() instead of Mnt.fs.ls() which is less intuitive and we 
would still need to somehow hijack the call to rewrite the path). If not doing 
this, we need to copy/reimplement all methods (again). The additional benefit 
of doing it this way is that it automatically adheres to changes in the fsspec 
API. Still, I agree with you that discoverability suffers (when using simple 
mounts) so if you know how to catch to birds with one stone I am all for it. 



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