9. apps
— pyFormex application loading.¶
This module contains the functions used to detect and load the pyFormex applications. pyFormex applications (‘apps’) are loaded as a Python module. They contain a dedicated function ‘run’ that is executed when the application is started. The application stays in memory, unless it is explicitely unloaded.
This module contains functions to find, handle, list and (un)load applications and manage application directories.
9.1. Classes defined in module apps¶
9.2. Functions defined in module apps¶
-
apps.
guessDir
(n, s)[source]¶ Guess the appdir from the name
n: app name s: app path
This works for dirs having a matching cfg[‘NAMEdir’] entry
-
apps.
checkAppdir
(d)[source]¶ Check that a directory d can be used as a pyFormex application path.
If the path does not exist, it is created. If no __init__.py exists, it is created. If __init__.py exists, it is not checked.
If successful, returns the path, else None
-
apps.
load
(appname, refresh=False, strict=False)[source]¶ Load the named app
If refresh is True, the module will be reloaded if it was already loaded before. On succes, returns the loaded module, else returns None. In the latter case, if the config variable apptraceback is True, the traceback is store in a module variable _traceback.
-
apps.
findAppSource
(app)[source]¶ Find the source file of an application.
app is either an imported application module (like: pkg.mod) or the corresponding application module name(like: ‘pkg.mod’). In the first case the name is extracted from the loaded module. In the second case an attempt is made to find the path that the module would be loaded from, without actually loading the module. This can be used to load the source file when the application can not be loaded.
-
apps.
listLoaded
(appsdir='appsdir')[source]¶ List the currently loaded apps
Parameters: appsdir (str) – The base name of a directory registered as an application directory. Returns: list of str – A list with the currently loaded applications from the specified application directory.
-
apps.
detect
(appdir)[source]¶ Detect the apps present in the specified appdir.
Parameters: appdir (path_like) – Path to an appdir (i.e. a directory containing a file ‘__init__.py’). Returns: list of str – A list with all the pyFormex apps in the specified appdir. If a file ‘.apps.dir’ exists in the appdir, the returned list is the contents of that file. Otherwise the list contains all ‘.py’ files in the directory, without the ‘.py’ extension and sorted. Examples
>>> detect(pf.cfg.appsdir) ['FeEx', 'Hesperia', 'RunAll']