def _prepare_artifact(metadata_handler: metadata.Metadata, uri: str, properties: Dict[(str, Any)], custom_properties: Dict[(str, Any)], reimport: bool, output_artifact_class: Type[types.Artifact], mlmd_artifact_type: Optional[metadata_store_pb2.ArtifactType]) -> types.Artifact:
    "Prepares the Importer's output artifact.\n\n  If there is already an artifact in MLMD with the same URI and properties /\n  custom properties, that artifact will be reused unless the `reimport`\n  argument is set to True.\n\n  Args:\n    metadata_handler: The handler of MLMD.\n    uri: The uri of the artifact.\n    properties: The properties of the artifact, given as a dictionary from\n      string keys to integer / string values. Must conform to the declared\n      properties of the destination channel's output type.\n    custom_properties: The custom properties of the artifact, given as a\n      dictionary from string keys to integer / string values.\n    reimport: If set to True, will register a new artifact even if it already\n      exists in the database.\n    output_artifact_class: The class of the output artifact.\n    mlmd_artifact_type: The MLMD artifact type of the Artifact to be created.\n\n  Returns:\n    An Artifact object representing the imported artifact.\n  "
    absl.logging.info(('Processing source uri: %s, properties: %s, custom_properties: %s' % (uri, properties, custom_properties)))
    for (key, value) in custom_properties.items():
        if (not isinstance(value, (int, str, bytes))):
            raise ValueError(('Custom property value for key %r must be a string or integer (got %r instead)' % (key, value)))
    unfiltered_previous_artifacts = metadata_handler.get_artifacts_by_uri(uri)
    previous_artifacts = []
    for candidate_mlmd_artifact in unfiltered_previous_artifacts:
        is_candidate = True
        candidate_artifact = output_artifact_class(mlmd_artifact_type)
        candidate_artifact.set_mlmd_artifact(candidate_mlmd_artifact)
        for (key, value) in properties.items():
            if (getattr(candidate_artifact, key) != value):
                is_candidate = False
                break
        for (key, value) in custom_properties.items():
            if isinstance(value, int):
                if (candidate_artifact.get_int_custom_property(key) != value):
                    is_candidate = False
                    break
            elif isinstance(value, (str, bytes)):
                if (candidate_artifact.get_string_custom_property(key) != value):
                    is_candidate = False
                    break
        if is_candidate:
            previous_artifacts.append(candidate_mlmd_artifact)
    result = output_artifact_class(mlmd_artifact_type)
    result.uri = uri
    _set_artifact_properties(result, properties, custom_properties)
    if (bool(previous_artifacts) and (not reimport)):
        absl.logging.info('Reusing existing artifact')
        result.set_mlmd_artifact(max(previous_artifacts, key=(lambda m: m.id)))
    return result
Prepares the Importer's output artifact.

If there is already an artifact in MLMD with the same URI and properties /
custom properties, that artifact will be reused unless the `reimport`
argument is set to True.

Args:
  metadata_handler: The handler of MLMD.
  uri: The uri of the artifact.
  properties: The properties of the artifact, given as a dictionary from
    string keys to integer / string values. Must conform to the declared
    properties of the destination channel's output type.
  custom_properties: The custom properties of the artifact, given as a
    dictionary from string keys to integer / string values.
  reimport: If set to True, will register a new artifact even if it already
    exists in the database.
  output_artifact_class: The class of the output artifact.
  mlmd_artifact_type: The MLMD artifact type of the Artifact to be created.

Returns:
  An Artifact object representing the imported artifact.
def _prepare_artifact(metadata_handler: metadata.Metadata, uri: str, properties: Dict[(str, Any)], custom_properties: Dict[(str, Any)], reimport: bool, output_artifact_class: Type[types.Artifact], mlmd_artifact_type: Optional[metadata_store_pb2.ArtifactType]) -> types.Artifact:
    "Prepares the Importer's output artifact.\n\n  If there is already an artifact in MLMD with the same URI and properties /\n  custom properties, that artifact will be reused unless the `reimport`\n  argument is set to True.\n\n  Args:\n    metadata_handler: The handler of MLMD.\n    uri: The uri of the artifact.\n    properties: The properties of the artifact, given as a dictionary from\n      string keys to integer / string values. Must conform to the declared\n      properties of the destination channel's output type.\n    custom_properties: The custom properties of the artifact, given as a\n      dictionary from string keys to integer / string values.\n    reimport: If set to True, will register a new artifact even if it already\n      exists in the database.\n    output_artifact_class: The class of the output artifact.\n    mlmd_artifact_type: The MLMD artifact type of the Artifact to be created.\n\n  Returns:\n    An Artifact object representing the imported artifact.\n  "
    absl.logging.info(('Processing source uri: %s, properties: %s, custom_properties: %s' % (uri, properties, custom_properties)))
    for (key, value) in custom_properties.items():
        if (not isinstance(value, (int, str, bytes))):
            raise ValueError(('Custom property value for key %r must be a string or integer (got %r instead)' % (key, value)))
    unfiltered_previous_artifacts = metadata_handler.get_artifacts_by_uri(uri)
    previous_artifacts = []
    for candidate_mlmd_artifact in unfiltered_previous_artifacts:
        is_candidate = True
        candidate_artifact = output_artifact_class(mlmd_artifact_type)
        candidate_artifact.set_mlmd_artifact(candidate_mlmd_artifact)
        for (key, value) in properties.items():
            if (getattr(candidate_artifact, key) != value):
                is_candidate = False
                break
        for (key, value) in custom_properties.items():
            if isinstance(value, int):
                if (candidate_artifact.get_int_custom_property(key) != value):
                    is_candidate = False
                    break
            elif isinstance(value, (str, bytes)):
                if (candidate_artifact.get_string_custom_property(key) != value):
                    is_candidate = False
                    break
        if is_candidate:
            previous_artifacts.append(candidate_mlmd_artifact)
    result = output_artifact_class(mlmd_artifact_type)
    result.uri = uri
    _set_artifact_properties(result, properties, custom_properties)
    if (bool(previous_artifacts) and (not reimport)):
        absl.logging.info('Reusing existing artifact')
        result.set_mlmd_artifact(max(previous_artifacts, key=(lambda m: m.id)))
    return result