Skip to content

Commit

Permalink
rename useResultCache to forceRestore
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed Sep 28, 2023
1 parent be05bac commit 80c5c3d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Microsoft.DotNet.Interactive.PackageManagement
public static class KernelExtensions
public static T UseNugetDirective<T>(Func<T,System.Collections.Generic.IReadOnlyList<Microsoft.DotNet.Interactive.ResolvedPackageReference>,System.Threading.Tasks.Task> onResolvePackageReferences, System.Boolean useResultsCache = True)
public static T UseNugetDirective<T>(Func<T,System.Collections.Generic.IReadOnlyList<Microsoft.DotNet.Interactive.ResolvedPackageReference>,System.Threading.Tasks.Task> onResolvePackageReferences, System.Boolean forceRestore = False)
public class PackageRestoreContext, System.IDisposable
.ctor(System.Boolean useResultsCache = True)
.ctor(System.Boolean forceRestore = False)
public System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.PackageReference> RequestedPackageReferences { get;}
public System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.ResolvedPackageReference> ResolvedPackageReferences { get;}
public System.Collections.Generic.IEnumerable<System.String> RestoreSources { get;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace Microsoft.DotNet.Interactive.PackageManagement;

public static class KernelExtensions
{
public static T UseNugetDirective<T>(this T kernel, Func<T, IReadOnlyList<ResolvedPackageReference>, Task> onResolvePackageReferences, bool useResultsCache = true)
public static T UseNugetDirective<T>(this T kernel, Func<T, IReadOnlyList<ResolvedPackageReference>, Task> onResolvePackageReferences, bool forceRestore = false)
where T : Kernel
{
var lazyPackageRestoreContext = new Lazy<PackageRestoreContext>(() =>
{
var packageRestoreContext = new PackageRestoreContext(useResultsCache);
var packageRestoreContext = new PackageRestoreContext(forceRestore);
kernel.RegisterForDisposal(packageRestoreContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class PackageRestoreContext : IDisposable

private readonly DependencyProvider _dependencyProvider;

public PackageRestoreContext(bool useResultsCache = true)
public PackageRestoreContext(bool forceRestore = false)
{
_dependencyProvider = new DependencyProvider(AssemblyProbingPaths, NativeProbingRoots, useResultsCache: useResultsCache);
_dependencyProvider = new DependencyProvider(AssemblyProbingPaths, NativeProbingRoots, useResultsCache: !forceRestore);
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public PackageRestoreContextTests(ITestOutputHelper output) : base(output)
[Fact]
public async Task Returns_new_references_if_they_are_added()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
var added = restoreContext.GetOrAddPackageReference("FluentAssertions", "5.7.0");
added.Should().NotBeNull();

Expand All @@ -43,7 +43,7 @@ public async Task Returns_new_references_if_they_are_added()
[Fact]
public async Task Returns_references_when_package_version_is_not_specified()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
var added = restoreContext.GetOrAddPackageReference("NewtonSoft.Json");
added.Should().NotBeNull();

Expand All @@ -64,7 +64,7 @@ public async Task Returns_references_when_package_version_is_not_specified()
[Fact]
public async Task Returns_failure_if_package_installation_fails()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
var added = restoreContext.GetOrAddPackageReference("not-a-real-package-definitely-not", "5.7.0");
added.Should().NotBeNull();

Expand All @@ -76,7 +76,7 @@ public async Task Returns_failure_if_package_installation_fails()
[Fact]
public async Task Returns_failure_if_adding_package_twice_at_different_versions()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
var added = restoreContext.GetOrAddPackageReference("another-not-a-real-package-definitely-not", "5.7.0");
added.Should().NotBeNull();

Expand All @@ -92,7 +92,7 @@ public async Task Returns_failure_if_adding_package_twice_at_different_versions(
public async Task A_failing_package_restore_does_not_cause_future_resolves_to_fail()

{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
var added = restoreContext.GetOrAddPackageReference("FluentAssertions", "5.7.0");
added.Should().NotBeNull();

Expand All @@ -115,7 +115,7 @@ public async Task A_failing_package_restore_does_not_cause_future_resolves_to_fa
[Fact]
public async Task Invalid_package_restores_are_not_remembered()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);

// This package does not exist
restoreContext.GetOrAddPackageReference("NonExistentNugetPackage", "99.99.99-NoReallyIDontExist");
Expand All @@ -135,7 +135,7 @@ public async Task Invalid_package_restores_are_not_remembered()
[Fact]
public async Task Can_get_path_to_nuget_packaged_assembly()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("fluentAssertions", "5.7.0");

await restoreContext.RestoreAsync();
Expand Down Expand Up @@ -163,7 +163,7 @@ public async Task Can_get_path_to_nuget_packaged_assembly()
[Fact]
public async Task Can_get_path_to_nuget_package_root()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("fluentAssertions", "5.7.0");

await restoreContext.RestoreAsync();
Expand All @@ -183,7 +183,7 @@ public async Task Can_get_path_to_nuget_package_root()
[Fact]
public async Task Can_get_path_to_nuget_package_when_multiple_packages_are_added()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("fluentAssertions", "5.7.0");
restoreContext.GetOrAddPackageReference("htmlagilitypack", "1.11.12");

Expand All @@ -206,7 +206,7 @@ public async Task Can_get_path_to_nuget_package_when_multiple_packages_are_added
[Fact]
public async Task Fail_if_restore_source_has_an_invalid_uri()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.TryAddRestoreSource("https://completelyFakerestore Source");
var result = await restoreContext.RestoreAsync();
result.Succeeded.Should().BeFalse();
Expand All @@ -215,7 +215,7 @@ public async Task Fail_if_restore_source_has_an_invalid_uri()
[Fact]
public async Task Can_add_to_list_of_added_sources()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);

restoreContext.TryAddRestoreSource("https://completelyFakerestoreSource");
await restoreContext.RestoreAsync();
Expand All @@ -226,7 +226,7 @@ public async Task Can_add_to_list_of_added_sources()
[Fact]
public async Task Can_add_same_source_to_list_of_added_sources_without_error()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);

var savedRestoreSources = restoreContext.RestoreSources.ToArray();
restoreContext.TryAddRestoreSource("https://completelyFakerestoreSource");
Expand All @@ -240,7 +240,7 @@ public async Task Can_add_same_source_to_list_of_added_sources_without_error()
[Fact]
public async Task Allows_duplicate_package_specifications()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.9");
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.9");

Expand All @@ -255,7 +255,7 @@ public async Task Allows_duplicate_package_specifications()
// Question: should it not throw, or is ignore sufficient
public async Task Ignores_subsequent_package_specifications_with_different_higher_version()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.0");
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.9");

Expand All @@ -269,7 +269,7 @@ public async Task Ignores_subsequent_package_specifications_with_different_highe
[Fact]
public async Task Disallows_package_specifications_with_different_lower_version()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.9");
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.0");
await restoreContext.RestoreAsync();
Expand All @@ -282,7 +282,7 @@ public async Task Disallows_package_specifications_with_different_lower_version(
[Fact]
public async Task Disallows_package_specifications_with_different_lower_unspecified_version_first()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("NodaTime", "*");
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.0");

Expand All @@ -296,7 +296,7 @@ public async Task Disallows_package_specifications_with_different_lower_unspecif
[Fact]
public async Task Disallows_package_specifications_with_different_lower_unspecified_version_last()
{
using var restoreContext = new PackageRestoreContext(false);
using var restoreContext = new PackageRestoreContext(true);
restoreContext.GetOrAddPackageReference("NodaTime", "3.1.0");
restoreContext.GetOrAddPackageReference("NodaTime", "*");

Expand Down
8 changes: 4 additions & 4 deletions src/dotnet-interactive/KernelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ namespace Microsoft.DotNet.Interactive.App;

public static class KernelExtensions
{
public static CSharpKernel UseNugetDirective(this CSharpKernel kernel, bool useResultsCache = true)
public static CSharpKernel UseNugetDirective(this CSharpKernel kernel, bool forceRestore = false)
{
kernel.UseNugetDirective((k, resolvedPackageReference) =>
{
k.AddAssemblyReferences(resolvedPackageReference
.SelectMany(r => r.AssemblyPaths));
return Task.CompletedTask;
}, useResultsCache);
}, forceRestore);

return kernel;
}

public static FSharpKernel UseNugetDirective(this FSharpKernel kernel, bool useResultsCache = true)
public static FSharpKernel UseNugetDirective(this FSharpKernel kernel, bool forceRestore = false)
{
kernel.UseNugetDirective((k, resolvedPackageReference) =>
{
Expand All @@ -50,7 +50,7 @@ public static FSharpKernel UseNugetDirective(this FSharpKernel kernel, bool useR
k.AddAssemblyReferencesAndPackageRoots(resolvedAssemblies, packageRoots);
return Task.CompletedTask;
}, useResultsCache);
}, forceRestore);

return kernel;
}
Expand Down

0 comments on commit 80c5c3d

Please sign in to comment.