# Path: sampletester/parser.py
# SCHEMA_TYPE_KEY = 'type'
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# SCHEMA_TYPE_SEPARATOR = '/'
# SCHEMA_VERSION_KEY = 'schema_version'
# class SchemaDescriptor:
# class IndexedDocs(object):
# class YamlDocSyntaxError(Exception):
#   def __post_init__(self) -> str:
#   def has_version(self) -> bool:
#   def __init__(self,
#                strict: bool = False,
#                resolver: Callable[[Document], str] = None):
#   def contains(self, *type_names: str) -> bool:
#   def from_files(self, *paths: str):
#   def from_strings(self, *sources: Tuple[str, str]):
#   def add(self, content:str, file_name: str):
#   def add_documents(self, *documents: Document):
#   def of_type(self, type_name: str) -> List[Document]:
#   def resolve_uncategorized(self):
# def only_files_in(paths: Iterable[str]) -> Set[str]:
# 
# Path: sampletester/parser.py
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# 
# Path: sampletester/sample_manifest.py
# SCHEMA = parser.SchemaDescriptor('manifest')
# 
# Path: sampletester/testplan.py
# SCHEMA = parser.SchemaDescriptor('test','samples', 1)


import glob
import itertools
import logging
import os
from functools import reduce
from typing import Set
from sampletester import parser
from sampletester.parser import SCHEMA_TYPE_ABSENT as UNKNOWN_TYPE
from sampletester.sample_manifest import SCHEMA as MANIFEST_SCHEMA
from sampletester.testplan import SCHEMA as TESTPLAN_SCHEMA
    if prev_ext == ".manifest":
      return MANIFEST_SCHEMA.primary_type
    else:
      return TESTPLAN_SCHEMA.primary_type
  return UNKNOWN_TYPE


def index_docs(*file_patterns: str) -> parser.IndexedDocs:
  """Obtains manifests and testplans by indexing the specified paths or cwd.

  This function works in the following sequence:

  1. It attempts to obtain all the manifests and testplans contained in
  the globs in `file_patterns`.

  2. If either no manifest or no testplan is obtained this way:

    2.1 if any of the globs in `file_patterns` resolved to a directory, it does
        not search for any more files.

    2.2 if none of the globs in `file_patterns` resolved to a directory, it
        searches in all the paths under the cwd and registers the
        `file_patterns` matching the types not found in the previous step. In
        other words, if no manifests are found via the globs in `file_patterns`,
        it attempts to get manifests under the cwd, and similarly for testplans.

  Returns: the indexed docs of the files that were searched for.
  """
  def log_files(indexed_files):
    "Helper to be called before exiting this method"

# Path: sampletester/parser.py
# SCHEMA_TYPE_KEY = 'type'
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# SCHEMA_TYPE_SEPARATOR = '/'
# SCHEMA_VERSION_KEY = 'schema_version'
# class SchemaDescriptor:
# class IndexedDocs(object):
# class YamlDocSyntaxError(Exception):
#   def __post_init__(self) -> str:
#   def has_version(self) -> bool:
#   def __init__(self,
#                strict: bool = False,
#                resolver: Callable[[Document], str] = None):
#   def contains(self, *type_names: str) -> bool:
#   def from_files(self, *paths: str):
#   def from_strings(self, *sources: Tuple[str, str]):
#   def add(self, content:str, file_name: str):
#   def add_documents(self, *documents: Document):
#   def of_type(self, type_name: str) -> List[Document]:
#   def resolve_uncategorized(self):
# def only_files_in(paths: Iterable[str]) -> Set[str]:
# 
# Path: sampletester/parser.py
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# 
# Path: sampletester/sample_manifest.py
# SCHEMA = parser.SchemaDescriptor('manifest')
# 
# Path: sampletester/testplan.py
# SCHEMA = parser.SchemaDescriptor('test','samples', 1)


# Path: sampletester/inputs.py
import glob
import itertools
import logging
import os
from functools import reduce
from typing import Set
from sampletester import parser
from sampletester.parser import SCHEMA_TYPE_ABSENT as UNKNOWN_TYPE
from sampletester.sample_manifest import SCHEMA as MANIFEST_SCHEMA
from sampletester.testplan import SCHEMA as TESTPLAN_SCHEMA

    if prev_ext == ".manifest":
      return MANIFEST_SCHEMA.primary_type
    else:
      return TESTPLAN_SCHEMA.primary_type
  return UNKNOWN_TYPE


def index_docs(*file_patterns: str) -> parser.IndexedDocs:
  """Obtains manifests and testplans by indexing the specified paths or cwd.

  This function works in the following sequence:

  1. It attempts to obtain all the manifests and testplans contained in
  the globs in `file_patterns`.

  2. If either no manifest or no testplan is obtained this way:

    2.1 if any of the globs in `file_patterns` resolved to a directory, it does
        not search for any more files.

    2.2 if none of the globs in `file_patterns` resolved to a directory, it
        searches in all the paths under the cwd and registers the
        `file_patterns` matching the types not found in the previous step. In
        other words, if no manifests are found via the globs in `file_patterns`,
        it attempts to get manifests under the cwd, and similarly for testplans.

  Returns: the indexed docs of the files that were searched for.
  """
  def log_files(indexed_files):
    "Helper to be called before exiting this method"

    manifest_paths = [doc.path for doc in indexed_files.of_type(MANIFEST_SCHEMA.primary_type)]