PEP 621: [project] dependencies = [...]
(toml: string, deps: string[])
| 1172 | |
| 1173 | /** PEP 621: [project] dependencies = [...] */ |
| 1174 | function parsePyprojectProjectDeps(toml: string, deps: string[]): void { |
| 1175 | const projectIdx = toml.indexOf("[project]"); |
| 1176 | if (projectIdx < 0) return; |
| 1177 | |
| 1178 | const afterProject = toml.slice(projectIdx); |
| 1179 | const depMatch = afterProject.match(/\bdependencies\s*=\s*\[/); |
| 1180 | if (!depMatch) return; |
| 1181 | |
| 1182 | // Bracket counting to handle packages with extras like django[bcrypt] |
| 1183 | const arrStart = projectIdx + (depMatch.index ?? 0) + depMatch[0].length - 1; |
| 1184 | let depth = 1; |
| 1185 | let pos = arrStart + 1; |
| 1186 | let inStr = false; |
| 1187 | while (pos < toml.length && depth > 0) { |
| 1188 | const ch = toml[pos]; |
| 1189 | if (ch === '"' && toml[pos - 1] !== "\\") inStr = !inStr; |
| 1190 | if (!inStr) { |
| 1191 | if (ch === "[") depth++; |
| 1192 | else if (ch === "]") depth--; |
| 1193 | } |
| 1194 | pos++; |
| 1195 | } |
| 1196 | const depsContent = toml.slice(arrStart + 1, pos - 1); |
| 1197 | for (const m of depsContent.matchAll(/"([^"]+)"/g)) { |
| 1198 | addPythonDep(m[1].split(/[>=<\[!~;]/)[0], deps); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | /** Poetry: [tool.poetry.dependencies] — key = "version" pairs */ |
| 1203 | function parsePyprojectPoetryDeps(toml: string, deps: string[]): void { |
no test coverage detected