File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919 env :
2020 PYTHONNET_SHUTDOWN_MODE : ${{ matrix.SHUTDOWN_MODE }}
21+ PYTHONNET_PYVER : ${{ matrix.PYTHON }}
2122
2223 steps :
2324 - name : Set Environment on macOS
Original file line number Diff line number Diff line change 99using Python . Runtime . Native ;
1010using Python . Runtime . Platform ;
1111using System . Linq ;
12+ using static System . FormattableString ;
1213
1314namespace 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 ( ) ;
You can’t perform that action at this time.
0 commit comments