API Reference

wiz

wiz.fetch_definition_mapping(paths, max_depth=None, system_mapping=None)[source]

Return mapping including all definitions available under paths.

Mapping returned should be in the form of:

{
    "command": {
        "foo-app": "foo",
        ...
    },
    "package": {
        "foo": {
            "1.1.0": Definition(identifier="foo", version="1.1.0"),
            "1.0.0": Definition(identifier="foo", version="1.0.0"),
            "0.1.0": Definition(identifier="foo", version="0.1.0"),
            ...
        },
        ...
    },
    "implicit-packages": [
        "bar==0.1.0",
        ...
    ]
    "registries": [
        "/path/to/registry",
        ...
    ]
}
Parameters:
  • paths – List of registry paths to recursively fetch definitions from.
  • max_depth – Limited recursion value to search for definitions. Default is None, which means that all sub-trees will be visited.
  • system_mapping – Mapping defining the current system to filter out non compatible definitions. Default is None, which means that the current system mapping will be queried.
Returns:

Definition mapping.

wiz.fetch_definition(request, definition_mapping)[source]

Return Definition instance from request.

Parameters:
  • request – String indicating which definition should be fetched. (e.g. “definition”, “definition >= 1.0.0, < 2”, etc.).
  • definition_mapping – Mapping regrouping all available definitions. It could be fetched with fetch_definition_mapping().
Returns:

Instance of Definition.

Raise:

wiz.exception.RequestNotFound is the corresponding definition cannot be found.

wiz.fetch_package(request, definition_mapping)[source]

Return best matching Package instance from request.

Parameters:
  • request – String indicating which package should be fetched. (e.g. “package”, “package[Variant] >= 1.0.0, < 2”, etc.).
  • definition_mapping – Mapping regrouping all available definitions. It could be fetched with fetch_definition_mapping().
Returns:

Instance of Package.

Raise:

wiz.exception.RequestNotFound is the corresponding definition cannot be found.

Note

If several packages are extracted from request, only the first one will be returned.

wiz.fetch_package_request_from_command(command_request, definition_mapping)[source]

Return package request corresponding to command request.

Example:

>>> mapping = {
...     "command": {"hiero": "nuke"},
...     "package": {"nuke": ...}
... }
>>> fetch_package_request_from_command("hiero==10.5.*", mapping)
nuke==10.5.*
Parameters:
  • command_request – String indicating which command should be fetched. (e.g. “command”, “command >= 1.0.0, < 2”, etc.).
  • definition_mapping – Mapping regrouping all available definitions. It could be fetched with fetch_definition_mapping().
Returns:

Package requests string.

Raise:

wiz.exception.RequestNotFound is the corresponding command cannot be found.

wiz.resolve_context(requests, definition_mapping=None, ignore_implicit=False, environ_mapping=None, maximum_combinations=None, maximum_attempts=None)[source]

Return context mapping from requests.

The context should contain the resolved environment mapping, the resolved command mapping, and an ordered list of all serialized packages which constitute the resolved context.

It should be in the form of:

{
    "command": {
        "app": "AppExe"
        ...
    },
    "environ": {
        "KEY1": "value1",
        "KEY2": "value2",
        ...
    },
    "packages": [
        Package(identifier="test1==1.1.0", version="1.1.0"),
        Package(identifier="test2==0.3.0", version="0.3.0"),
        ...
    ],
    "registries": [
        "/path/to/registry",
        ...
    ]
}
Parameters:
  • requests – List of strings indicating the package version requested to build the context (e.g. [“package >= 1.0.0, < 2”])
  • definition_mapping – Mapping regrouping all available definitions. It could be fetched with fetch_definition_mapping(). If no definition mapping is provided, a default one will be fetched from default registries.
  • ignore_implicit – Indicates whether implicit packages should not be included in context. Default is False.
  • environ_mapping – Mapping of environment variables which would be augmented by the resolved environment. Default is None.
  • maximum_combinations – Maximum number of combinations which can be generated from conflicting variants. Default is None, which means that the default value will be picked from the configuration.
  • maximum_attempts – Maximum number of resolution attempts before raising an error. Default is None, which means that the default value will be picked from the configuration.
Returns:

Context mapping.

Raise:

wiz.exception.GraphResolutionError if the resolution graph cannot be resolved in time.

wiz.resolve_command(elements, command_mapping)[source]

Return resolved command elements from elements and command_mapping.

Example:

>>> resolve_command(
...     ["app", "--option", "value", "/path/to/script"],
...     {"app": "App0.1 --modeX"}
... )

["App0.1", "--modeX", "--option", "value", "/path/to/script"]
Parameters:
  • elements – List of strings constituting the command line to resolve (e.g. [“app_exe”, “–option”, “value”])
  • command_mapping – Mapping associating command aliased to real commands.
Returns:

List of strings constituting the resolved command line.

wiz.discover_context()[source]

Return context mapping used to resolve the current wiz environment.

It should be in the form of:

{
    "command": {
        "app": "AppExe"
        ...
    },
    "environ": {
        "KEY1": "value1",
        "KEY2": "value2",
        ...
    },
    "packages": [
        Package(identifier="test1==1.1.0", version="1.1.0"),
        Package(identifier="test2==0.3.0", version="0.3.0"),
        ...
    ],
    "registries": [
        "/path/to/registry",
        ...
    ]
}

The context should have been encoded into a WIZ_CONTEXT environment variable that can be used to retrieve the list of registries and packages from which the current environment was resolved.

Warning

The context cannot be retrieved if this function is called outside of a resolved environment.

Returns:Context mapping.
Raise:RequestNotFound if the WIZ_CONTEXT environment variable is not found.
wiz.load_definition(path)[source]

Return Definition instance from file path.

Parameters:pathJSON file path which contains a definition.
Raise:wiz.exception.IncorrectDefinition if the definition is incorrect.
wiz.export_definition(path, data, overwrite=False)[source]

Export definition data as a JSON file in directory path.

Parameters:
  • path – Target path to save the exported definition into.
  • data

    Instance of wiz.definition.Definition or a mapping in the form of:

    {
        "identifier": "foo",
        "description": "This is my package",
        "version": "0.1.0",
        "command": {
            "app": "AppExe",
            "appX": "AppExe --mode X"
        },
        "environ": {
            "KEY1": "value1",
            "KEY2": "value2"
        },
        "requirements": [
            "package1 >=1, <2",
            "package2"
        ]
    }
    
  • overwrite – Indicate whether existing definitions in the target path will be overwritten. Default is False.
Returns:

Path to exported definition.

Raise:

wiz.exception.IncorrectDefinition if data is a mapping that cannot create a valid instance of wiz.definition.Definition.

Raise:

wiz.exception.FileExists if definition already exists in path and overwrite is False.

Raise:

OSError if the definition can not be exported in path.

Warning

Ensure that the data identifier, namespace, version and system requirement are unique in the registry.

Each command must also be unique in the registry.

wiz.export_script(path, script_type, identifier, environ, command=None, packages=None)[source]

Export environment as Bash or C-Shell script in path.

Parameters:
  • path – Target path to save the exported script into.
  • script_type – Should be either tcsh or bash.
  • identifier – File name of the exported script.
  • environ

    Mapping of all environment variables that will be set by the exported definition. It should be in the form of:

    {
        "KEY1": "value1",
        "KEY2": "value2",
    }
    
  • command – Define a command to run within the exported wrapper. Default is None.
  • packages – Indicate a list of wiz.package.Package instances which helped creating the context.
Returns:

Path to the exported script.

Raise:

ValueError if the script_type is incorrect.

Raise:

ValueError if environ mapping is empty.

Raise:

OSError if the wrapper can not be exported in path.