@@ -43,34 +43,38 @@ internal RuntimeManager(string pythonHome, string scriptPath, IObserver<RuntimeM
43
43
disposable => disposable . Subject )
44
44
. Take ( 1 ) ;
45
45
46
- internal static bool IsEmbeddedResourcePath ( string path )
46
+ static bool IsEmbeddedResourcePath ( string path )
47
47
{
48
48
var separatorIndex = path . IndexOf ( AssemblySeparator ) ;
49
49
return separatorIndex >= 0 && ! SystemPath . IsPathRooted ( path ) ;
50
50
}
51
51
52
- internal static string GetEmbeddedPythonCode ( string path )
52
+ static string ReadAllText ( string path )
53
53
{
54
- var nameElements = path . Split ( new [ ] { AssemblySeparator } , 2 ) ;
55
- if ( string . IsNullOrEmpty ( nameElements [ 0 ] ) )
54
+ if ( IsEmbeddedResourcePath ( path ) )
56
55
{
57
- throw new InvalidOperationException (
58
- "The embedded resource path \" " + path +
59
- "\" must be qualified with a valid assembly name." ) ;
60
- }
56
+ var nameElements = path . Split ( new [ ] { AssemblySeparator } , 2 ) ;
57
+ if ( string . IsNullOrEmpty ( nameElements [ 0 ] ) )
58
+ {
59
+ throw new InvalidOperationException (
60
+ "The embedded resource path \" " + path +
61
+ "\" must be qualified with a valid assembly name." ) ;
62
+ }
61
63
62
- var assembly = Assembly . Load ( nameElements [ 0 ] ) ;
63
- var resourceName = string . Join ( ExpressionHelper . MemberSeparator , nameElements ) ;
64
- using var resourceStream = assembly . GetManifestResourceStream ( resourceName ) ;
65
- if ( resourceStream == null )
66
- {
67
- throw new InvalidOperationException (
68
- "The specified embedded resource \" " + nameElements [ 1 ] +
69
- "\" was not found in assembly \" " + nameElements [ 0 ] + "\" " ) ;
64
+ var assembly = Assembly . Load ( nameElements [ 0 ] ) ;
65
+ var resourceName = string . Join ( ExpressionHelper . MemberSeparator , nameElements ) ;
66
+ using var resourceStream = assembly . GetManifestResourceStream ( resourceName ) ;
67
+ if ( resourceStream == null )
68
+ {
69
+ throw new InvalidOperationException (
70
+ "The specified embedded resource \" " + nameElements [ 1 ] +
71
+ "\" was not found in assembly \" " + nameElements [ 0 ] + "\" " ) ;
72
+ }
73
+
74
+ using var reader = new StreamReader ( resourceStream ) ;
75
+ return reader . ReadToEnd ( ) ;
70
76
}
71
- using var reader = new StreamReader ( resourceStream ) ;
72
- var code = reader . ReadToEnd ( ) ;
73
- return code ;
77
+ else return File . ReadAllText ( path ) ;
74
78
}
75
79
76
80
internal static DynamicModule CreateModule ( string name = "" , string scriptPath = "" )
@@ -82,7 +86,7 @@ internal static DynamicModule CreateModule(string name = "", string scriptPath =
82
86
{
83
87
try
84
88
{
85
- var code = IsEmbeddedResourcePath ( scriptPath ) ? GetEmbeddedPythonCode ( scriptPath ) : File . ReadAllText ( scriptPath ) ;
89
+ var code = ReadAllText ( scriptPath ) ;
86
90
module . Exec ( code ) ;
87
91
}
88
92
catch ( Exception )
0 commit comments