* Parses a `requirements.txt` file and returns an array of packages * * Caches the result. * @returns List of package data w/ name and version
()
| 206 | * @returns List of package data w/ name and version |
| 207 | */ |
| 208 | protected async parseRequirementsTxt(): Promise<PipPackage[]> { |
| 209 | if (this.requirementsTxt) { |
| 210 | return this.requirementsTxt; |
| 211 | } |
| 212 | |
| 213 | const requiredPackages: PipPackage[] = []; |
| 214 | |
| 215 | try { |
| 216 | let requirementsTxt = await fs.readFile(REQUIREMENTS_TXT_PATH, 'utf8'); |
| 217 | requirementsTxt = requirementsTxt.trim(); |
| 218 | log.debug('Raw %s: %s', NAME_REQUIREMENTS_TXT, requirementsTxt); |
| 219 | for (const line of requirementsTxt.split(/\r?\n/)) { |
| 220 | const [name, version] = line.trim().split('=='); |
| 221 | requiredPackages.push({name, version}); |
| 222 | } |
| 223 | log.debug('Parsed %s: %O', NAME_REQUIREMENTS_TXT, requiredPackages); |
| 224 | } catch (e) { |
| 225 | throw new DocutilsError(`Could not find ${REQUIREMENTS_TXT_PATH}. This is a bug`, {cause: e}); |
| 226 | } |
| 227 | |
| 228 | return (this.requirementsTxt = requiredPackages); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Resets the cache of emitted errors |
no test coverage detected