25. software — software.py

A module to help with detecting required software and helper software, and to check the versions of it.

This module is currently experimental. It contains some old functions moved here from utils.py.

25.1. Functions defined in module software

software.checkVersion(name, version, external=False)[source]

Checks a version of a program/module.

name is either a module or an external program whose availability has been registered. Default is to treat name as a module. Add external=True for a program.

Return value is -1, 0 or 1, depending on a version found that is <, == or > than the requested values. This should normally understand version numbers in the format 2.10.1 Returns -2 if no version found.

software.hasModule(name, check=False)[source]

Test if we have the named module available.

Returns a nonzero (version) string if the module is available, or an empty string if it is not.

By default, the module is only checked on the first call. The result is remembered in the the_version dict. The optional argument check==True forces a new detection.

software.requireModule(name, version=None, comp='ge')[source]

Ensure that the named Python module/version is available.

Checks that the specified module is available, and that its version number is not lower than the specified version. If no version is specified, any version is ok.

The default comparison operator ‘ge’ can be replaced with one of: ‘eq’, ‘ge’, ‘gt’, ‘le’, ‘lt’, ‘ne’.

Returns if the required module/version could be loaded, else an error is raised.

software.checkAllModules()[source]

Check the existence of all known modules.

software.checkModule(name, ver=(), fatal=False, quiet=False)[source]

Check if the named Python module is available, and record its version.

ver is a tuple of:

  • modname: name of the module to test import
  • vername: name of the module holding the version string
  • more fields are consecutive attributes leading to the version string

The obtained version string is returned, empty if the module could not be loaded. The (name,version) pair is also inserted into the the_version dict.

If fatal=True, pyFormex will abort if the module can not be loaded.

software.hasExternal(name, force=False)[source]

Test if we have the external command ‘name’ available.

Returns a nonzero string if the command is available, or an empty string if it is not.

The external command is only checked on the first call. The result is remembered in the the_external dict.

software.requireExternal(name)[source]

Ensure that the named external program is available.

If the module is not available, an error is raised.

software.checkAllExternals()[source]

Check the existence of all known externals.

Returns a dict with all the known externals, detected or not. The detected ones have a non-zero value, usually the version number.

software.checkExternal(name, command=None, answer=None, quiet=False)[source]

Check if the named external command is available on the system.

name is the generic command name, command is the command as it will be executed to check its operation, answer is a regular expression to match positive answers from the command. answer should contain at least one group. In case of a match, the contents of the match will be stored in the the_external dict with name as the key. If the result does not match the specified answer, an empty value is inserted.

Usually, command will contain an option to display the version, and the answer re contains a group to select the version string from the result.

As a convenience, we provide a list of predeclared external commands, that can be checked by their name alone.

software.Shaders()[source]

Return a list of the available GPU shader programs.

Shader programs are in the pyformex/glsl directory and consist at least of two files: ‘vertex_shader_SHADER.c’ and ‘fragment_shader_SHADER.c’. This function will return a list of all the SHADER filename parts currently available. The default shader programs do not have the ‘_SHADER’ part and will not be contained in this list.

software.detectedSoftware(all=True)[source]

Return a dict with all detected helper software

software.formatDict(d, indent=4)[source]

Format a dict in nicely formatted Python source representation.

Each (key,value) pair is formatted on a line of the form:

key = value

If all the keys are strings containing only characters that are allowed in Python variable names, the resulting text is a legal Python script to define the items in the dict. It can be stored on a file and executed.

This format is the storage format of the Config class.

software.compareVersion(has, want)[source]

Check whether a detected version matches the requirements.

has is the version string detected. want is the required version string, possibly preceded by one of the doubly underscored comparison operators: __gt__, etc. If no comparison operator is specified, ‘__eq__’ is assumed.

Note that any tail behind x.y.z version is considered to be later version than x.y.z.

Returns the result of the comparison: True or False .. rubric:: Examples

>>> compareVersion('2.7','2.4.3')
False
>>> compareVersion('2.7','>2.4.3')
True
>>> compareVersion('2.7','>= 2.4.3')
True
>>> compareVersion('2.7','>= 2.7-rc3')
False
>>> compareVersion('2.7-rc4','>= 2.7-rc3')
True
software.checkDict(has, want)[source]

Check that software dict has has the versions required in want

software.checkSoftware(req, report=False)[source]

Check that we have the matching components

Returns True or False. If report=True, also returns a string with a full report.

software.registerSoftware(req)[source]

Register the current values of required software

software.soft2config(soft)[source]

Convert software collection to config

software.config2soft(conf)[source]

Convert software collection from config

software.storeSoftware(soft, fn, mode='pretty')[source]

Store the software collection on file.

software.readSoftware(fn, mode='python')[source]

Read the software collection from file.

  • mode = ‘pretty’: readable, editable
  • mode = ‘python’: readable, editable
  • mode = ‘config’: readable, editable
  • mode = ‘pickle’: binary