ktmud edited a comment on issue #9077: [SIP-35] Proposal for Improving 
Superset’s Python Code Organization
URL: 
https://github.com/apache/incubator-superset/issues/9077#issuecomment-586536501
 
 
   Chime in my two cents as a passerby.  I really like that different modules 
have their independent folders and we are introducing conventions and 
increasing consistency. I think an intuitive code structure and consistent 
paradigms help a lot for future contributors to understand the code.
   
   Sharing the approach I took in one of my older projects ([a general purpose 
CMS](https://github.com/ktmud/david/tree/master/david
   )).  It's slightly different than what is proposed, but very similar in 
concept.
   
   All my python files are organized [like 
this](https://github.com/ktmud/david/tree/master/david):
   
   ```
   ├── __init__.py
   ├── app.py
   ├── core/   # core data models, user accounts, base data entities etc
   ├── ext/      # 3rd-party/non-essential extensions, s3 uploads, etc
   ├── lib/       # db mixins, cache decorators, utilities
   ├── modules/   # modules as organized in the main menu (URL route)
   │   ├── __init__.py  # import and compose all modules
   │   ├── module_1
   │   │   ├── __init__.py
   │   │   ├── admin.py   # admin views, a separate Blueprint for editing 
objects
   │   │   ├── model.py   # operation on data entities, objects for data access
   │   │   └── view.py     # User facing Blueprint for "module_1", handlers 
parsing parameters
   │   ├── module_2
   │   │   ├── __init__.py
   │   │   ├── admin.py
   │   │   ├── model.py
   │   │   └── view.py
   ```
   
   I find the separation of core/shared functionalities (and the addition of a 
"modules" folder) especially useful because it makes the whole project easier 
to navigate.
   
   Loading modules  and booting the app is as simple as 
[this](https://github.com/ktmud/david/blob/master/david/ext/modules.py). 
   
   ```python
   def load_module(app, name):
       """Dynamically load modules in the `modules/` folder.
       package = 'david.modules.%s' % name
       mod = __import__(package, fromlist=['admin', 'bp', 'setup', 'view'])
   
       # register module blueprint and setup
       register_views(app, mod)
   
       if hasattr(mod, 'view'):
           register_views(app, mod.view)
   
       return mod
   
   def register_views(app, *view_modules):
       """Register views, including API endpoints"""
       for v in view_modules:
           if hasattr(v, 'bp'):
               app.register_blueprint(v.bp)
           if hasattr(v, 'setup'):
               v.setup(app)
   ```
   
   It looks like the `boot.py` file will achieve the same goal.
   
   Hope this helps.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to