-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestsRuntimeConfig.cs
More file actions
77 lines (70 loc) · 2.8 KB
/
Copy pathTestsRuntimeConfig.cs
File metadata and controls
77 lines (70 loc) · 2.8 KB
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
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Python.Runtime.Codecs
{
partial class TestsRuntimeConfig
{
public static void Ensure()
{
if (Path.IsPathFullyQualified(Runtime.PythonDLL)) return;
string pyVer = Environment.GetEnvironmentVariable("PYTHON_VERSION");
if (!string.IsNullOrEmpty(pyVer))
{
Runtime.PythonVersion = Version.Parse(pyVer);
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// work around Python.NET unstable issue with dll suffixes on *nix
if (!Runtime.PythonDLL.StartsWith("lib"))
{
string dllExtension = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so";
Runtime.PythonDLL = "lib" + Runtime.PythonDLL + dllExtension;
}
}
else
{
Runtime.PythonDLL += ".dll";
}
string pyHome = Environment.GetEnvironmentVariable("PYTHON_HOME")
// defined in GitHub action setup-python
?? Environment.GetEnvironmentVariable("pythonLocation");
if (!string.IsNullOrEmpty(pyHome))
{
string dll = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Path.Combine(pyHome, Runtime.PythonDLL)
: Path.Combine(pyHome, "lib", Runtime.PythonDLL);
if (File.Exists(dll))
{
Runtime.PythonDLL = dll;
}
}
if (!Path.IsPathFullyQualified(Runtime.PythonDLL))
{
string[] paths = Environment.GetEnvironmentVariable("PATH")
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
foreach (string pathDir in paths)
{
string dll = Path.Combine(pathDir, Runtime.PythonDLL);
if (File.Exists(dll))
{
Runtime.PythonDLL = dll;
if (string.IsNullOrEmpty(pyHome))
{
pyHome = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
// on Windows, paths is PYTHON_HOME/dll
? Path.GetDirectoryName(dll)
// on *nix the path is HOME/lib/dll
: Path.GetDirectoryName(Path.GetDirectoryName(dll));
}
break;
}
}
}
if (!string.IsNullOrEmpty(pyHome))
{
PythonEngine.PythonHome = pyHome;
}
}
}
}