Skip to content

GitProject

TM1Project(version=1.0, name='', settings=None, tasks=None, objects=None, ignore=None, files=None, deployment=None, pre_push=None, post_push=None, pre_pull=None, post_pull=None)

Bases: TM1Object

Abstraction of Git tm1project

Args: version (int): description settings (dict, optional): description. Defaults to None. tasks (dict, optional): description. Defaults to None. objects (dict, optional): description. Defaults to None. ignore (list, optional): description. Defaults to None. files (list, optional): description. Defaults to None. deployment (dict, optional): description. Defaults to None. pre_push (list, optional): description. Defaults to None. post_push (list, optional): description. Defaults to None. pre_pull (list, optional): description. Defaults to None. post_pull (list, optional): description. Defaults to None.

Source code in TM1py/Objects/GitProject.py
def __init__(
    self,
    version: int = 1.0,
    name: Optional[str] = "",
    settings: Optional[Dict] = None,
    tasks: Optional[Dict[str, TM1ProjectTask]] = None,
    objects: Optional[Dict] = None,
    ignore: Optional[List] = None,
    files: Optional[List] = None,
    deployment: Optional[Dict] = None,
    pre_push: Optional[List] = None,
    post_push: Optional[List] = None,
    pre_pull: Optional[List] = None,
    post_pull: Optional[List] = None,
):
    """

    Args:
        version (int): _description_
        settings (dict, optional): _description_. Defaults to None.
        tasks (dict, optional): _description_. Defaults to None.
        objects (dict, optional): _description_. Defaults to None.
        ignore (list, optional): _description_. Defaults to None.
        files (list, optional): _description_. Defaults to None.
        deployment (dict, optional): _description_. Defaults to None.
        pre_push (list, optional): _description_. Defaults to None.
        post_push (list, optional): _description_. Defaults to None.
        pre_pull (list, optional): _description_. Defaults to None.
        post_pull (list, optional): _description_. Defaults to None.
    """
    self._version = version
    self._name = name
    self._settings = settings
    self._tasks = tasks
    self._objects = objects
    self._ignore = ignore
    self._files = files
    self._deployment = deployment
    self._pre_push = pre_push
    self._post_push = post_push
    self._pre_pull = pre_pull
    self._post_pull = post_pull

body property

body_as_dict property

deployment property writable

ignore property writable

name property writable

objects property writable

post_pull property writable

post_push property writable

pre_pull property writable

pre_push property writable

settings property writable

tasks property writable

version property writable

add_deployment(deployment)

"Deployment is an OPTIONAL property. Each of its property defines a named deployment and its specific properties. All the tm1project properties can be redefined for a deployment, except Version. Those properties override the tm1project properties for the specific deployment.

Current deployment is set by action GitInit."

Source code in TM1py/Objects/GitProject.py
def add_deployment(self, deployment: "TM1ProjectDeployment"):
    """
    "Deployment is an OPTIONAL property. Each of its property defines a named deployment and its specific properties.
    All the tm1project properties can be redefined for a deployment, except Version.
    Those properties override the tm1project properties for the specific deployment.

    Current deployment is set by action GitInit."

    """
    if self._deployment is None:
        self._deployment = dict()

    if deployment._deployment_name in self._deployment:
        raise ValueError(
            f"Deployment with name '{deployment._deployment_name}' already exists in TM1 project. "
            f"Deployment name must be unique"
        )

    self._deployment[deployment._deployment_name] = deployment

add_ignore(object_class, object_name)

Ignore is an optional property in the tm1project It specifies the objects to be excluded from the source, if the object is newly created.

Args: object_class: class of the object e.g., "Dimensions" object_name: name of the object e.g., "Product"

For the object_type pass value like Dimensions or Cubes/Views

Wildcards (*) can be used in the object_name, if the object is not a control object.

Example of the ignore property in the tm1project: Exclude all the new Cubes and Views in the source, except Cube_A; include control Process }Drill_Drill_A; and exclude all the new Dimensions which has a name starting with 'Dim'

"Ignore":
[
  "Cubes/Views",
  "!Cubes('Cube_A')",
  "!Processes('}Drill_Drill_A')",
  "Dimensions('Dim*')"
]
Source code in TM1py/Objects/GitProject.py
def add_ignore(self, object_class: str, object_name: str):
    """
    Ignore is an optional property in the tm1project
    It specifies the objects to be excluded from the source, if the object is newly created.

    Args:
        object_class: class of the object e.g., "Dimensions"
        object_name: name of the object e.g., "Product"

    For the `object_type` pass value like `Dimensions` or `Cubes/Views`

    Wildcards (`*`) can be used in the `object_name`, if the object is not a control object.

    Example of the `ignore` property in the tm1project:
        Exclude all the new Cubes and Views in the source, except Cube_A;
        include control Process }Drill_Drill_A;
        and exclude all the new Dimensions which has a name starting with 'Dim'

        "Ignore":
        [
          "Cubes/Views",
          "!Cubes('Cube_A')",
          "!Processes('}Drill_Drill_A')",
          "Dimensions('Dim*')"
        ]
    """

    if object_name.startswith("}") and "*" in object_name:
        raise ValueError("'*' character must not be used in object_name for control objects")

    if self.ignore is None:
        self.ignore = []

    ignore_entry = object_class
    if object_name:
        ignore_entry += f"('{object_name}')"

    if ignore_entry not in self.ignore:
        self.ignore.append(ignore_entry)

add_ignore_exceptions(object_class, object_names)

Specify exceptions to ignore policy. Wildcards (*) can not be used in the object_name

Args: object_class: class of the object e.g., "Dimensions" object_names: names of the objects e.g., ["Product", "Customer", "Region"]

Example of the ignore property in the tm1project: Exclude all Dimensions that start with 'Dim', except for dimension 'DimB', 'DimA'

"Ignore":
[
  "Dimensions('Dim*')",
  "!Dimensions('DimA')",
  "!Dimensions('DimB')"
]
Source code in TM1py/Objects/GitProject.py
def add_ignore_exceptions(self, object_class: str, object_names: List[str]):
    """
    Specify exceptions to ignore policy.
    Wildcards (`*`) can not be used in the `object_name`

    Args:
        object_class: class of the object e.g., "Dimensions"
        object_names: names of the objects e.g., ["Product", "Customer", "Region"]

    Example of the ignore property in the tm1project:
        Exclude all Dimensions that start with 'Dim', except for dimension 'DimB', 'DimA'

        "Ignore":
        [
          "Dimensions('Dim*')",
          "!Dimensions('DimA')",
          "!Dimensions('DimB')"
        ]
    """

    for object_name in object_names:
        if "*" in object_name:
            raise ValueError("'*' character must not be used in object_name")

        ignore_entry = "!" + object_class
        if object_name:
            ignore_entry += f"('{object_name}')"

        if self.ignore is None:
            self.ignore = []

        if ignore_entry not in self.ignore:
            self.ignore.append(ignore_entry)

add_task(project_task)

Source code in TM1py/Objects/GitProject.py
def add_task(self, project_task: TM1ProjectTask):
    if self._tasks is None:
        self._tasks = dict()

    if project_task.task_name in self._tasks:
        raise ValueError(
            f"Task with name '{project_task.task_name}' already exists in TM1 project. " f"Task name must be unique"
        )

    self._tasks[project_task.task_name] = project_task

from_dict(tm1project_as_dict) classmethod

Parameters:

Name Type Description Default
tm1project_as_dict Dict

Dictionary, tm1project as dictionary

required

Returns:

Type Description
TM1Project

an instance of this class

Source code in TM1py/Objects/GitProject.py
@classmethod
def from_dict(cls, tm1project_as_dict: Dict) -> "TM1Project":
    """
    :param tm1project_as_dict: Dictionary, tm1project as dictionary
    :return: an instance of this class
    """
    return cls(
        version=tm1project_as_dict["Version"],
        name=tm1project_as_dict.get("Name"),
        settings=tm1project_as_dict.get("Settings"),
        tasks=(
            {
                task_name: TM1ProjectTask.from_dict(task_name, task)
                for task_name, task in tm1project_as_dict.get("Tasks").items()
            }
            if "Tasks" in tm1project_as_dict
            else {}
        ),
        objects=tm1project_as_dict.get("Objects"),
        ignore=tm1project_as_dict.get("Ignore"),
        files=tm1project_as_dict.get("Files"),
        deployment=(
            {
                deployment_name: TM1ProjectDeployment.from_dict(deployment_name, deployment)
                for deployment_name, deployment in tm1project_as_dict.get("Deployment").items()
            }
            if "Deployment" in tm1project_as_dict
            else {}
        ),
        pre_push=tm1project_as_dict.get("PrePush"),
        post_push=tm1project_as_dict.get("PostPush"),
        pre_pull=tm1project_as_dict.get("PrePull"),
        post_pull=tm1project_as_dict.get("PostPull"),
    )

from_file(filename) classmethod

Source code in TM1py/Objects/GitProject.py
@classmethod
def from_file(cls, filename: str) -> "TM1Project":
    with open(filename, "r") as file_object:
        json_file = json.load(file_object)

    return cls.from_dict(json_file)

from_json(tm1project_as_json) classmethod

Parameters:

Name Type Description Default
tm1project_as_json str

response of /!tm1project

required

Returns:

Type Description
TM1Project

an instance of this class

Source code in TM1py/Objects/GitProject.py
@classmethod
def from_json(cls, tm1project_as_json: str) -> "TM1Project":
    """
    :param tm1project_as_json: response of /!tm1project
    :return: an instance of this class
    """
    tm1project_as_dict = json.loads(tm1project_as_json)
    return cls.from_dict(tm1project_as_dict=tm1project_as_dict)

include_all_attribute_dimensions(tm1)

Add an ignore-exception for each attribute dimension

Source code in TM1py/Objects/GitProject.py
def include_all_attribute_dimensions(self, tm1):
    """
    Add an ignore-exception for each attribute dimension

    """
    attribute_dimensions = [
        dimension
        for dimension in tm1.dimensions.get_all_names()
        if dimension.lower().startswith("}elementattributes_")
    ]

    self.add_ignore_exceptions("Dimensions", attribute_dimensions)

remove_deployment(deployment_name)

Source code in TM1py/Objects/GitProject.py
def remove_deployment(self, deployment_name: str):
    if deployment_name in self._deployment:
        self._deployment.pop(deployment_name, None)

remove_ignore(ignore_entry)

Source code in TM1py/Objects/GitProject.py
def remove_ignore(self, ignore_entry: str):
    if ignore_entry in self.ignore:
        self.ignore.remove(ignore_entry)

remove_task(task_name)

Source code in TM1py/Objects/GitProject.py
def remove_task(self, task_name: str):
    if task_name in self._tasks:
        self._tasks.pop(task_name, None)

TM1ProjectDeployment(deployment_name, settings=None, tasks=None, objects=None, ignore=None, files=None, pre_push=None, post_push=None, pre_pull=None, post_pull=None)

Bases: TM1Project

Source code in TM1py/Objects/GitProject.py
def __init__(
    self,
    deployment_name: str,
    settings: Optional[Dict] = None,
    tasks: Optional[Dict[str, TM1ProjectTask]] = None,
    objects: Optional[Dict] = None,
    ignore: Optional[List] = None,
    files: Optional[List] = None,
    pre_push: Optional[List] = None,
    post_push: Optional[List] = None,
    pre_pull: Optional[List] = None,
    post_pull: Optional[List] = None,
):
    super().__init__(
        version=None,
        name=deployment_name,
        settings=settings,
        tasks=tasks,
        objects=objects,
        ignore=ignore,
        files=files,
        pre_push=pre_push,
        post_push=post_push,
        pre_pull=pre_pull,
        post_pull=post_pull,
    )

    self._deployment_name = deployment_name

body property

body_as_dict property

construct_body()

Source code in TM1py/Objects/GitProject.py
def construct_body(self) -> Dict:
    body_as_dict = {
        "Settings": self._settings,
        "Tasks": {name: task.construct_body() for name, task in self.tasks.items()} if self._tasks else None,
        "Objects": self._objects,
        "Ignore": self._ignore,
        "Files": self._files,
        "PrePush": self._pre_push,
        "PostPush": self._post_push,
        "PrePull": self._pre_pull,
        "PostPull": self._post_pull,
    }
    return clean_null_terms(body_as_dict)

from_dict(deployment_name, deployment) classmethod

Parameters:

Name Type Description Default
deployment Dict

Deployment as dictionary

required

Returns:

Type Description
TM1ProjectDeployment

an instance of this class

Source code in TM1py/Objects/GitProject.py
@classmethod
def from_dict(cls, deployment_name: str, deployment: Dict) -> "TM1ProjectDeployment":
    """
    :param deployment: Deployment as dictionary
    :return: an instance of this class
    """
    return cls(
        deployment_name=deployment_name,
        settings=deployment.get("Settings"),
        tasks={
            task_name: TM1ProjectTask.from_dict(task_name, task)
            for task_name, task in deployment.get("Tasks").items()
        },
        objects=deployment.get("Objects"),
        ignore=deployment.get("Ignore"),
        files=deployment.get("Files"),
        pre_push=deployment.get("PrePush"),
        post_push=deployment.get("PostPush"),
        pre_pull=deployment.get("PrePull"),
        post_pull=deployment.get("PostPull"),
    )

TM1ProjectTask(task_name, chore=None, process=None, parameters=None, dependencies=None, precondition=None)

Defines an action that executes a Process or a Chore with certain parameters.

A Task MUST either have a Process or a Chore property. The property specifies the reference of the Process or Chore to be executed. The Process or Chore MUST be visible.

A Task MAY have a Parameters property. The property specifies the parameters to be passed to the Process. This property MUST NOT be specified if the task is to execute a Chore.

A Task MAY have a Dependencies property. The property specifies an array of URIs of tasks or objects, which will be executed or loaded, respectively, before executing the current task. E.g.: ["Cubes('Cube_A')", "Dimensions('Dimension_C')"]

A Task MAY have a Precondition property. The server only executes a Task when either the precondition is not specified, or it is evaluated to TRUE.

The server only executes a Task one time during a deployment.

Source code in TM1py/Objects/GitProject.py
def __init__(
    self,
    task_name: str,
    chore: str = None,
    process: str = None,
    parameters: List[Dict[str, str]] = None,
    dependencies: List[str] = None,
    precondition: str = None,
):
    """
    Defines an action that executes a Process or a Chore with certain parameters.

    A Task MUST either have a Process or a Chore property.
    The property specifies the reference of the Process or Chore to be executed.
    The Process or Chore MUST be visible.

    A Task MAY have a Parameters property.
    The property specifies the parameters to be passed to the Process.
    This property MUST NOT be specified if the task is to execute a Chore.

    A Task MAY have a Dependencies property.
    The property specifies an array of URIs of tasks or objects,
    which will be executed or loaded, respectively, before executing the current task.
    E.g.: ["Cubes('Cube_A')", "Dimensions('Dimension_C')"]

    A Task MAY have a Precondition property.
    The server only executes a Task when either the precondition is not specified, or it is evaluated to TRUE.

    The server only executes a Task one time during a deployment.
    """

    if not any([chore, process]):
        raise ValueError("TM1ProjectTask must either have a 'Process' or a 'Chore' property")

    if all([chore, process]):
        raise ValueError("TM1ProjectTask must not have a 'Chore' and 'Process' property")

    if all([chore, parameters]):
        raise ValueError("TM1ProjectTask must not have a 'Chore' and 'Parameters' property")

    self.task_name = task_name
    self.chore = chore
    self.process = process
    self.parameters = parameters
    self.dependencies = dependencies
    self.precondition = precondition

chore = chore instance-attribute

dependencies = dependencies instance-attribute

parameters = parameters instance-attribute

precondition = precondition instance-attribute

process = process instance-attribute

task_name = task_name instance-attribute

construct_body()

Source code in TM1py/Objects/GitProject.py
def construct_body(self) -> Dict:
    body = dict()

    if self.chore:
        if not self.chore.startswith("Chores('"):
            body = {"Chore": f"Chores('{self.chore}')"}
        else:
            body["Chore"] = self.chore
    else:
        if not self.process.startswith("Processes('"):
            body = {
                "Process": f"Processes('{self.process}')",
            }
        else:
            body["Process"] = self.process
        body.update({"Parameters": self.parameters})

    if self.dependencies:
        body["Dependencies"] = self.dependencies

    return body

from_dict(task_name, task) classmethod

Source code in TM1py/Objects/GitProject.py
@classmethod
def from_dict(cls, task_name: str, task: Dict):
    return cls(
        task_name=task_name,
        chore=task.get("Chore"),
        process=task.get("Process"),
        parameters=task.get("Parameters"),
        dependencies=task.get("Dependencies"),
        precondition=task.get("Precondition"),
    )

clean_null_terms(d)

Source code in TM1py/Objects/GitProject.py
def clean_null_terms(d: Dict):
    clean = {}
    for k, v in d.items():
        if isinstance(v, dict):
            nested = clean_null_terms(v)
            if len(nested.keys()) > 0:
                clean[k] = nested
        elif isinstance(v, list) and not d[k]:
            continue
        elif v is not None:
            clean[k] = v
    return clean