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 2022/02/02 06:14:34 UTC

[GitHub] [airflow] uranusjr commented on issue #21259: Custom Timetables must be imported relative to $PLUGINS_FOLDER

uranusjr commented on issue #21259:
URL: https://github.com/apache/airflow/issues/21259#issuecomment-1027620661


   The asterisk is optional in this case. It means `run_after` can only be called as a keyword argument, while the example code allows the caller to use it as _either_ positional or keyword. But since the function is always only called with keyword arguments in Airflow, both syntax will work. The example code is not wrong.
   
   As for the absolute import issue, unfortunately this is a (somewhat obsecure and annoying) problem in Python. If you add a directory in `sys.path` via multiple paths, names imported from different `sys.path` items have different identities.
   
   ```console
   $ tree
   .
   |-- plugins
       |-- __init__.py
       `-- mod.py
   $ cat plugins/mod.py
   class A:
       pass
   $ PYTHONPATH=plugins python -q  # Simulate how Airflow loads the plugin directory.
   >>> from plugins.mod import A as AFromAbsolute
   >>> from mod import A as AFromPlugin
   >>> AFromAbsolute == AFromPlugin
   False
   ```
   
   And since timetable is loaded fomr plugin, you must import relative to the plugin directory, or somewhere that’s not related to the plugin directory hierarchy, such as `site-packages`. There are _probably_ hacks we can use to work around this, but this kind of “working above” the Python language rules is not a good idea to me.


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