Skip to content

pre_maya_launch

Add the AYON USD startup script to Maya's Python path.

SetupAssetResolver

Bases: PreLaunchHook

Configure the AYON USD startup script for Maya.

Source code in client/ayon_usd/hooks/pre_maya_launch.py
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
55
56
class SetupAssetResolver(PreLaunchHook):
    """Configure the AYON USD startup script for Maya."""

    # Must run after InitializeAssetResolver.
    order = 20

    app_groups = {"maya"}
    launch_types = {
        LaunchTypes.local,
    }

    def execute(self):
        """Add the AYON USD Maya startup directory to PYTHONPATH."""
        if not self.data.get("ayon_usd_resolver_initialized"):
            self.log.debug(
                "Skipping AYON USD Maya startup initialization because USD resolver is disabled."
            )
            return

        user_setup_path = os.path.join(
            MAYA_STARTUP_DIR,
            "userSetup.py",
        )

        if not os.path.isfile(user_setup_path):
            raise RuntimeError(
                "AYON USD Maya userSetup.py was not found: "
                f"{user_setup_path}"
            )

        env = self.launch_context.env
        current_pythonpath = env.get("PYTHONPATH", "")
        paths = current_pythonpath.split(os.pathsep) if current_pythonpath else []
        if MAYA_STARTUP_DIR not in paths:
            paths.append(MAYA_STARTUP_DIR)

        env["PYTHONPATH"] = os.pathsep.join(paths)

        self.log.info(
            "Added AYON USD Maya startup directory: %s",
            MAYA_STARTUP_DIR,
        )

execute()

Add the AYON USD Maya startup directory to PYTHONPATH.

Source code in client/ayon_usd/hooks/pre_maya_launch.py
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
55
56
def execute(self):
    """Add the AYON USD Maya startup directory to PYTHONPATH."""
    if not self.data.get("ayon_usd_resolver_initialized"):
        self.log.debug(
            "Skipping AYON USD Maya startup initialization because USD resolver is disabled."
        )
        return

    user_setup_path = os.path.join(
        MAYA_STARTUP_DIR,
        "userSetup.py",
    )

    if not os.path.isfile(user_setup_path):
        raise RuntimeError(
            "AYON USD Maya userSetup.py was not found: "
            f"{user_setup_path}"
        )

    env = self.launch_context.env
    current_pythonpath = env.get("PYTHONPATH", "")
    paths = current_pythonpath.split(os.pathsep) if current_pythonpath else []
    if MAYA_STARTUP_DIR not in paths:
        paths.append(MAYA_STARTUP_DIR)

    env["PYTHONPATH"] = os.pathsep.join(paths)

    self.log.info(
        "Added AYON USD Maya startup directory: %s",
        MAYA_STARTUP_DIR,
    )