You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
58 lines
1.9 KiB
1 year ago
|
using StabilityMatrix.Core.Extensions;
|
||
|
|
||
|
namespace StabilityMatrix.Core.Python;
|
||
|
|
||
|
public record PipShowResult
|
||
|
{
|
||
|
public required string Name { get; init; }
|
||
|
|
||
|
public required string Version { get; init; }
|
||
|
|
||
|
public string? Summary { get; init; }
|
||
|
|
||
|
public string? HomePage { get; init; }
|
||
|
|
||
|
public string? Author { get; init; }
|
||
|
|
||
|
public string? AuthorEmail { get; init; }
|
||
|
|
||
|
public string? License { get; init; }
|
||
|
|
||
|
public string? Location { get; init; }
|
||
|
|
||
|
public List<string>? Requires { get; init; }
|
||
|
|
||
|
public List<string>? RequiredBy { get; init; }
|
||
|
|
||
|
public static PipShowResult Parse(string output)
|
||
|
{
|
||
|
// Decode each line by splitting on first ":" to key and value
|
||
|
var lines = output
|
||
|
.SplitLines(StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
|
||
|
.Select(line => line.Split(new[] { ':' }, 2))
|
||
|
.Where(split => split.Length == 2)
|
||
|
.Select(split => new KeyValuePair<string, string>(split[0].Trim(), split[1].Trim()))
|
||
|
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||
|
|
||
|
return new PipShowResult
|
||
|
{
|
||
|
Name = lines["Name"],
|
||
|
Version = lines["Version"],
|
||
|
Summary = lines.GetValueOrDefault("Summary"),
|
||
|
HomePage = lines.GetValueOrDefault("Home-page"),
|
||
|
Author = lines.GetValueOrDefault("Author"),
|
||
|
AuthorEmail = lines.GetValueOrDefault("Author-email"),
|
||
|
License = lines.GetValueOrDefault("License"),
|
||
|
Location = lines.GetValueOrDefault("Location"),
|
||
|
Requires = lines
|
||
|
.GetValueOrDefault("Requires")
|
||
|
?.Split(new[] { ',' }, StringSplitOptions.TrimEntries)
|
||
|
.ToList(),
|
||
|
RequiredBy = lines
|
||
|
.GetValueOrDefault("Required-by")
|
||
|
?.Split(new[] { ',' }, StringSplitOptions.TrimEntries)
|
||
|
.ToList()
|
||
|
};
|
||
|
}
|
||
|
}
|