21
21
// calls are made to indicate what's going on during the load...
22
22
//============================================================================
23
23
using System ;
24
+ using System . Diagnostics ;
24
25
using System . Globalization ;
25
26
using System . IO ;
26
27
using System . Reflection ;
@@ -37,9 +38,7 @@ public static IntPtr PyInit_clr()
37
38
public static void initclr ( )
38
39
#endif
39
40
{
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." ) ;
43
42
#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
44
43
var pythonRuntimePublicKeyTokenData = new byte [ ] { 0x50 , 0x00 , 0xfe , 0xa6 , 0xcb , 0xa7 , 0x02 , 0xdd } ;
45
44
#endif
@@ -65,12 +64,11 @@ public static void initclr()
65
64
try
66
65
{
67
66
pythonRuntime = Assembly . Load ( pythonRuntimeName ) ;
68
- #if DEBUG
69
- Console . WriteLine ( "Success!" ) ;
70
- #endif
67
+ debugPrint ( "Success loading 'Python.Runtime' using standard binding rules." ) ;
71
68
}
72
69
catch ( IOException )
73
70
{
71
+ debugPrint ( "'Python.Runtime' not found using standard binding rules." ) ;
74
72
try
75
73
{
76
74
// If the above fails for any reason, we fallback to attempting to load "Python.Runtime.dll"
@@ -89,16 +87,13 @@ public static void initclr()
89
87
throw new InvalidOperationException ( executingAssembly . Location ) ;
90
88
}
91
89
string 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 } .'") ;
95
91
pythonRuntime = Assembly . LoadFrom ( pythonRuntimeDllPath ) ;
92
+ debugPrint ( $ "Success loading 'Python.Runtime' from: '{ pythonRuntimeDllPath } '.") ;
96
93
}
97
94
catch ( InvalidOperationException )
98
95
{
99
- #if DEBUG
100
- Console . WriteLine ( "Could not load Python.Runtime" ) ;
101
- #endif
96
+ debugPrint ( "Could not load 'Python.Runtime'." ) ;
102
97
#if PYTHON3
103
98
return IntPtr . Zero ;
104
99
#elif PYTHON2
@@ -117,4 +112,14 @@ public static void initclr()
117
112
pythonEngineType . InvokeMember ( "InitExt" , BindingFlags . InvokeMethod , null , null , null ) ;
118
113
#endif
119
114
}
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
+ }
120
125
}
0 commit comments