You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/24 22:44:05 UTC

[GitHub] [airflow] mik-laj opened a new pull request #9002: Support properties in plugins

mik-laj opened a new pull request #9002:
URL: https://github.com/apache/airflow/pull/9002


   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [X] Description above provides context of the change
   - [X] Unit tests coverage for changes (not needed for documentation changes)
   - [X] Target Github ISSUE in description if exists
   - [X] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [X] Relevant documentation is updated including usage instructions.
   - [X] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


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

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



[GitHub] [airflow] mik-laj merged pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #9002:
URL: https://github.com/apache/airflow/pull/9002


   


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

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



[GitHub] [airflow] turbaszek commented on a change in pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9002:
URL: https://github.com/apache/airflow/pull/9002#discussion_r429848205



##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()

Review comment:
       ```suggestion
                   plugin_instance = plugin_class()
   ```
   WDYT?

##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()
                 if callable(getattr(plugin_obj, 'on_load', None)):
                     plugin_obj.on_load()
-                    plugins.append(plugin_obj)
+                    plugins.append(plugin_obj())

Review comment:
       I'm not sure, but do we call here an instantiated class (via `__call__`)? Why we do this?  




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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9002:
URL: https://github.com/apache/airflow/pull/9002#discussion_r429854416



##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()
                 if callable(getattr(plugin_obj, 'on_load', None)):
                     plugin_obj.on_load()
-                    plugins.append(plugin_obj)
+                    plugins.append(plugin_obj())

Review comment:
       We call the class constructor.Previously, we only used the class, not the plugin object.
   ```
   >>> class AirflowTestPropertyPlugin(AirflowPlugin):
   ...     name = "test_property_plugin"
   ...     @property
   ...     def operators(self):
   ...         from airflow.models.baseoperator import BaseOperator
   ...         class PluginPropertyOperator(BaseOperator):
   ...             pass
   ...         return [PluginPropertyOperator]
   ...
   >>> print(AirflowTestPropertyPlugin().operators)
   [<class '__main__.AirflowTestPropertyPlugin.operators.<locals>.PluginPropertyOperator'>]
   >>> print(AirflowTestPropertyPlugin.operators)
   <property object at 0x10b2172c8>
   
   ```




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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9002:
URL: https://github.com/apache/airflow/pull/9002#discussion_r429859599



##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()
                 if callable(getattr(plugin_obj, 'on_load', None)):
                     plugin_obj.on_load()
-                    plugins.append(plugin_obj)
+                    plugins.append(plugin_obj())

Review comment:
       Good point. Fixed. 




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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9002:
URL: https://github.com/apache/airflow/pull/9002#discussion_r429857486



##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()

Review comment:
       I updated the PR.




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

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



[GitHub] [airflow] turbaszek commented on a change in pull request #9002: Support properties in plugins

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9002:
URL: https://github.com/apache/airflow/pull/9002#discussion_r429858176



##########
File path: airflow/plugins_manager.py
##########
@@ -145,11 +145,12 @@ def load_entrypoint_plugins():
     for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
         try:
-            plugin_obj = entry_point.load()
-            if is_valid_plugin(plugin_obj):
+            plugin_class = entry_point.load()
+            if is_valid_plugin(plugin_class):
+                plugin_obj = plugin_class()
                 if callable(getattr(plugin_obj, 'on_load', None)):
                     plugin_obj.on_load()
-                    plugins.append(plugin_obj)
+                    plugins.append(plugin_obj())

Review comment:
       Currently we have:
   ```python
   plugin_class = entry_point.load() # class object
   plugin_obj = plugin_class() # class instance created via calling __init__
   plugin_obj() # we call existing instance so it has to have __call__
   ```
   What am I missing?




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

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