You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "bolkedebruin (via GitHub)" <gi...@apache.org> on 2023/10/08 21:21:03 UTC

Re: [PR] AIP-58: Add Airflow FS [airflow]

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


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

Review Comment:
   Done.



-- 
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-unsubscribe@airflow.apache.org

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