Skip to content

Commit d02f62e

Browse files
zavubGitHub Enterprise
authored andcommitted
improve dev editor experience (#15)
1 parent 0c6c2bc commit d02f62e

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

DSPythonNet3/DSPythonNet3CodeCompletionProviderCore.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class DSPythonNet3CodeCompletionProviderCore : PythonCodeCompletionProv
3535
/// The scope used by the engine. This is where all the loaded symbols
3636
/// are stored. It's essentially an environment dictionary.
3737
/// </summary>
38-
internal PyModule Scope
38+
internal PyModule? Scope
3939
{
4040
get { return scope; }
4141
set { scope = value; }
@@ -413,10 +413,10 @@ protected override object EvaluateScript(string script, PythonScriptType evalTyp
413413
switch (evalType)
414414
{
415415
case PythonScriptType.Expression:
416-
var result = Scope.Eval(script);
416+
var result = Scope?.Eval(script);
417417
return DSPythonNet3Evaluator.OutputMarshaler.Marshal(result);
418418
default:
419-
Scope.Exec(script);
419+
Scope?.Exec(script);
420420
return null;
421421
}
422422
}
@@ -568,6 +568,7 @@ public void Dispose()
568568
using (Py.GIL())
569569
{
570570
Scope.Dispose();
571+
Scope = null;
571572
}
572573
}
573574
catch { }

DSPythonNet3/DSPythonNet3Evaluator.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,36 @@ internal static async Task InstallPythonAsync()
344344
AssemblyLoadContext context = AssemblyLoadContext.GetLoadContext(assembly) ?? throw new Exception("Can't get assembly context.");
345345

346346
Assembly wheelsAssembly = context.LoadFromAssemblyPath(Path.Join(Path.GetDirectoryName(assembly.Location), "DSPythonNet3Wheels.dll"));
347-
await Task.WhenAll(wheelsAssembly.GetManifestResourceNames().Where(x => x.Contains(".whl")).Select(wheel => Python.Included.Installer.InstallWheel(wheelsAssembly, wheel))).ConfigureAwait(false);
347+
348+
List<string> pipWheelInstall = new List<string>();
349+
await Task.WhenAll(wheelsAssembly.GetManifestResourceNames().Where(x =>
350+
{
351+
bool isWheel = x.Contains(".whl");
352+
if (isWheel && x.Contains("pywin32-"))
353+
{
354+
pipWheelInstall.Add(x);
355+
return false;
356+
}
357+
358+
return isWheel;
359+
}).Select(wheel => Python.Included.Installer.InstallWheel(wheelsAssembly, wheel))).ConfigureAwait(false);
360+
361+
foreach (var pipWheelResource in pipWheelInstall)
362+
{
363+
var pipWheelName = pipWheelResource.Remove(0, "DSPythonNet3Wheels.Resources.".Count());
364+
string wheelPath = Path.Combine(Python.Included.Installer.EmbeddedPythonHome, "Lib", pipWheelName);
365+
using (Stream? stream = wheelsAssembly.GetManifestResourceStream(pipWheelResource))
366+
{
367+
using (FileStream destination = new FileStream(wheelPath, FileMode.Create))
368+
{
369+
stream?.CopyTo(destination);
370+
}
371+
}
372+
373+
string cmdToExecute = $"python -m pip install \"Lib\\{pipWheelName}\"";
374+
await Python.Deployment.Installer.RunCommand(cmdToExecute, CancellationToken.None);
375+
File.Delete(wheelPath);
376+
}
348377

349378
isPythonInstalled = true;
350379
}
1.74 MB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)