Return a mapping of package data collected from the opam OCaml package manifest ``text``.
(text)
| 176 | |
| 177 | |
| 178 | def parse_opam_from_text(text): |
| 179 | """ |
| 180 | Return a mapping of package data collected from the opam OCaml package |
| 181 | manifest ``text``. |
| 182 | """ |
| 183 | |
| 184 | opam_data = {} |
| 185 | |
| 186 | lines = text.splitlines() |
| 187 | for i, line in enumerate(lines): |
| 188 | parsed_line = parse_file_line(line) |
| 189 | if not parsed_line: |
| 190 | continue |
| 191 | key = parsed_line.group('key').strip() |
| 192 | value = parsed_line.group('value').strip() |
| 193 | if key == 'description': # Get multiline description |
| 194 | value = '' |
| 195 | for cont in lines[i + 1:]: |
| 196 | value += ' ' + cont.strip() |
| 197 | if '"""' in cont: |
| 198 | break |
| 199 | |
| 200 | opam_data[key] = clean_data(value) |
| 201 | |
| 202 | if key == 'maintainer': |
| 203 | stripped_val = value.strip('["] ') |
| 204 | stripped_val = stripped_val.split('" "') |
| 205 | opam_data[key] = stripped_val |
| 206 | elif key == 'authors': |
| 207 | if '[' in line: # If authors are present in multiple lines |
| 208 | for authors in lines[i + 1:]: |
| 209 | value += ' ' + authors.strip() |
| 210 | if ']' in authors: |
| 211 | break |
| 212 | value = value.strip('["] ') |
| 213 | else: |
| 214 | value = clean_data(value) |
| 215 | value = value.split('" "') |
| 216 | opam_data[key] = value |
| 217 | elif key == 'depends': # Get multiline dependencies |
| 218 | value = [] |
| 219 | for dep in lines[i + 1:]: |
| 220 | if ']' in dep: |
| 221 | break |
| 222 | parsed_dep = parse_dep(dep) |
| 223 | if parsed_dep: |
| 224 | version = parsed_dep.group('version').strip('{ } ').replace('"', '') |
| 225 | name = parsed_dep.group('name').strip() |
| 226 | value.append(dict( |
| 227 | purl=PackageURL(type='opam', name=name).to_string(), |
| 228 | version=version, |
| 229 | )) |
| 230 | opam_data[key] = value |
| 231 | |
| 232 | elif key == 'src': # Get multiline src |
| 233 | if not value: |
| 234 | value = lines[i + 1].strip() |
| 235 | opam_data[key] = clean_data(value) |
no test coverage detected