コード例 #1
0
ファイル: metadata.py プロジェクト: davidyangcool/elyra
def metadata_path(*subdirs):
    """Return a list of directories to search for metadata files.

    ELYRA_METADATA_PATH environment variable has highest priority.

    This is based on jupyter_core.paths.jupyter_path, but where the python
    env-based directory is last in the list, preceded by the system shared
    locations with the user's home-based directory still first in the list.

    The first directory in the list (data_dir, if env is not set) is where files
    will be written, although files can reside at other levels as well, with
    SYSTEM_JUPYTER_PATH representing shared data and ENV_JUPYTER_PATH representing
    the location of factory data (created during installation).

    If ``*subdirs`` are given, that subdirectory will be added to each element.
    """

    paths = []
    # highest priority is env
    if os.environ.get('ELYRA_METADATA_PATH'):
        paths.extend(
            p.rstrip(os.sep)
            for p in os.environ['ELYRA_METADATA_PATH'].split(os.pathsep)
        )
    # then user dir
    paths.append(jupyter_core.paths.jupyter_data_dir())

    # then system, where shared files will reside
    # Note, we're using getattr for these, since tests adjust the value of these
    # and we need to pull them at runtime, rather than during load.
    system_path = getattr(jupyter_core.paths, 'SYSTEM_JUPYTER_PATH')
    paths.extend(system_path)

    # then sys.prefix, where installed files will reside (factory data)
    env_path = getattr(jupyter_core.paths, 'ENV_JUPYTER_PATH')
    for p in env_path:
        if p not in system_path:
            paths.append(p)

    # add subdir, if requested.
    # Note, the 'metadata' parent dir is automatically added.
    if subdirs:
        paths = [os.path.join(p, 'metadata', *subdirs) for p in paths]
    return paths
コード例 #2
0
async def test_modify_component_catalogs(jp_environ, component_cache,
                                         metadata_manager_with_teardown,
                                         create_inprocess):
    # Get initial set of components
    initial_components = component_cache.get_all_components(RUNTIME_PROCESSOR)

    # Create new registry instance with a single URL-based component
    paths = [_get_resource_path("kfp_test_operator.yaml")]

    instance_metadata = {
        "description": "A test registry",
        "runtime_type": RUNTIME_PROCESSOR.name,
        "categories": ["New Components"],
        "paths": paths,
    }
    registry_instance = Metadata(
        schema_name="local-file-catalog",
        name=TEST_CATALOG_NAME,
        display_name="New Test Registry",
        metadata=instance_metadata,
    )

    if create_inprocess:
        metadata_manager_with_teardown.create(TEST_CATALOG_NAME,
                                              registry_instance)
    else:
        res: CompletedProcess = run([
            "elyra-metadata",
            "install",
            "component-catalogs",
            f"--schema_name={registry_instance.schema_name}",
            f"--json={registry_instance.to_json()}",
            f"--name={TEST_CATALOG_NAME}",
        ])
        assert res.returncode == 0

    # Wait for update to complete
    component_cache.wait_for_all_cache_tasks()

    # Get new set of components from all active registries, including added test registry
    components_after_create = component_cache.get_all_components(
        RUNTIME_PROCESSOR)
    assert len(components_after_create) == len(initial_components) + 1

    added_component_names = [
        component.name for component in components_after_create
    ]
    assert "Test Operator" in added_component_names
    assert "Test Operator No Inputs" not in added_component_names

    # Modify the test registry to add a path to the catalog instance
    paths.append(_get_resource_path("kfp_test_operator_no_inputs.yaml"))
    metadata_manager_with_teardown.update(TEST_CATALOG_NAME, registry_instance)

    # Wait for update to complete
    component_cache.wait_for_all_cache_tasks()

    # Get set of components from all active registries, including modified test registry
    components_after_update = component_cache.get_all_components(
        RUNTIME_PROCESSOR)
    assert len(components_after_update) == len(initial_components) + 2

    modified_component_names = [
        component.name for component in components_after_update
    ]
    assert "Test Operator" in modified_component_names
    assert "Test Operator No Inputs" in modified_component_names

    # Delete the test registry
    metadata_manager_with_teardown.remove(TEST_CATALOG_NAME)

    # Wait for update to complete
    component_cache.wait_for_all_cache_tasks()

    # Check that components remaining after delete are the same as before the new catalog was added
    components_after_remove = component_cache.get_all_components(
        RUNTIME_PROCESSOR)
    assert len(components_after_remove) == len(initial_components)