Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/AngouriMath/extension.dib
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ if (FindType("Numbers", "PeterO.Numbers.ERational") is { } rational)
RegisterLatex(rational, o => $@"\frac{{{rational.GetProperty("Numerator").GetValue(o)}}}{{{rational.GetProperty("Denominator").GetValue(o)}}}");

"Extensions for LaTeX loaded!"

#!csharp

// The namespaces a C# notebook writes without opening: `AngouriMath` and `AngouriMath.Extensions` are opened only
// when the cell above was compiled against AngouriMath, which is when this kernel loaded the package rather than
// another kernel of the same notebook, and the opening is deferred to this kernel's next submission.
static object PropertyOf(object o, string name) => o?.GetType().GetProperty(name)?.GetValue(o);

if (PropertyOf(PropertyOf(PropertyOf(Microsoft.DotNet.Interactive.Kernel.Current, "ScriptState"), "Script"), "Options") is { } options
&& PropertyOf(options, "MetadataReferences") is System.Collections.IEnumerable references
&& references.Cast<object>().Any(r => PropertyOf(r, "Display") is string path && System.IO.Path.GetFileName(path) == "AngouriMath.dll"))
Microsoft.DotNet.Interactive.Kernel.Current.DeferCommand(
new Microsoft.DotNet.Interactive.Commands.SubmitCode("using AngouriMath;\nusing AngouriMath.Extensions;"));
28 changes: 28 additions & 0 deletions Sources/Tests/InteractiveWrapperUnitTests/HostCompatibility.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

module AngouriMath.Interactive.Tests.HostCompatibility

open System.Reflection
open Xunit

let private fsharpCoreReferencedBy (assembly : Assembly) =
assembly.GetReferencedAssemblies()
|> Array.find (fun name -> name.Name = "FSharp.Core")
|> fun name -> name.Version

// A notebook host runs its own FSharp.Core and cannot give a package a newer one. Built against
// FSharp.Core 10.1 under a host carrying 10.0, the kernel extension hung a C# kernel as it loaded,
// and an F# kernel failed its first call into the wrappers unless the extension had loaded first:
// https://github.com/asc-community/AngouriMath/issues/2108
[<Fact>]
let ``The wrappers ask for no newer FSharp.Core than the F# kernel is built against`` () =
let kernel = fsharpCoreReferencedBy typeof<Microsoft.DotNet.Interactive.FSharp.FSharpKernel>.Assembly
for wrapper in [ typeof<AngouriMath.InteractiveExtension.KernelExtension>.Assembly
Assembly.Load "AngouriMath.FSharp" ] do
let asked = fsharpCoreReferencedBy wrapper
Assert.True(asked <= kernel, $"{wrapper.GetName().Name} asks for FSharp.Core {asked}, the F# kernel is built against {kernel}")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<Compile Include="AggressiveOperators.fs" />
<Compile Include="HtmlOutput.fs" />
<Compile Include="HostCompatibility.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions Sources/Wrappers/AngouriMath.FSharp/AngouriMath.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<Compile Include="Matrices.fs" />
</ItemGroup>

<ItemGroup>
<!-- A notebook host runs its own FSharp.Core, so the wrappers ask for the lowest one they build
against rather than the SDK's: 8.0.403 is Plotly.NET's floor, and 10.1 hung a C# kernel under a
host carrying 10.0. https://github.com/asc-community/AngouriMath/issues/2108 -->
<PackageReference Update="FSharp.Core" Version="8.0.403" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\AngouriMath\AngouriMath.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.23611.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.23611.1" />
<PackageReference Include="Plotly.NET" Version="6.0.0-preview.1" />
<!-- A notebook host runs its own FSharp.Core, so the wrappers ask for the lowest one they build
against rather than the SDK's: 8.0.403 is Plotly.NET's floor, and 10.1 hung a C# kernel under a
host carrying 10.0. https://github.com/asc-community/AngouriMath/issues/2108 -->
<PackageReference Update="FSharp.Core" Version="8.0.403" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading