Skip to content

Commit 70fc803

Browse files
committed
CI: figure out DLL name from environment
1 parent 2498d47 commit 70fc803

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818

1919
env:
2020
PYTHONNET_SHUTDOWN_MODE: ${{ matrix.SHUTDOWN_MODE }}
21+
PYTHONNET_PYVER: ${{ matrix.PYTHON }}
2122

2223
steps:
2324
- name: Set Environment on macOS

src/runtime/runtime.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Python.Runtime.Native;
1010
using Python.Runtime.Platform;
1111
using System.Linq;
12+
using static System.FormattableString;
1213

1314
namespace Python.Runtime
1415
{
@@ -30,7 +31,29 @@ public static string PythonDLL
3031
}
3132
}
3233

33-
static string _PythonDll;
34+
static string _PythonDll = GetDefaultDllName();
35+
private static string GetDefaultDllName()
36+
{
37+
string dll = Environment.GetEnvironmentVariable("PYTHONNET_PYDLL");
38+
if (dll is not null) return dll;
39+
40+
string verString = Environment.GetEnvironmentVariable("PYTHONNET_PYVER");
41+
if (!Version.TryParse(verString, out var version)) return null;
42+
43+
return GetDefaultDllName(version);
44+
}
45+
46+
private static string GetDefaultDllName(Version version)
47+
{
48+
string prefix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "" : "lib";
49+
string suffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
50+
? Invariant($"{version.Major}{version.Minor}")
51+
: Invariant($"{version.Major}.{version.Minor}");
52+
string ext = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll"
53+
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib"
54+
: ".so";
55+
return prefix + "python" + suffix + ext;
56+
}
3457

3558
// set to true when python is finalizing
3659
internal static object IsFinalizingLock = new object();

0 commit comments

Comments
 (0)