code: def BuildArtifactsRegistry(
        cls, artifact_definitions_path, custom_artifacts_path):
      
      if artifact_definitions_path and not os.path.isdir(
          artifact_definitions_path):
        raise errors.BadConfigOption(
            'No such artifacts filter file: {0:s}.'.format(
                artifact_definitions_path))
  
      if custom_artifacts_path and not os.path.isfile(custom_artifacts_path):
        raise errors.BadConfigOption(
            'No such artifacts filter file: {0:s}.'.format(custom_artifacts_path))
  
      registry = artifacts_registry.ArtifactDefinitionsRegistry()
      reader = artifacts_reader.YamlArtifactsReader()
  
      try:
        registry.ReadFromDirectory(reader, artifact_definitions_path)
  
      except (KeyError, artifacts_errors.FormatError) as exception:
        raise errors.BadConfigOption((
            'Unable to read artifact definitions from: {0:s} with error: '
            '{1!s}').format(artifact_definitions_path, exception))
  
      if custom_artifacts_path:
        try:
          registry.ReadFromFile(reader, custom_artifacts_path)
  
        except (KeyError, artifacts_errors.FormatError) as exception:
          raise errors.BadConfigOption((
              'Unable to read artifact definitions from: {0:s} with error: '
              '{1!s}').format(custom_artifacts_path, exception))
  
      return registry
docs: Build Find Specs from artifacts or filter file if available.
  
      Args:
         artifact_definitions_path (str): path to artifact definitions file.
         custom_artifacts_path (str): path to custom artifact definitions file.
  
      Returns:
        artifacts.ArtifactDefinitionsRegistry: artifact definitions registry.
  
      Raises:
        RuntimeError: if no valid FindSpecs are built.