Package Env Module
A Meco™ package may contain an optional Python module named packageEnvLib
(<PACKAGE_NAME>/python/<PACKAGE_NAME>/packageEnvLib.py
). This module can be used in order to customize the
environment based on the package it's in.
The packageEnvLib
module is created automatically when you create a Meco™ package by using the provided API or
the command.
Function
The function signature is provided below. You can use the provided function arguments to obtain detailed information regarding the environment, which will be initialized.
def setEnvironment(allLib, envEntryContainer):
return True
Function Arguments
allLib
Type: mMeco.libs.allLib.All
API Reference: mMeco.libs.allLib.All
You can use this instance to determine how you want to customize the environment. You must not change any state in this instance or any other instance it uses, treat it like a read only object.
envEntryContainer
Type: mMeco.libs.entryLib.EnvEntryContainer
API Reference: mMeco.libs.entryLib.EnvEntryContainer
You can use this instance to customize the environment by adding entries to it. The instance essentially represents
the package that you implement the setEnvironment
function for.
Determining to Initialize a Package
You can choose not to initialize a package based on some conditions. In such case the function must return False
.
If you want to initialize the package simply return True
.
If you have packageEnvLib
Python module in your package and do not have setEnvironment
function in it, the package
will be initialized.
Examples
addMulti
envEntryContainer
class instance has methods that you can invoke. One of them is addMulti
. This function adds
multi variable to the environment. A multi variable can be thought as paths, which can have multiple values.
For instance, in the example below, we check whether an app file provided for environment initialization.
If so, we check whether the app is Nuke
. In such case we add a multi value, which represents NUKE_PATH
env variable
and the provided absolute path as it's value.
def setEnvironment(allLib, envEntryContainer):
if allLib.settingsOperator().appFilePath():
_appFile = open(allLib.settingsOperator().appFilePath(), 'r')
appData = loads(_appFile.read())
_appFile.close()
if appData['application'] == 'nuke':
envEntryContainer.addMulti('NUKE_PATH', join(envEntryContainer.getPackageRootPath(), 'python'))
return True
return False
addSingle
You can use this method to add environment variables with single value.
def setEnvironment(allLib, envEntryContainer):
if allLib.settingsOperator().appFilePath():
_appFile = open(allLib.settingsOperator().appFilePath(), 'r')
appData = loads(_appFile.read())
_appFile.close()
if appData['application'] == 'maya':
envEntryContainer.addSingle('MAYA_LOCATION', '<MAYA_LOCATION_PATH>')
return True
return False
Please note, if MAYA_LOCATION
is set anywhere else by using addSingle
method, last provided value will be used.
addScript
You can use this method to add scripts. Please note, a script must be a valid one based on the platform in use.
Valid Script Extension | Platform |
---|---|
sh | Linux and Mac OS |
ps1 | Windows OS |
def setEnvironment(allLib, envEntryContainer):
if allLib.request().platform() == 'Windows':
envEntryContainer.addScript('<ABSOLUTE_SCRIPT_PATH.ps1>')
else:
envEntryContainer.addScript('<ABSOLUTE_SCRIPT_PATH.sh>')
return True
addCommand
In rare cases you may want to execute some commands, you can do so by using addCommand
method. Please note,
provided commands must be valid for the platform in use.
def setEnvironment(allLib, envEntryContainer):
envEntryContainer.addCommand('<VALID_COMMAND>')
return True
Using Additional Python Modules
Please remember, the environment wouldn't have been initialized yet when setEnvironment
function is invoked by Meco™.
Therefore, if you want to use other Python libraries in packageEnvLib
Python module, you must make sure that their
paths added to PYTHONPATH
prior.