示例#1
0
def test_import_app_py_ext(monkeypatch):
    monkeypatch.chdir(os.path.dirname(__file__))

    with pytest.raises(ImportError) as exc_info:
        util.import_app("support.py")

    assert "did you mean" in str(exc_info.value)
def test_import_app():
    assert util.import_app('support:app')

    with pytest.raises(ImportError) as err:
        util.import_app('a:app')
    assert 'No module' in str(err)

    with pytest.raises(AppImportError) as err:
        util.import_app('support:wrong_app')
    msg = "Failed to find application object 'wrong_app' in 'support'"
    assert msg in str(err)
示例#3
0
def test_import_app():
    assert util.import_app('support:app')

    with pytest.raises(ImportError) as err:
        util.import_app('a:app')
    assert 'No module' in str(err)

    with pytest.raises(AppImportError) as err:
        util.import_app('support:wrong_app')
    msg = "Failed to find application object 'wrong_app' in 'support'"
    assert msg in str(err)
示例#4
0
    def load(self):
        """ Attempt an import of the specified application """

        if isinstance(self.application,str):
            return util.import_app(self.application)
        else:
            return self.application
示例#5
0
文件: manage.py 项目: ei-grad/muffin
def run():
    """ CLI endpoint. """
    sys.path.insert(0, os.getcwd())

    parser = argparse.ArgumentParser(description="Manage Application")
    parser.add_argument('app', metavar='app',
                        type=str, help='Application module path')
    parser.add_argument('--config', type=str, help='Path to configuration.')
    parser.add_argument('--version', action="version", version=__version__)

    args_ = [_ for _ in sys.argv[1:] if _ not in ["--help", "-h"]]
    args_, unknown = parser.parse_known_args(args_)
    if args_.config:
        os.environ[CONFIGURATION_ENVIRON_VARIABLE] = args_.config

    from gunicorn.util import import_app

    try:
        app_uri = args_.app
        if ':' not in app_uri:
            app_uri += ':app'
        app = import_app(app_uri)
        app.logger.info('Application is loaded: %s' % app.name)

    except Exception as e:
        print(e)
        raise sys.exit(1)

    app.manage()
示例#6
0
def run():
    """CLI endpoint."""
    sys.path.insert(0, os.getcwd())
    logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])

    parser = argparse.ArgumentParser(description="Manage Application", add_help=False)
    parser.add_argument('app', metavar='app',
                        type=str, help='Application module path')
    parser.add_argument('--config', type=str, help='Path to configuration.')
    parser.add_argument('--version', action="version", version=__version__)

    args_, subargs_ = parser.parse_known_args(sys.argv[1:])
    if args_.config:
        os.environ[CONFIGURATION_ENVIRON_VARIABLE] = args_.config

    from gunicorn.util import import_app

    app_uri = args_.app
    if ':' not in app_uri:
        app_uri += ':app'
    try:
        app = import_app(app_uri)
        app.uri = app_uri
        app.logger.info('Application is loaded: %s' % app.name)
    except Exception as exc:
        logging.exception(exc)
        raise sys.exit(1)

    app.manage(*subargs_, prog='muffin %s' % args_.app)
示例#7
0
 def load(self):
     try:
         djangoapp.make_default_env(self.cfg)
     except RuntimeError:
         # ignore silently error while loading non django apps.
         pass
     return util.import_app(self.app_uri)
示例#8
0
        def load(self):
            """ Attempt an import of the specified application """

            if isinstance(self.application, str):
                return util.import_app(self.application)
            else:
                return self.application
示例#9
0
def run():
    """ CLI endpoint. """
    sys.path.insert(0, os.getcwd())

    parser = argparse.ArgumentParser(description="Manage Application")
    parser.add_argument('app',
                        metavar='app',
                        type=str,
                        help='Application module path')
    parser.add_argument('--config', type=str, help='Path to configuration.')
    parser.add_argument('--version', action="version", version=__version__)

    args_ = [_ for _ in sys.argv[1:] if _ not in ["--help", "-h"]]
    args_, unknown = parser.parse_known_args(args_)
    if args_.config:
        os.environ[CONFIGURATION_ENVIRON_VARIABLE] = args_.config

    from gunicorn.util import import_app

    try:
        app_uri = args_.app
        if ':' not in app_uri:
            app_uri += ':app'
        app = import_app(app_uri)
        app.logger.info('Application is loaded: %s' % app.name)

    except Exception as e:
        print(e)
        raise sys.exit(1)

    app.manage()
示例#10
0
 def load(self):
     brightsky_mods = [
         mod for name, mod in sys.modules.items()
         if name.startswith('brightsky.')]
     for mod in brightsky_mods:
         importlib.reload(mod)
     return import_app(self.app_uri)
示例#11
0
def run():
    """CLI endpoint."""
    sys.path.insert(0, os.getcwd())
    logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])

    parser = argparse.ArgumentParser(description="Manage Application",
                                     add_help=False)
    parser.add_argument('app',
                        metavar='app',
                        type=str,
                        help='Application module path')
    parser.add_argument('--config', type=str, help='Path to configuration.')
    parser.add_argument('--version', action="version", version=__version__)

    args_, subargs_ = parser.parse_known_args(sys.argv[1:])
    if args_.config:
        os.environ[CONFIGURATION_ENVIRON_VARIABLE] = args_.config

    from gunicorn.util import import_app

    app_uri = args_.app
    if ':' not in app_uri:
        app_uri += ':app'
    try:
        app = import_app(app_uri)
        app.uri = app_uri
        app.logger.info('Application is loaded: %s' % app.name)
    except Exception as exc:
        logging.exception(exc)
        raise sys.exit(1)

    app.manage(*subargs_, prog='muffin %s' % args_.app)
示例#12
0
 def load(self):
     try:
         djangoapp.make_default_env(self.cfg)
     except RuntimeError:
         # ignore silently error while loading non django apps.
         pass
     return util.import_app(self.app_uri)
示例#13
0
文件: pytest.py 项目: MarSoft/muffin
def app(pytestconfig, request):
    """ Provide an example application. """
    if pytestconfig.app:
        return util.import_app(pytestconfig.app)

    logging.warn(
        'Improperly configured. Please set ``muffin_app`` in your pytest config. '
        'Or use ``--muffin-app`` command option.')
    return None
示例#14
0
def app(pytestconfig, request):
    """ Provide an example application. """
    if pytestconfig.app:
        return util.import_app(pytestconfig.app)

    logging.warn(
        'Improperly configured. Please set ``muffin_app`` in your pytest config. '
        'Or use ``--muffin-app`` command option.')
    return None
示例#15
0
 def load(self):
     """Return our application to be run."""
     app = util.import_app("dallinger.experiment_server.sockets:app")
     app.secret_key = app.config["SECRET_KEY"] = os.environ.get(
         "FLASK_SECRET_KEY")
     if self.options.get("mode") == "debug":
         app.debug = True
     else:
         app = ProxyFix(app)
     return app
示例#16
0
文件: worker.py 项目: dveselov/muffin
    def load(self):
        """Load a Muffin application."""
        # Fix paths
        os.chdir(self.cfg.chdir)
        sys.path.insert(0, self.cfg.chdir)

        app = self.app_uri
        if not isinstance(app, Application):
            app = import_app(app)

        return app
示例#17
0
    def load(self):
        '''load method

        Imports our application and returns it to be run.
        
        FORMAT: <module>:<WSGI object>
        
        If the WSGI object is not named 'application', it must
        be included in the function parameter.
        '''
        return util.import_app("resultapp.main:app")
示例#18
0
文件: worker.py 项目: ei-grad/muffin
    def load(self):
        """ Load a Muffin application. """
        # Fix paths
        os.chdir(self.cfg.chdir)
        sys.path.insert(0, self.cfg.chdir)

        app = self.app_uri
        if not isinstance(app, Application):
            app = import_app(app)

        return app
示例#19
0
文件: main.py 项目: lericson/gunicorn
    def get_app(parser, opts, args):
        if len(args) != 1:
            parser.error("No application module specified.")


        opts.default_proc_name = args[0]
            
        try:
            return util.import_app(args[0])
        except:
            parser.error("Failed to import application module.")
    def load(self):
        '''load method

        Imports our application and returns it to be run.
        
        FORMAT: <module>:<WSGI object>
        
        If the WSGI object is not named 'application', it must
        be included in the function parameter.
        '''        
        return util.import_app("resultapp.main:app")
示例#21
0
    def load(self):
        if self._app:
            app = self._app
            if isinstance(app, str):
                app = import_app(self._app)
        else:
            app = self._load_app()

        if hasattr(app, "load_conf"):
            app.load_conf(self._app_conf)

        return app
示例#22
0
                def load(self):
                    """Reload modules."""
                    if not app.uri:
                        return app

                    module, *_ = app.uri.split(':', 1)
                    if module in sys.modules:
                        sys.modules.pop(module)
                        paths = [
                            p for p in sys.modules
                            if p.startswith('%s.' % module)
                        ]
                        for path in paths:
                            sys.modules.pop(path)
                    return import_app(app.uri)
示例#23
0
    def load(self):
        """Load a Muffin application."""
        # Fix paths
        os.chdir(self.cfg.chdir)
        sys.path.insert(0, self.cfg.chdir)

        app = self.app_uri
        if not isinstance(app, Application):
            module, *_ = self.app_uri.split(':', 1)
            if module in sys.modules:
                sys.modules.pop(module)
                paths = [p for p in sys.modules if p.startswith('%s.' % module)]
                for path in paths:
                    sys.modules.pop(path)
            app = import_app(app)

        return app
示例#24
0
def app(pytestconfig, request):
    """ Provide an example application. """
    from muffin.utils import to_coroutine
    from gunicorn import util

    if pytestconfig.app:
        app = util.import_app(pytestconfig.app)

        loop = asyncio.get_event_loop()
        for plugin in app.ps.values():
            if not hasattr(plugin, 'conftest'):
                continue
            loop.run_until_complete(to_coroutine(plugin.conftest)())

        return app

    logging.warn(
        'Improperly configured. Please set ``muffin_app`` in your pytest config. '
        'Or use ``--muffin-app`` command option.')

    return None
示例#25
0
文件: wsgi.py 项目: DH-Box/dhbox
    def load(self):
        '''load method

        Imports our application and returns it to be run.
        '''        
        return util.import_app("dhbox:app")
示例#26
0
 def load(self):
     self.chdir()
     if self.app_uri:
         return import_app(self.app_uri)
     return self._app
示例#27
0
 def load(self):
     return util.import_app(self.options.get("module_path"))
示例#28
0
    def load_wsgiapp(self):
        self.chdir()

        # load the app
        return util.import_app(self.app_uri)
示例#29
0
 def load(self):
     return util.import_app(self.app_uri)
示例#30
0
 def load(self):
     '''load method
     Imports our application and returns it to be run.
     '''
     return util.import_app("psiturk.experiment:app")
示例#31
0
 def load(self):
     self.chdir()
     if self.app_uri:
         return import_app(self.app_uri)
     return self._app
示例#32
0
 def make_app(self, config):
     return util.import_app(config['wsgi_app'])
示例#33
0
 def load(self):
     """Return our application to be run."""
     app = util.import_app("dallinger.experiment_server.sockets:app")
     if self.options.get('mode') == 'debug':
         app.debug = True
     return app
示例#34
0
    def load_wsgiapp(self):
        self.chdir()

        # load the flask
        return util.import_app(self.app_uri)
示例#35
0
文件: gunicorn.py 项目: fhk/Dallinger
from __future__ import absolute_import

from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
from dallinger.config import get_config
import logging

logger = logging.getLogger(__file__)

app = util.import_app("dallinger.experiment_server.experiment_server:app")


def when_ready(arbiter):
    # Signal to parent process that server has started.
    print('Ready.')


class StandaloneServer(Application):
    loglevels = ["debug", "info", "warning", "error", "critical"]

    def __init__(self):
        """__init__ method
        Load the base config and assign some core attributes.
        """
        self.usage = None
        self.cfg = None
        self.callable = None
        self.prog = None
        self.logger = None
示例#36
0
 def load(self):
     """Return our application to be run."""
     return util.import_app("dallinger.experiment_server.sockets:app")
示例#37
0
 def load(self):
     return util.import_app("todos:app")
示例#38
0
文件: app.py 项目: pigsoldierlu/sheep
 def make_app(self, config):
     handle = util.import_app(config['websocket'])
     app = WebSocketWSGI(handle)
     return app
示例#39
0
文件: app.py 项目: pigsoldierlu/sheep
 def make_app(self, config):
     return util.import_app(config['wsgi_app'])
示例#40
0
 def app(self):
   return import_app(self.path)  # Re-import to support live reloading
示例#41
0
    def load_wsgiapp(self):
        self.chdir()

        # load the app
        # wsgiapp 采用import的方式加载
        return util.import_app(self.app_uri)
示例#42
0
    def load(self):
        self.chdir()

        # load the app
        return util.import_app(self.app_uri)
示例#43
0
 def load(self):
     return util.import_app(self.app_uri)
示例#44
0
 def load(self):
     return import_app('api.app:create_app(wsgi=True,collect_transactions=True)')
示例#45
0
 def load_wsgiapp(self):
     # load the app
     return util.import_app(self.app_uri)
示例#46
0
 def load(self):
     return util.import_app("wsgi")
示例#47
0
 def load(self):
     '''load method
     Imports our application and returns it to be run.
     '''
     return util.import_app("psiturk.experiment:app")
示例#48
0
 def load(self):
     djangoapp.make_default_env(self.cfg)
     return util.import_app(self.app_uri)