@@ -109,6 +109,40 @@ IEnumerable<PythonEnvironment> Impl() {
109109 }
110110 }
111111
112+ public static PythonEnvironment FromInterpreterChecked ( FileInfo interpreter ) {
113+ if ( interpreter is null ) throw new ArgumentNullException ( nameof ( interpreter ) ) ;
114+
115+ if ( ! interpreter . Exists )
116+ throw new FileNotFoundException ( "Interpreter file not found" , interpreter . FullName ) ;
117+
118+ var version = TryGetVersion ( interpreter ) ;
119+ if ( version is null )
120+ throw new NotSupportedException ( "Unable to get interpreter version" ) ;
121+
122+ DirectoryInfo ? home = null ;
123+ string ? dllPath = null ;
124+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) {
125+ home = new DirectoryInfo ( interpreter . DirectoryName ) ;
126+ dllPath = GetDll ( home , version ) ;
127+ if ( dllPath != null && ! File . Exists ( dllPath ) )
128+ throw new NotSupportedException ( "Unable to find dynamic library" ) ;
129+ }
130+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux )
131+ || RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ) {
132+ dllPath = TryLocateSo ( interpreter ) ;
133+ if ( dllPath != null ) {
134+ home = TryGuessUnixHome ( interpreter , version , dllPath : dllPath ) ;
135+ } else {
136+ throw new NotSupportedException ( "Unable to find dynamic library" ) ;
137+ }
138+ }
139+
140+ return new PythonEnvironment ( interpreter , home ,
141+ dll : dllPath is null ? null : new FileInfo ( dllPath ) ,
142+ languageVersion : version ,
143+ architecture : null ) ;
144+ }
145+
112146 /// <summary>
113147 /// Enumerate Python environments, listed in the PATH environment variable.
114148 /// </summary>
@@ -260,7 +294,8 @@ internal static string GetDll(DirectoryInfo home, Version version)
260294 if ( match . Success )
261295 return match . Groups [ "ver" ] . Value ;
262296
263- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && interpreter . Name == "python" )
297+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && interpreter . Name == "python"
298+ || RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && interpreter . Name == "python.exe" )
264299 return TryRunScript ( interpreter , PrintVersionScript ) ;
265300
266301 return null ;
0 commit comments