Skip to content

tempdir

Temporary folder operations

create_custom_tempdir(project_name, anatomy=None)

Backward compatibility deprecated since 2024/12/09.

Source code in client/ayon_core/pipeline/tempdir.py
74
75
76
77
78
79
80
81
82
83
84
85
86
def create_custom_tempdir(project_name, anatomy=None):
    """Backward compatibility deprecated since 2024/12/09.
    """
    warnings.warn(
        "Used deprecated 'create_custom_tempdir' "
        "use 'ayon_core.pipeline.tempdir.get_temp_dir' instead.",
        DeprecationWarning,
    )

    if anatomy is None:
        anatomy = Anatomy(project_name)

    return _create_custom_tempdir(project_name, anatomy)

get_temp_dir(project_name, anatomy=None, prefix=None, suffix=None, use_local_temp=False)

Get temporary dir path.

If use_local_temp is set, tempdir will be created in local tempdir. If anatomy is not set, default anatomy will be used. If prefix or suffix is not set, default values will be used.

It also supports AYON_TMPDIR, so studio can define own temp shared repository per project or even per more granular context. Template formatting is supported also with optional keys. Folder is created in case it doesn't exists.

Parameters:

Name Type Description Default
project_name str

Name of project.

required
anatomy Optional[Anatomy]

Project Anatomy object.

None
suffix Optional[str]

Suffix for tempdir.

None
prefix Optional[str]

Prefix for tempdir.

None
use_local_temp Optional[bool]

If True, temp dir will be created in local tempdir.

False

Returns:

Name Type Description
str

Path to staging dir of instance.

Source code in client/ayon_core/pipeline/tempdir.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def get_temp_dir(
    project_name, anatomy=None, prefix=None, suffix=None, use_local_temp=False
):
    """Get temporary dir path.

    If `use_local_temp` is set, tempdir will be created in local tempdir.
    If `anatomy` is not set, default anatomy will be used.
    If `prefix` or `suffix` is not set, default values will be used.

    It also supports `AYON_TMPDIR`, so studio can define own temp
    shared repository per project or even per more granular context.
    Template formatting is supported also with optional keys. Folder is
    created in case it doesn't exists.

    Args:
        project_name (str): Name of project.
        anatomy (Optional[Anatomy]): Project Anatomy object.
        suffix (Optional[str]): Suffix for tempdir.
        prefix (Optional[str]): Prefix for tempdir.
        use_local_temp (Optional[bool]): If True, temp dir will be created in
            local tempdir.

    Returns:
        str: Path to staging dir of instance.

    """
    if prefix is None:
        prefix = "ay_tmp_"
    suffix = suffix or ""

    if use_local_temp:
        return _create_local_staging_dir(prefix, suffix)

    # make sure anatomy is set
    if not anatomy:
        anatomy = Anatomy(project_name)

    # get customized tempdir path from `OPENPYPE_TMPDIR` env var
    custom_temp_dir = _create_custom_tempdir(anatomy.project_name, anatomy)

    return _create_local_staging_dir(prefix, suffix, dirpath=custom_temp_dir)