-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEnvironmentConfig.cs
66 lines (56 loc) · 2.04 KB
/
EnvironmentConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.IO;
namespace Bonsai.Scripting.Python
{
internal class EnvironmentConfig
{
private EnvironmentConfig()
{
}
public EnvironmentConfig(string pythonHome, string pythonVersion)
{
Path = pythonHome;
PythonHome = pythonHome;
PythonVersion = pythonVersion;
IncludeSystemSitePackages = true;
}
public string Path { get; private set; }
public string PythonHome { get; private set; }
public string PythonVersion { get; private set; }
public bool IncludeSystemSitePackages { get; private set; }
public static EnvironmentConfig FromConfigFile(string configFileName)
{
var config = new EnvironmentConfig
{
Path = System.IO.Path.GetDirectoryName(configFileName)
};
using var configReader = new StreamReader(File.OpenRead(configFileName));
while (!configReader.EndOfStream)
{
var line = configReader.ReadLine();
if (line.StartsWith("home"))
{
config.PythonHome = GetConfigValue(line);
}
else if (line.StartsWith("include-system-site-packages"))
{
config.IncludeSystemSitePackages = bool.Parse(GetConfigValue(line));
}
else if (line.StartsWith("version"))
{
var pythonVersion = GetConfigValue(line);
if (!string.IsNullOrEmpty(pythonVersion))
{
pythonVersion = pythonVersion.Substring(0, pythonVersion.LastIndexOf('.'));
}
config.PythonVersion = pythonVersion;
}
}
return config;
}
private static string GetConfigValue(string line)
{
var parts = line.Split('=');
return parts.Length > 1 ? parts[1].Trim() : string.Empty;
}
}
}