zhongjiajie commented on code in PR #11360:
URL: https://github.com/apache/dolphinscheduler/pull/11360#discussion_r950659688


##########
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/resources_plugin/__init__.py:
##########
@@ -0,0 +1,122 @@
+# 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.
+
+"""Init resources_plugin package and dolphinScheduler ResourcePlugin object."""
+
+import importlib
+import importlib.util
+from pathlib import Path
+
+import os
+from pathlib import Path
+
+from pydolphinscheduler.exceptions import PyResPluginException
+
+path_resources_plugin = Path(__file__).parent
+
+
+# [start resource_plugin_definition]
+class ResourcePlugin:
+    """ResourcePlugin object, declare resource plugin for task and workflow to 
dolphinscheduler.
+
+    :param type: A unique, meaningful string for the ResourcePlugin,
+
+    Its value should be taken from the constant of ResourceType in 
constants.py.
+
+    :param prefix: A string representing the prefix of ResourcePlugin.
+
+    """
+
+    # [start init_method]
+    # def __init__(self, type: str, prefix: str):
+    #     self.type = type
+    #     self.prefix = prefix
+    #
+    # # [end init_method]
+    #
+    # # [start get_all_modules]
+    # def get_all_modules(self) -> Path:
+    #     """Get all res files path in resources_plugin directory."""
+    #     return (
+    #         ex
+    #         for ex in path_resources_plugin.iterdir()
+    #         if ex.is_file() and not ex.name.startswith("__")
+    #     )
+    #
+    # # [end get_all_modules]
+    #
+    # # [start import_module]
+    # def import_module(self, script_name, script_path):
+    #     """Import module."""
+    #     spec = importlib.util.spec_from_file_location(script_name, 
script_path)
+    #     module = importlib.util.module_from_spec(spec)
+    #     spec.loader.exec_module(module)
+    #     plugin = getattr(module, self.type.capitalize())
+    #     return plugin(self.prefix)
+    #
+    # # [end import_module]
+    #
+    # @property
+    # # [start resource]
+    # def resource(self):
+    #     """Dynamically return resource plugin."""
+    #     for ex in self.get_all_modules():
+    #         if ex.stem == self.type:
+    #             return self.import_module(ex.name, str(ex))
+    #     raise PyResPluginException("{} type is not 
supported.".format(self.type))
+
+    # [end resource]
+
+    class Local:
+        """Local object, declare local resource plugin for task and workflow 
to dolphinscheduler.
+
+        :param prefix: A string representing the prefix of Local.
+
+        """
+
+        # [start init_method]
+        def __init__(self, prefix: str):
+            self._prefix = prefix
+
+        # [end init_method]
+
+        @property
+        def prefix(self):
+            """Get the _prefix attribute."""
+            return self._prefix
+
+        # [start read_file_method]
+        def read_file(self, suf: str):

Review Comment:
   I do not think that a good idea, If we have to do this, I prefer we add 
class `ResourcePlugin` in `core` module. and make class `local` in the new 
module `resource_plugin`. and all class in `resource_plugin` inherit from class 
`ResourcePlugin`
   
   and for the optional value like `access token`, `username`, `pasword` in 
both GitHub and gitlab, you can use
   
   ```py
   class ResourcePlugin:
       def __init__(
           self,
           type: str,
           prefix: str,
           username: Optional[str] = None,
           password: Optional[str] = None,
           access_token: Optional[str] = None,
           *args,
           *kwargs
       )
   ```



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