2121// calls are made to indicate what's going on during the load...
2222//============================================================================
2323using System ;
24+ using System . Diagnostics ;
2425using System . Globalization ;
2526using System . IO ;
2627using System . Reflection ;
@@ -37,9 +38,7 @@ public static IntPtr PyInit_clr()
3738public static void initclr ( )
3839#endif
3940{
40- #if DEBUG
41- Console . WriteLine ( "Attempting to load Python.Runtime using standard binding rules... " ) ;
42- #endif
41+ debugPrint ( "Attempting to load 'Python.Runtime' using standard binding rules." ) ;
4342#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
4443var pythonRuntimePublicKeyTokenData = new byte [ ] { 0x50 , 0x00 , 0xfe , 0xa6 , 0xcb , 0xa7 , 0x02 , 0xdd } ;
4544#endif
@@ -65,12 +64,11 @@ public static void initclr()
6564try
6665{
6766pythonRuntime = Assembly . Load ( pythonRuntimeName ) ;
68- #if DEBUG
69- Console . WriteLine ( "Success!" ) ;
70- #endif
67+ debugPrint ( "Success loading 'Python.Runtime' using standard binding rules." ) ;
7168}
7269catch ( IOException )
7370{
71+ debugPrint ( "'Python.Runtime' not found using standard binding rules." ) ;
7472try
7573{
7674// If the above fails for any reason, we fallback to attempting to load "Python.Runtime.dll"
@@ -89,16 +87,13 @@ public static void initclr()
8987throw new InvalidOperationException ( executingAssembly . Location ) ;
9088}
9189string pythonRuntimeDllPath = Path . Combine ( assemblyDirectory , "Python.Runtime.dll" ) ;
92- #if DEBUG
93- Console . WriteLine ( "Attempting to load Python.Runtime from: '{0}'..." , pythonRuntimeDllPath ) ;
94- #endif
90+ debugPrint ( $ "Attempting to load Python.Runtime from: '{ pythonRuntimeDllPath } .'") ;
9591pythonRuntime = Assembly . LoadFrom ( pythonRuntimeDllPath ) ;
92+ debugPrint ( $ "Success loading 'Python.Runtime' from: '{ pythonRuntimeDllPath } '.") ;
9693}
9794catch ( InvalidOperationException )
9895{
99- #if DEBUG
100- Console . WriteLine ( "Could not load Python.Runtime" ) ;
101- #endif
96+ debugPrint ( "Could not load 'Python.Runtime'." ) ;
10297#if PYTHON3
10398return IntPtr . Zero ;
10499#elif PYTHON2
@@ -117,4 +112,14 @@ public static void initclr()
117112pythonEngineType . InvokeMember ( "InitExt" , BindingFlags . InvokeMethod , null , null , null ) ;
118113#endif
119114}
115+
116+ /// <summary>
117+ /// Substitute for Debug.Writeline(...). Ideally we would use Debug.Writeline
118+ /// but haven't been able to configure the TRACE from within Python.
119+ /// </summary>
120+ [ Conditional ( "DEBUG" ) ]
121+ private static void debugPrint ( string str )
122+ {
123+ Console . WriteLine ( str ) ;
124+ }
120125}
0 commit comments