MCPcopy Create free account
hub / github.com/IBM/AssetOpsBench / _collect_docs

Function _collect_docs

src/couchdb/loader.py:120–155  ·  view source on GitHub ↗

Resolve a manifest source ("default"/path/dir/list/inline docs) to parsed docs. Relative data paths resolve against the scenario folder (``base_dir``), then its parent (so a sibling ``shared/`` corpus is reachable as ``shared/...``), then ``_HERE``. With base_dir=None (legacy flat manif

(key, source, cfg, base_dir=None)

Source from the content-addressed store, hash-verified

118
119
120def _collect_docs(key, source, cfg, base_dir=None) -> list:
121 """Resolve a manifest source ("default"/path/dir/list/inline docs) to parsed docs.
122
123 Relative data paths resolve against the scenario folder (``base_dir``), then its parent
124 (so a sibling ``shared/`` corpus is reachable as ``shared/...``), then ``_HERE``. With
125 base_dir=None (legacy flat manifests) only ``_HERE`` is used, preserving behaviour.
126 """
127 roots = ([base_dir, os.path.dirname(base_dir)] if base_dir else []) + [_HERE]
128 ext = ".csv" if cfg.get("format") == "csv" else ".json"
129
130 def _resolve(s):
131 for root in roots:
132 p = os.path.join(root, s)
133 if os.path.exists(p):
134 return p
135 return os.path.join(roots[0], s)
136
137 def files_from(s):
138 if s.strip().lower() == "default":
139 return sorted(glob.glob(os.path.join(SAMPLE_DATA_DIR, key, "*" + ext)))
140 p = s if os.path.isabs(s) else _resolve(s)
141 if os.path.isdir(p):
142 return sorted(glob.glob(os.path.join(p, "*" + ext)))
143 return [p]
144
145 docs = []
146 for item in source if isinstance(source, list) else [source]:
147 if isinstance(item, dict):
148 docs.append(item) # inline document
149 elif isinstance(item, str):
150 for fp in files_from(item):
151 if not os.path.isfile(fp):
152 logger.warning("data file not found: %s", fp)
153 continue
154 docs += _parse_file(fp, cfg)
155 return docs
156
157
158# --------------------------------------------------------------------------- #

Callers 1

load_collectionFunction · 0.85

Calls 3

files_fromFunction · 0.85
_parse_fileFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected