(content string)
| 1133 | var rePoetryDepLine = regexp.MustCompile(`^(\S+)\s*=\s*["']([^"']+)["']`) |
| 1134 | |
| 1135 | func parsePoetryDeps(content string) []string { |
| 1136 | lines := strings.Split(content, "\n") |
| 1137 | inSection := false |
| 1138 | var deps []string |
| 1139 | for _, line := range lines { |
| 1140 | trimmed := strings.TrimSpace(line) |
| 1141 | if trimmed == "[tool.poetry.dependencies]" { |
| 1142 | inSection = true |
| 1143 | continue |
| 1144 | } |
| 1145 | if inSection { |
| 1146 | if strings.HasPrefix(trimmed, "[") { |
| 1147 | break // next section |
| 1148 | } |
| 1149 | m := rePoetryDepLine.FindStringSubmatch(trimmed) |
| 1150 | if m == nil { |
| 1151 | continue |
| 1152 | } |
| 1153 | name, ver := m[1], m[2] |
| 1154 | if strings.EqualFold(name, "python") { |
| 1155 | continue // skip python version constraint |
| 1156 | } |
| 1157 | // Convert Poetry version specifier to pip specifier. |
| 1158 | // Poetry uses "^1.0" (caret) and "~1.0" (tilde) which pip doesn't understand. |
| 1159 | // Map them to >= equivalents for installation purposes. |
| 1160 | ver = poetryVerToPip(name, ver) |
| 1161 | if ver != "" { |
| 1162 | deps = append(deps, ver) |
| 1163 | } else { |
| 1164 | deps = append(deps, name) |
| 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | return deps |
| 1169 | } |
| 1170 | |
| 1171 | // poetryVerToPip converts a Poetry version specifier to a pip-compatible one. |
| 1172 | // e.g. "^3.228.0" → "pulumi>=3.228.0", "==3.228.0" → "pulumi==3.228.0" |
no test coverage detected