From 02bd54c12a0873469bcbd1be90a12476bae44442 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Wed, 6 Dec 2023 19:23:11 -0500 Subject: [PATCH 1/5] Create dotnet-desktop.yml --- .github/workflows/dotnet-desktop.yml | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/dotnet-desktop.yml diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml new file mode 100644 index 0000000..52ee6ea --- /dev/null +++ b/.github/workflows/dotnet-desktop.yml @@ -0,0 +1,33 @@ +# Build DSIronPython package using msbuild +name: DSIronPython-VS2022Build +on: [push, pull_request] +jobs: + build: + runs-on: windows-2022 + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + path: DSIronPython + repository: DynamoDS/DSIronPython + - name: Setup nuget + uses: nuget/setup-nuget@v1.2 + - name: Setup msbuild + uses: microsoft/setup-msbuild@v1.3 + - name: Nuget Restore DSIronPython solution + run: nuget restore ${{ github.workspace }}\DSIronPython\DSIronPython.sln + - name: Build DSIronPython with MSBuild + run: | + Write-Output "***Continue with the build, Good luck developer!***" + msbuild ${{ github.workspace }}\DSIronPython\DSIronPython.sln + - name: Look for package + run: | + Write-Output "***Locating iron python package!***" + if (Test-Path -Path "${{ github.workspace }}\DSIronPython\package_output\DSIronPython\bin\DSIronPython.dll") { + Write-Output "python node dll exists!" + } else { + Write-Error "python node dll was not found!" + } + - name: Test with the dotnet CLI + run: dotnet test + From a06a017d096eb0503f515afea1ed0914ded281a1 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Wed, 6 Dec 2023 19:33:00 -0500 Subject: [PATCH 2/5] Update dotnet-desktop.yml --- .github/workflows/dotnet-desktop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml index 52ee6ea..e1f3075 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/dotnet-desktop.yml @@ -29,5 +29,5 @@ jobs: Write-Error "python node dll was not found!" } - name: Test with the dotnet CLI - run: dotnet test + run: dotnet test ${{ github.workspace }}\DSIronPython From e5ad676ef30c15e08f61992beff3124a1dc94288 Mon Sep 17 00:00:00 2001 From: Aabishkar KC Date: Mon, 11 Dec 2023 09:48:53 -0500 Subject: [PATCH 3/5] Update workflow (#2) - add workflow_dispatch event to manually trigger workflow - add step to publish test reporter - add step to upload artifact --- .../{dotnet-desktop.yml => build.yml} | 22 ++++++++++++---- .github/workflows/publish_test_report.yml | 25 +++++++++++++++++++ .gitignore | 3 ++- 3 files changed, 44 insertions(+), 6 deletions(-) rename .github/workflows/{dotnet-desktop.yml => build.yml} (58%) create mode 100644 .github/workflows/publish_test_report.yml diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/build.yml similarity index 58% rename from .github/workflows/dotnet-desktop.yml rename to .github/workflows/build.yml index e1f3075..11eb86b 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ # Build DSIronPython package using msbuild name: DSIronPython-VS2022Build -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build: runs-on: windows-2022 @@ -13,7 +13,7 @@ jobs: - name: Setup nuget uses: nuget/setup-nuget@v1.2 - name: Setup msbuild - uses: microsoft/setup-msbuild@v1.3 + uses: microsoft/setup-msbuild@v1.3.1 - name: Nuget Restore DSIronPython solution run: nuget restore ${{ github.workspace }}\DSIronPython\DSIronPython.sln - name: Build DSIronPython with MSBuild @@ -28,6 +28,18 @@ jobs: } else { Write-Error "python node dll was not found!" } - - name: Test with the dotnet CLI - run: dotnet test ${{ github.workspace }}\DSIronPython - + - name: Run test with the dotnet CLI + run: | + dotnet test ${{ github.workspace }}\DSIronPython --logger "trx;LogFileName=results.trx" --results-directory ${{ github.workspace }}\DSIronPython\TestResults + - name: Upload build artifact + uses: actions/upload-artifact@v3.1.3 + with: + name: DSIronPython + path: ${{ github.workspace }}\DSIronPython\package_output + retention-days: 7 + - name: Upload test artifact + uses: actions/upload-artifact@v3.1.3 + with: + name: TestResults + path: ${{ github.workspace }}\DSIronPython\TestResults + retention-days: 1 diff --git a/.github/workflows/publish_test_report.yml b/.github/workflows/publish_test_report.yml new file mode 100644 index 0000000..1cb9adb --- /dev/null +++ b/.github/workflows/publish_test_report.yml @@ -0,0 +1,25 @@ +name: Publish Test Report + +on: + workflow_run: + workflows: + - DSIronPython-VS2022Build + types: + - completed + +permissions: + contents: read + actions: read + checks: write + +jobs: + publish_test_report: + name: Publish Test Report + runs-on: ubuntu-latest + steps: + - uses: dorny/test-reporter@v1.7.0 + with: + artifact: TestResults + name: Test Results + path: '*.trx' + reporter: dotnet-trx diff --git a/.gitignore b/.gitignore index 9491a2f..d4d380b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ bld/ [Oo]ut/ [Ll]og/ [Ll]ogs/ +package_output/ # Visual Studio 2015/2017 cache/options directory .vs/ @@ -360,4 +361,4 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd From 53e979c1f06f745e7fb43594bd7f4f525ed20f70 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Tue, 12 Dec 2023 12:19:04 -0500 Subject: [PATCH 4/5] appdomain for deps (#1) --- DSIronPython/DSIronPython.csproj | 6 +- IronPythonExtension/IronPythonExtension.cs | 55 ++++++++++++------- .../IronPythonExtension.csproj | 4 +- ...ronPythonExtension_ExtensionDefinition.xml | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/DSIronPython/DSIronPython.csproj b/DSIronPython/DSIronPython.csproj index d2cb92a..05c7e7f 100644 --- a/DSIronPython/DSIronPython.csproj +++ b/DSIronPython/DSIronPython.csproj @@ -3,7 +3,7 @@ - $(SolutionDir)\package_output\DSIronPython\bin\ + $(SolutionDir)\package_output\DSIronPython\extra\ {9EEF4F42-6B3B-4358-9A8A-C2701539A822} Library Properties @@ -29,7 +29,7 @@ - + diff --git a/IronPythonExtension/IronPythonExtension.cs b/IronPythonExtension/IronPythonExtension.cs index 38babc3..89be644 100644 --- a/IronPythonExtension/IronPythonExtension.cs +++ b/IronPythonExtension/IronPythonExtension.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Reflection; +using System.Runtime.Loader; using Dynamo.Extensions; using Dynamo.Logging; using Dynamo.PythonServices; @@ -61,26 +62,9 @@ public void Startup(StartupParams sp) /// public void Ready(ReadyParams sp) { - // Searches for DSIronPython engine binary in same folder with extension itself - var targetDir = Path.GetDirectoryName(Assembly.GetAssembly(typeof(IronPythonExtension)).Location); - var libraryLoader = sp.StartupParams.LibraryLoader; - Assembly pythonEvaluatorLib = null; - try - { - pythonEvaluatorLib = Assembly.LoadFrom(Path.Combine(targetDir, PythonEvaluatorAssembly + ".dll")); - } - catch (Exception ex) - { - // Most likely the IronPython engine is excluded in this case - // but logging the exception message in case for diagnose - OnMessageLogged(LogMessage.Info(ex.Message)); - return; - } - // Import IronPython Engine into VM, so Python node using IronPython engine could evaluate correctly - if (pythonEvaluatorLib != null) - { - libraryLoader.LoadNodeLibrary(pythonEvaluatorLib); - } + var extraPath = Path.Combine(new FileInfo(Assembly.GetAssembly(typeof(IronPythonExtension)).Location).Directory.Parent.FullName, "extra"); + var alc = new IsolatedPythoContext(Path.Combine(extraPath,"DSIronPython.dll")); + alc.LoadFromAssemblyName(new AssemblyName("DSIronPython")); } /// @@ -91,4 +75,35 @@ public void Shutdown() // Do nothing for now } } + internal class IsolatedPythoContext : AssemblyLoadContext + { + private AssemblyDependencyResolver resolver; + + public IsolatedPythoContext(string libPath) + { + resolver = new AssemblyDependencyResolver(libPath); + } + + protected override Assembly Load(AssemblyName assemblyName) + { + string assemblyPath = resolver.ResolveAssemblyToPath(assemblyName); + if (assemblyPath != null) + { + return LoadFromAssemblyPath(assemblyPath); + } + + return null; + } + + protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) + { + string libraryPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName); + if (libraryPath != null) + { + return LoadUnmanagedDllFromPath(libraryPath); + } + + return IntPtr.Zero; + } + } } diff --git a/IronPythonExtension/IronPythonExtension.csproj b/IronPythonExtension/IronPythonExtension.csproj index f03e34e..41e7a85 100644 --- a/IronPythonExtension/IronPythonExtension.csproj +++ b/IronPythonExtension/IronPythonExtension.csproj @@ -3,7 +3,7 @@ - $(SolutionDir)\package_output\DSIronPython\bin\ + $(SolutionDir)\package_output\DSIronPython\extra\ {182FCA4E-B6EF-451F-9EC4-7BF2C622F4F7} Library Properties @@ -21,6 +21,6 @@ - + \ No newline at end of file diff --git a/IronPythonExtension/IronPythonExtension_ExtensionDefinition.xml b/IronPythonExtension/IronPythonExtension_ExtensionDefinition.xml index a149d07..1ab1acc 100644 --- a/IronPythonExtension/IronPythonExtension_ExtensionDefinition.xml +++ b/IronPythonExtension/IronPythonExtension_ExtensionDefinition.xml @@ -1,4 +1,4 @@ - ..\bin\IronPythonExtension.dll + IronPythonExtension.dll IronPythonExtension.IronPythonExtension \ No newline at end of file From d8dc59b455bb1f85c579dd082d5980879d497860 Mon Sep 17 00:00:00 2001 From: Michael Kirschner Date: Mon, 18 Dec 2023 19:48:26 -0500 Subject: [PATCH 5/5] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11eb86b..f38cb85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: - name: Look for package run: | Write-Output "***Locating iron python package!***" - if (Test-Path -Path "${{ github.workspace }}\DSIronPython\package_output\DSIronPython\bin\DSIronPython.dll") { + if (Test-Path -Path "${{ github.workspace }}\DSIronPython\package_output\DSIronPython\extra\DSIronPython.dll") { Write-Output "python node dll exists!" } else { Write-Error "python node dll was not found!"