Skip to content

Commit 405f3fc

Browse files
twastvedtGitHub Enterprise
authored andcommitted
DYN-7554: Return of the python libraries (#9)
* Add wheels as originally implemented. * Use current ALC * Use async right, Trygve
1 parent dfba692 commit 405f3fc

26 files changed

+250
-17
lines changed

DSPythonNet3/DSPythonNet3.csproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88
<NoWarn>MSB3539;CS1591;NUnit2005;NUnit2007;CS0618;CS0612;CS0672</NoWarn>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<Reference Include="Python.Deployment">
12-
<HintPath>..\extern\Python\Python.Deployment.dll</HintPath>
13-
<Private>True</Private>
14-
</Reference>
15-
<Reference Include="Python.Included">
16-
<HintPath>..\extern\Python\Python.Included.dll</HintPath>
17-
<Private>True</Private>
18-
</Reference>
1911
<InternalsVisibleTo Include="PythonMigrationViewExtension" />
2012
<InternalsVisibleTo Include="DynamoPythonTests" />
2113

2214
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynamoPackageVersion)" ExcludeAssets="runtime" />
2315
<PackageReference Include="DynamoVisualProgramming.DynamoServices" Version="$(DynamoPackageVersion)" ExcludeAssets="runtime" />
16+
<PackageReference Include="Python.Included" Version="3.11.6" />
2417
<PackageReference Include="pythonnet" Version="3.1.0-preview-ADSK-*" />
2518
</ItemGroup>
2619
<ItemGroup>
@@ -45,6 +38,9 @@
4538
<LastGenOutput>Resources.en-US.Designer.cs</LastGenOutput>
4639
</EmbeddedResource>
4740
</ItemGroup>
41+
<ItemGroup>
42+
<ProjectReference Include="..\DSPythonNet3Wheels\DSPythonNet3Wheels.csproj" />
43+
</ItemGroup>
4844
<ItemGroup>
4945
<None Update="pkg.json">
5046
<TargetPath>..\%(Filename)%(Extension)</TargetPath>

DSPythonNet3/DSPythonNet3CodeCompletionProviderCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import clr
7171

7272
private object ExecutePythonScriptCode(string code)
7373
{
74-
DSPythonNet3Evaluator.InstallPythonAsync().Wait();
74+
Task.Run(DSPythonNet3Evaluator.InstallPythonAsync).Wait();
7575

7676
if (!PythonEngine.IsInitialized)
7777
{
@@ -375,7 +375,7 @@ public DSPythonNet3CodeCompletionProviderCore()
375375
BasicVariableTypes.Add(Tuple.Create(LIST_VARIABLE, typeof(PyList)));
376376
BasicVariableTypes.Add(Tuple.Create(DICT_VARIABLE, typeof(PyDict)));
377377

378-
DSPythonNet3Evaluator.InstallPythonAsync().Wait();
378+
Task.Run(DSPythonNet3Evaluator.InstallPythonAsync).Wait();
379379

380380
if (!PythonEngine.IsInitialized)
381381
{

DSPythonNet3/DSPythonNet3Evaluator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Diagnostics;
44
using System.Reflection;
5+
using System.Runtime.Loader;
56
using Autodesk.DesignScript.Runtime;
67
using DSPythonNet3.Encoders;
78
using Dynamo.Events;
@@ -246,7 +247,7 @@ public override object Evaluate(
246247
return null;
247248
}
248249

249-
InstallPythonAsync().Wait();
250+
Task.Run(InstallPythonAsync).Wait();
250251
if (!PythonEngine.IsInitialized)
251252
{
252253
PythonEngine.Initialize();
@@ -346,6 +347,13 @@ internal static async Task InstallPythonAsync()
346347
}
347348

348349
await Python.Included.Installer.SetupPython();
350+
351+
Assembly assembly = Assembly.GetAssembly(typeof(DSPythonNet3Evaluator)) ?? throw new Exception("Can't get assembly.");
352+
AssemblyLoadContext context = AssemblyLoadContext.GetLoadContext(assembly) ?? throw new Exception("Can't get assembly context.");
353+
354+
Assembly wheelsAssembly = context.LoadFromAssemblyPath(Path.Join(Path.GetDirectoryName(assembly.Location), "DSPythonNet3Wheels.dll"));
355+
await Task.WhenAll(wheelsAssembly.GetManifestResourceNames().Where(x => x.Contains(".whl")).Select(wheel => Python.Included.Installer.InstallWheel(wheelsAssembly, wheel))).ConfigureAwait(false);
356+
349357
isPythonInstalled = true;
350358
}
351359
catch (Exception e)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputPath>$(BuildOutput)extra\</OutputPath>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<None Remove="Resources\*.whl" />
8+
<EmbeddedResource Include="Resources\*.whl" />
9+
</ItemGroup>
10+
11+
<Target Name="UpdateWheels">
12+
<RemoveDir Directories="Resources" />
13+
<MakeDir Directories="Resources" />
14+
<Exec Command="pip download --only-binary :all: --platform win_amd64 --implementation cp --python-version 3.11 --dest Resources --no-cache -r requirements.txt" />
15+
</Target>
16+
</Project>
Binary file not shown.
8.13 KB
Binary file not shown.
17.6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)