I am trying to build my own custom add-on in order to handle OAuth login external to my application in a generic way.
I have read the documentation on implementing OAuth, as well as the documentation on creating add-ons. I have the code working if I hack it into the application (no add-on), but I don't want this. I want it in such a way that I can simply include the code and set a variable in my config.py to use it. That's why I am trying the add-on thing.
I moved the code I got working inside the application out to the add-on. I used the fabmanager to generate the skeleton for me, then just fixed the model.py file, which is where my code sits, and the config files. Then I added the below line, as per the docs, in my main app's config.py file to tell it to use my add-on.
ADDON_MANAGERS = ['fab_addon_x.manager.X']
This does not work however. I get a "ModuleNotFoundError".
File "/usr/local/lib/python3.6/site-packages/flask_appbuilder/base.py", line 30, in dynamic_class_import
package = __import__(module_path)
ModuleNotFoundError: No module named 'fab_addon_x'
I've placed the add-on code both on the same level as the main project:
/myapp/
/fab_addon_x/
and inside the main project:
/myapp/
/myapp/fab_addon_x/
Neither of these work.
Full folder structure
/usr/local/lib/python3.6/site-packages/myapp/
- __init__.py
- __pycache__
- bin
- cache_util.py
- cli.py
- config.py
- connectors
- data
- dataframe.py
- db_engine_specs.py
- db_engines
- dict_import_export_util.py
- extract_table_names.py
- forms.py
- import_util.py
- jinja_context.py
- legacy.py
- migrations
- models
- security.py
- sql_lab.py
- sql_parse.py
- static
- stats_logger.py
- templates
- translations
- utils.py
- views
- viz.py
I've placed the add-on folder both at this level and one level up. Add-on folder structure:
fab_addon_x
- README.rst
- config.py
- fab_addon_x
- __init__.py
- manager.py
- models.py
- templates
- translations
- version.py
- views.py
- run.py
- setup.py
Is there a specific way to register my add-on? Or is this a straight forward referencing issue that I just can't seem to figure out?
Edit 1
Changed "ADDON_MANAGERS = ['fab_addon_first.manager.FirstAddOnManager']" to what it is now.
Edit 2
Added folder structure
So I figured out my own issue here. The docs doesn't mention this anywhere, but if you don't upload your add-on to the registry and just copy the files into the directory you first have to install it. This probably sounds self-explanatory for those familiar with python, but I'm not, so it wasn't for me.
The below command will install it and you should be good to go:
python setup.py install