Skip to content

Custom python functions

white238 edited this page Sep 14, 2011 · 1 revision

MixDown has the ability to execute user created python functions. These can be useful if the default behavior of MixDown does not work for specific build step or a build step cannot be done with a simple command.

To create and use your own custom python function, create a python file in the same directory where your project file. In this example, we will call it mySteps.py.

mySteps.py

import sys
from md import utilityFunctions

def patchFoo(pythonCallInfo):
    variableList = {}

    filename = pythonCallInfo.currentPath+"/config.py"
    variableList['MPICC'] = "'/Users/test/mpi/bin/mpicc'"
    variableList['CC'] = "'/usr/local/gfortran/bin/gcc'"

    pythonCallInfo.success =  utilityFunctions.setVariables(filename, variableList)

    return pythonCallInfo

This example function sets some variables inside of a python file.

This function can then be used as a build step by the following line in the project file:

Patch: mySteps.patchFoo(pythonCallInfo)

MixDown allows you to name to python file and function anything you like but you must use only a single parameter named "pythonCallInfo" that is a class PythonCallInfo, defined as:

class PythonCallInfo(object):
    def __init__(self):
        self.success = False
        self.currentPath = ""
        self.outputPath = ""
        self.outputPathSpecified = False
        self.prefix = ""
        self.downloadDir = ""
        self.logger = logger.Logger()

The members of PythonCall mean the following:

  • success: Specifies whether the python function was successful
  • currentPath: Specifies where the target is currently
  • outputPath: Specifies where to extract the target
  • outputPathSpecified: Specifies whether the output path was defined for the target inside of the project file
  • prefix: Directory where the package should be installed
  • downloadDir: Directory where MixDown saves downloaded files
  • logger: Used to access MixDown's logger

All variables except success and logger can be overwritten and will be used for following build steps by MixDown. For example if you change outputPath in build step fetch, in build step unpack the target will be extracted to the new location.