2. _main
— pyFormex main module¶
This module contains the main function of pyFormex, which is normally run
by the pyformex
command.
2.1. Functions defined in module _main¶
- _main.load_user_config()[source]¶
Load the pyFormex configuration
Notes
This function should be called to create a proper configuration when pyFormex is imported in Python and not started from the pyformex command.
- _main.savePreferences()[source]¶
Save the preferences.
The name of the preferences file is determined at startup from the configuration files, and saved in
pyformex.preffile
. If a local preferences file was read, it will be saved there. Otherwise, it will be saved as the user preferences, possibly creating that file. Ifpyformex.preffile
is None, preferences are not saved.
- _main.override_config(option, setting, delete=True)[source]¶
Override a config setting with a command line option
- Parameters:
Notes
If the option was given, its value is written into the corresponding setting and the option is deleted.
- _main.main(args=[])[source]¶
The pyFormex main function.
This function is normally executed by the
pyformex
launcher script, but it can also be run from a Python interpreter where the pyformex module has been imported.- Parameters:
args (list | str) – The list of pyformex command line options to be used. Run the command
pyformex --help
to get the full list.- Returns:
int – The returncode. The value depends on what operations the run function executed and how it ended. Usually a value 0 is returned, meaning that the operation terminated normally. The pyFormex launcher script returns with this value to the operating system.
Notes
After pyFormex launcher script has correctly set up the Python import paths, this function is executed. It is responsible for reading the configuration file(s), processing the command line options and starting the application.
The basic configuration file is ‘pyformexrc’ located in the pyFormex main directory. It should always be present and be left unchanged. If you want to make changes, copy (parts of) this file to another location where you can change them. Then make sure pyFormex reads you modifications file. By default, pyFormex will try to read the following configuration files if they are present (and in this order):
default settings: <pyformexdir>/pyformexrc (always loaded) system-wide settings: /etc/pyformex.conf user settings: <configdir>/pyformex/pyformex.conf local settings $PWD/.pyformexrc
Also, an extra config file can be specified in the command line, using the –config option. The system-wide and user settings can be skipped by using the –nodefaultconfig option.
Config files are loaded in the above order. Settings always override those loaded from a previous file.
When pyFormex exits, the preferences that were changed are written to the last read config file. Changed settings are those that differ from the settings obtained after loading all but the last config file. If none of the optional config files exists, a new user settings file will be created, and an error will occur if the <configdir> path is not writable.