コード例 #1
0
ファイル: test_mockstore.py プロジェクト: papepipe/tk-core
    def test_framework_registration(self, mock_store):
        """
        Makes sure the framework is registered correctly.
        """
        # Version this is a dependency.
        dependency = mock_store.add_framework("tk-framework-dependency",
                                              "v1.0.0")
        self.assertEqual(
            dependency.get_major_dependency_descriptor(),
            {
                "version": "v1.x.x",
                "name": "tk-framework-dependency",
                "type": "app_store",
            },
        )
        # This is V1 of a framework that has no depdendencies.
        mock_store.add_framework("tk-framework-main", "v1.0.0")
        # This is V2 of a framework that now has a depdendency
        mock_store.add_framework(
            "tk-framework-main", "v2.0.0").required_frameworks = [
                dependency.get_major_dependency_descriptor()
            ]

        # Makes sure we respect the interface of the TankAppStoreDescriptor

        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v2.0.0",
                "type": "app_store"
            },
        )

        self.assertEqual(
            desc.required_frameworks,
            [{
                "type": "app_store",
                "name": "tk-framework-dependency",
                "version": "v1.x.x",
            }],
        )

        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v1.0.0",
                "type": "app_store"
            },
        )

        self.assertEqual(desc.required_frameworks, [])
コード例 #2
0
ファイル: test_mockstore.py プロジェクト: adriankrupa/tk-core
    def test_framework_registration(self, mock_store):
        """
        Makes sure the framework is registered correctly.
        """
        # Version this is a dependency.
        dependency = mock_store.add_framework("tk-framework-dependency", "v1.0.0")
        self.assertEqual(dependency.get_major_dependency_descriptor(), {
            "version": "v1.x.x",
            "name": "tk-framework-dependency",
            "type": "app_store"
        })
        # This is V1 of a framework that has no depdendencies.
        mock_store.add_framework("tk-framework-main", "v1.0.0")
        # This is V2 of a framework that now has a depdendency
        mock_store.add_framework("tk-framework-main", "v2.0.0").required_frameworks = [
            dependency.get_major_dependency_descriptor()
        ]

        # Makes sure we respect the interface of the TankAppStoreDescriptor

        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {"name": "tk-framework-main", "version": "v2.0.0", "type": "app_store"}
        )

        self.assertEqual(
            desc.required_frameworks,
            [{"type": "app_store", "name": "tk-framework-dependency", "version": "v1.x.x"}]
        )

        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {"name": "tk-framework-main", "version": "v1.0.0", "type": "app_store"}
        )

        self.assertEqual(desc.required_frameworks, [])
コード例 #3
0
ファイル: test_appstore.py プロジェクト: papepipe/tk-core
    def test_label_support(self, find_mock, find_one_mock):
        """
        Tests the label syntax and that it restricts versions correctly
        """
        def find_one_mock_impl(*args, **kwargs):
            """
            The app store implementation will call this once to resolve the main
            app as part of retrieving latest.
            Expected form:

            args: (
                'CustomNonProjectEntity13',
                [['sg_system_name', 'is', 'tk-framework-main']],
                ['id', 'sg_system_name', 'sg_status_list', 'sg_deprecation_message']
                )
            kwargs: {}
            """
            # ensure that input is what we expected
            self.assertEqual(kwargs, {})
            self.assertEqual(
                args,
                (
                    "CustomNonProjectEntity13",
                    [["sg_system_name", "is", "tk-framework-main"]],
                    [
                        "id",
                        "sg_system_name",
                        "sg_status_list",
                        "sg_deprecation_message",
                    ],
                ),
            )

            return {
                "type": "CustomNonProjectEntity13",
                "id": 1234,
                "sg_system_name": "tk-framework-main",
                "sg_status_list": "prod",
                "sg_deprecation_message": None,
            }

        def find_mock_impl(*args, **kwargs):
            """
            The find call to get app store versions will arrive here as a consequence
            of the find_latest_version call.
            Expected form:

            args: ('CustomNonProjectEntity09',)
            kwargs: {
                'fields': [
                    'id', 'code', 'sg_status_list', 'description', 'tags', 'sg_detailed_release_notes',
                    'sg_documentation', 'sg_payload'
                ],
                'limit': 1,
                'order': [{'direction': 'desc', 'field_name': 'created_at'}],
                'filters': [['sg_status_list', 'is_not', 'rev'], ['sg_status_list', 'is_not', 'bad'],
                            ['sg_tank_framework', 'is', {'sg_status_list': 'prod', 'type': 'CustomNonProjectEntity13', 'id': 1234,
               'sg_system_name': 'tk-framework-main',
               'sg_deprecation_message': None}]]
            }
            """
            self.assertEqual(args, ("CustomNonProjectEntity09", ))

            # app store is trying to be smart about bandwidth depending on queries, so limit may vary.
            kwargs["limit"] = None

            self.assertEqual(
                kwargs,
                {
                    "fields": [
                        "id",
                        "code",
                        "sg_status_list",
                        "description",
                        "tags",
                        "sg_detailed_release_notes",
                        "sg_documentation",
                        "sg_payload",
                    ],
                    "limit":
                    None,
                    "order": [{
                        "direction": "desc",
                        "field_name": "created_at"
                    }],
                    "filters": [
                        ["sg_status_list", "is_not", "rev"],
                        ["sg_status_list", "is_not", "bad"],
                        [
                            "sg_tank_framework",
                            "is",
                            {
                                "sg_status_list": "prod",
                                "type": "CustomNonProjectEntity13",
                                "id": 1234,
                                "sg_system_name": "tk-framework-main",
                                "sg_deprecation_message": None,
                            },
                        ],
                    ],
                },
            )

            return_data = []

            return_data.append({
                "type":
                "CustomNonProjectEntity09",
                "id":
                1,
                "code":
                "v1.0.1",
                "tags": [
                    {
                        "id": 1,
                        "name": "2017.*",
                        "type": "Tag"
                    },
                    {
                        "id": 2,
                        "name": "2016.*",
                        "type": "Tag"
                    },
                ],
                "sg_detailed_release_notes":
                "Test 1",
                "sg_status_list":
                "prod",
                "description":
                "dummy",
                "sg_detailed_release_notes":
                "dummy",
                "sg_documentation":
                "dummy",
                "sg_payload": {},
            })

            return_data.append({
                "type":
                "CustomNonProjectEntity09",
                "id":
                2,
                "code":
                "v2.0.1",
                "tags": [{
                    "id": 1,
                    "name": "2017.*",
                    "type": "Tag"
                }],
                "sg_detailed_release_notes":
                "Test 2",
                "sg_status_list":
                "prod",
                "description":
                "dummy",
                "sg_detailed_release_notes":
                "dummy",
                "sg_documentation":
                "dummy",
                "sg_payload": {},
            })

            return_data.append({
                "type":
                "CustomNonProjectEntity09",
                "id":
                3,
                "code":
                "v3.0.1",
                "tags": [{
                    "id": 3,
                    "name": "2018.*",
                    "type": "Tag"
                }],
                "sg_detailed_release_notes":
                "Test 3",
                "sg_status_list":
                "prod",
                "description":
                "dummy",
                "sg_detailed_release_notes":
                "dummy",
                "sg_documentation":
                "dummy",
                "sg_payload": {},
            })

            # return it in desc/reverse order, e.g. higher versions last, as requested by the API call
            return return_data[::-1]

        find_mock.side_effect = find_mock_impl
        find_one_mock.side_effect = find_one_mock_impl

        # no label
        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v1.0.0",
                "type": "app_store"
            },
        )
        self.assertEqual(
            desc.get_uri(),
            "sgtk:descriptor:app_store?name=tk-framework-main&version=v1.0.0",
        )
        desc2 = desc.find_latest_version()
        self.assertEqual(
            desc2.get_uri(),
            "sgtk:descriptor:app_store?name=tk-framework-main&version=v3.0.1",
        )

        # i am version 2016.3.45 so i am only getting 1.0.1
        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v1.0.0",
                "type": "app_store",
                "label": "2016.3.45",
            },
        )
        self.assertEqual(
            desc.get_uri(),
            "sgtk:descriptor:app_store?label=2016.3.45&name=tk-framework-main&version=v1.0.0",
        )
        desc2 = desc.find_latest_version()
        self.assertEqual(
            desc2.get_uri(),
            "sgtk:descriptor:app_store?label=2016.3.45&name=tk-framework-main&version=v1.0.1",
        )

        # i am version 2017.3.45 so i am getting 2.0.1
        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v1.0.0",
                "type": "app_store",
                "label": "2017.3.45",
            },
        )
        self.assertEqual(
            desc.get_uri(),
            "sgtk:descriptor:app_store?label=2017.3.45&name=tk-framework-main&version=v1.0.0",
        )
        desc2 = desc.find_latest_version()
        self.assertEqual(
            desc2.get_uri(),
            "sgtk:descriptor:app_store?label=2017.3.45&name=tk-framework-main&version=v2.0.1",
        )

        # i am version 2018.3.45 so i am getting 3.0.1
        desc = create_descriptor(
            None,
            Descriptor.FRAMEWORK,
            {
                "name": "tk-framework-main",
                "version": "v1.0.0",
                "type": "app_store",
                "label": "2018.3.45",
            },
        )
        self.assertEqual(
            desc.get_uri(),
            "sgtk:descriptor:app_store?label=2018.3.45&name=tk-framework-main&version=v1.0.0",
        )
        desc2 = desc.find_latest_version()
        self.assertEqual(
            desc2.get_uri(),
            "sgtk:descriptor:app_store?label=2018.3.45&name=tk-framework-main&version=v3.0.1",
        )
コード例 #4
0
def _build_bundle_cache(sg_connection, target_path, config_descriptor_uri):
    """
    Perform a build of the bundle cache.

    This will build the bundle cache for a given config descriptor.

    :param sg_connection: Shotgun connection
    :param target_path: Path to build
    :param config_descriptor_uri: Descriptor of the configuration to cache.
    """
    logger.info("The build will generated into '%s'" % target_path)

    bundle_cache_root = os.path.join(target_path,
                                     BUNDLE_CACHE_ROOT_FOLDER_NAME)

    # try to create target path
    logger.info("Creating bundle cache folder...")
    filesystem.ensure_folder_exists(bundle_cache_root)

    # Resolve the configuration
    cfg_descriptor = create_descriptor(
        sg_connection,
        Descriptor.CONFIG,
        config_descriptor_uri,
        # If the user hasn't specified the version to retrieve, resolve the latest from Shotgun.
        resolve_latest=is_descriptor_version_missing(config_descriptor_uri))

    logger.info("Resolved config %r" % cfg_descriptor)
    logger.info("Runtime config descriptor uri will be %s" %
                config_descriptor_uri)

    # cache config in bundle cache
    logger.info("Downloading and caching config...")

    cfg_descriptor.ensure_local()

    # copy the config payload across to the plugin bundle cache
    cfg_descriptor.clone_cache(bundle_cache_root)

    # cache all apps, engines and frameworks
    cache_apps(sg_connection, cfg_descriptor, bundle_cache_root)

    if cfg_descriptor.associated_core_descriptor:
        logger.info(
            "Config is specifying a custom core in config/core/core_api.yml.")
        logger.info("This will be used when the config is executing.")
        logger.info("Ensuring this core (%s) is cached..." %
                    cfg_descriptor.associated_core_descriptor)
        bootstrap_core_desc = create_descriptor(
            sg_connection,
            Descriptor.CORE,
            cfg_descriptor.associated_core_descriptor,
            bundle_cache_root_override=bundle_cache_root)
        # cache it
        bootstrap_core_desc.ensure_local()
        bootstrap_core_desc.clone_cache(bundle_cache_root)

    cleanup_bundle_cache(bundle_cache_root)

    logger.info("")
    logger.info("Build complete!")
    logger.info("")
    logger.info("- Your bundle cache is ready in '%s'" % target_path)
    logger.info(
        "- All dependencies have been baked out into the bundle_cache folder")
    logger.info("")
コード例 #5
0
def _build_bundle_cache(sg_connection, target_path, config_descriptor_uri):
    """
    Perform a build of the bundle cache.

    This will build the bundle cache for a given config descriptor.

    :param sg_connection: Shotgun connection
    :param target_path: Path to build
    :param config_descriptor_uri: Descriptor of the configuration to cache.
    """
    logger.info("The build will generated into '%s'" % target_path)

    bundle_cache_root = os.path.join(target_path, BUNDLE_CACHE_ROOT_FOLDER_NAME)

    # try to create target path
    logger.info("Creating bundle cache folder...")
    filesystem.ensure_folder_exists(bundle_cache_root)

    # Resolve the configuration
    cfg_descriptor = create_descriptor(
        sg_connection,
        Descriptor.CONFIG,
        config_descriptor_uri,
        # If the user hasn't specified the version to retrieve, resolve the latest from Shotgun.
        resolve_latest=is_descriptor_version_missing(config_descriptor_uri)
    )

    logger.info("Resolved config %r" % cfg_descriptor)
    logger.info("Runtime config descriptor uri will be %s" % config_descriptor_uri)

    # cache config in bundle cache
    logger.info("Downloading and caching config...")

    cfg_descriptor.ensure_local()

    # copy the config payload across to the plugin bundle cache
    cfg_descriptor.clone_cache(bundle_cache_root)

    # cache all apps, engines and frameworks
    cache_apps(sg_connection, cfg_descriptor, bundle_cache_root)

    if cfg_descriptor.associated_core_descriptor:
        logger.info("Config is specifying a custom core in config/core/core_api.yml.")
        logger.info("This will be used when the config is executing.")
        logger.info("Ensuring this core (%s) is cached..." % cfg_descriptor.associated_core_descriptor)
        bootstrap_core_desc = create_descriptor(
            sg_connection,
            Descriptor.CORE,
            cfg_descriptor.associated_core_descriptor,
            bundle_cache_root_override=bundle_cache_root
        )
        # cache it
        bootstrap_core_desc.ensure_local()
        bootstrap_core_desc.clone_cache(bundle_cache_root)

    cleanup_bundle_cache(bundle_cache_root)

    logger.info("")
    logger.info("Build complete!")
    logger.info("")
    logger.info("- Your bundle cache is ready in '%s'" % target_path)
    logger.info("- All dependencies have been baked out into the bundle_cache folder")
    logger.info("")