MCPcopy
hub / github.com/pallets/flask / ScriptInfo

Class ScriptInfo

src/flask/cli.py:293–372  ·  view source on GitHub ↗

Helper object to deal with Flask applications. This is usually not necessary to interface with as it's used internally in the dispatching to click. In future versions of Flask this object will most likely play a bigger role. Typically it's created automatically by the :class:`Flas

Source from the content-addressed store, hash-verified

291
292
293class ScriptInfo:
294 """Helper object to deal with Flask applications. This is usually not
295 necessary to interface with as it's used internally in the dispatching
296 to click. In future versions of Flask this object will most likely play
297 a bigger role. Typically it's created automatically by the
298 :class:`FlaskGroup` but you can also manually create it and pass it
299 onwards as click object.
300
301 .. versionchanged:: 3.1
302 Added the ``load_dotenv_defaults`` parameter and attribute.
303 """
304
305 def __init__(
306 self,
307 app_import_path: str | None = None,
308 create_app: t.Callable[..., Flask] | None = None,
309 set_debug_flag: bool = True,
310 load_dotenv_defaults: bool = True,
311 ) -> None:
312 #: Optionally the import path for the Flask application.
313 self.app_import_path = app_import_path
314 #: Optionally a function that is passed the script info to create
315 #: the instance of the application.
316 self.create_app = create_app
317 #: A dictionary with arbitrary data that can be associated with
318 #: this script info.
319 self.data: dict[t.Any, t.Any] = {}
320 self.set_debug_flag = set_debug_flag
321
322 self.load_dotenv_defaults = get_load_dotenv(load_dotenv_defaults)
323 """Whether default ``.flaskenv`` and ``.env`` files should be loaded.
324
325 ``ScriptInfo`` doesn't load anything, this is for reference when doing
326 the load elsewhere during processing.
327
328 .. versionadded:: 3.1
329 """
330
331 self._loaded_app: Flask | None = None
332
333 def load_app(self) -> Flask:
334 """Loads the Flask app (if not yet loaded) and returns it. Calling
335 this multiple times will just result in the already loaded app to
336 be returned.
337 """
338 if self._loaded_app is not None:
339 return self._loaded_app
340 app: Flask | None = None
341 if self.create_app is not None:
342 app = self.create_app()
343 else:
344 if self.app_import_path:
345 path, name = (
346 re.split(r":(?![\\/])", self.app_import_path, maxsplit=1) + [None]
347 )[:2]
348 import_name = prepare_import(path)
349 app = locate_app(import_name, name)
350 else:

Callers 6

test_scriptinfoFunction · 0.90
test_with_appcontextFunction · 0.90
test_cli_custom_objFunction · 0.90
invokeMethod · 0.85
make_contextMethod · 0.85

Calls

no outgoing calls

Tested by 5

test_scriptinfoFunction · 0.72
test_with_appcontextFunction · 0.72
test_cli_custom_objFunction · 0.72
invokeMethod · 0.68