Code Monkey home page Code Monkey logo

flask-appfactory's People

Contributors

crepererum avatar egabancho avatar greut avatar helix84 avatar jalavik avatar jirikuncar avatar kaplun avatar lnielsen avatar tiborsimko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-appfactory's Issues

RFC Naming: Extensions

The name "extensions" as used in Flask-AppFactory causes some confusion with Flask Extensions hence the name might not be the most appropriate.

Concepts:

def create_app():
    app = Flask("myapp")
    db = FlaskSQLAlchemy(app)
    cache = FlaskCache(app)
    return app
  • Flask-AppFactory extensions: Actually the core of Flask-AppFactory extensions is that they are used to initialise your Flask application - i.e. your monolithic application factory function is split into parts which each can be easily enabled or disabled:
def create_app():
    class config:
        EXTENSIONS = ["sqlachemy","cache"]
    return appfactory("myapp", config)

#sqlalchemy.py
def setup_app(app):
    db = FlaskSQLAlchemy(app)

#cache.py
def setup_app(app):
    cache = FlaskCache(app)

To complicate things, it is actually possible to not have a setup_app method, if you Flask-Extension just takes an app argument`` (see example):

def create_app():
    class config:
        EXTENSIONS = ["flask_sqlalchemy:FlaskSQLAlchemy", "flask_cache:FlaskCache"]
    return appfactory("myapp", config)

I.e. the main purpose of Flask-AppFactory extensions is to initialise a Flask Application.

Proposals:

  1. Live with the ambiguity and call it AppFactory extensions.
  2. or, rename Extensions to something along the lines of:
  • initializers
  • initialization
  • appsetup
  • setupsteps
  • ?

@jirikuncar @jbenito3 @tiborsimko @nharraud ?

Example and flask_appfactory.ext.jinja2

I first bumped into this following the example instructions, then replicated it by checking out the examples from github page. I started with a fresh 14.04 Ubuntu VM. Then installed AppFactory:

sudo pip install Flask-AppFactory
cd ~/flask-appfactory/examples
sudo python setup.py install

And then trying out the application:

$ myapp testsimple
Test
$ myapp testapp
Traceback (most recent call last):
  File "/usr/local/bin/myapp", line 9, in <module>
    load_entry_point('MyApp==1.0', 'console_scripts', 'myapp')()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 343, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 209, in decorator
    with __ctx.ensure_object(ScriptInfo).load_app().app_context():
  File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 185, in load_app
    rv = self.create_app(self)
  File "/usr/local/lib/python2.7/dist-packages/flask_appfactory/cli.py", line 85, in create_cli_app
    load_application(app)
  File "/usr/local/lib/python2.7/dist-packages/flask_appfactory/app.py", line 126, in load_application
    extensions=ExtensionRegistry(app),
  File "/usr/local/lib/python2.7/dist-packages/flask_registry/registries/appdiscovery.py", line 153, in __init__
    self.register(app, ext_name)
  File "/usr/local/lib/python2.7/dist-packages/flask_registry/registries/appdiscovery.py", line 163, in register
    ext = import_string(ext_name)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 437, in import_string
    sys.exc_info()[2])
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 425, in import_string
    module = import_string(module_name)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 437, in import_string
    sys.exc_info()[2])
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 430, in import_string
    raise ImportError(e)
werkzeug.utils.ImportStringError: import_string() failed for 'flask_appfactory.ext.jinja2'. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

- 'flask_appfactory' found in '/usr/local/lib/python2.7/dist-packages/flask_appfactory/__init__.pyc'.
- 'flask_appfactory.ext' not found.

Original exception:

ImportStringError: import_string() failed for 'flask_appfactory.ext'. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

- 'flask_appfactory' found in '/usr/local/lib/python2.7/dist-packages/flask_appfactory/__init__.pyc'.
- 'flask_appfactory.ext' not found.

Original exception:

ImportError: 'module' object has no attribute 'ext'

trying to run the server or shell looks the same. Any obvious things I am missing?

Change signature of appfactory()

Change method signature from:

def appfactory(app_name, module_name, load=True, **kwargs_config):

to

def appfactory(app_name, module_name, load=True, flask_config=None, app_config=None):

In order to support customising the base Flask application (i.e. base_app).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.