Using Apache Airflow they install plugins by modifying sys.modules
like this:
sys.modules[operators_module.__name__] = operators_module
Which is how they get python classes from their plugins
folder to be imported via
from airflow.operators.plugin_name import Operator
even though the class Operator
exists inside
airflow/plugins/Operators.py
This makes it impossible for PyCharm to understand the above import statement because it is a non-traditional way of generating module/module name.
Is there any way to get PyCharm to have something like a module/package alias for situations like these?
If your plugin is in the same repository as the dag you can wrap you import in try-except
block:
try:
# local development
from plugin_name import Operator
except ImportError:
from airflow.operators.plugin_name import Operator
my_operator = Operator(...)
And mark plugins
directory as sources in your PyCharm Project Structure.
Afterwards PyCharm picks up your plugin source code and works nicely with autocompletion and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With