Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4505 Remove reliance on getting product version for model.zip/version.txt from FileVersionInfo and replace with using assembly custom attributes #4512

Merged
merged 1 commit into from Oct 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Microsoft.ML.Core/Data/Repository.cs
Expand Up @@ -7,6 +7,8 @@
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using Microsoft.ML.Internal.Utilities;
using Microsoft.ML.Runtime;

Expand Down Expand Up @@ -305,10 +307,10 @@ public static RepositoryWriter CreateNew(Stream stream, IExceptionContext ectx =
Contracts.CheckValueOrNull(ectx);
ectx.CheckValue(stream, nameof(stream));
var rep = new RepositoryWriter(stream, ectx, useFileSystem);
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(RepositoryWriter).Assembly.Location);

using (var ent = rep.CreateEntry(DirTrainingInfo, "Version.txt"))
using (var writer = Utils.OpenWriter(ent.Stream))
writer.WriteLine(versionInfo.ProductVersion);
writer.WriteLine(GetProductVersion());
return rep;
}

Expand Down Expand Up @@ -432,6 +434,24 @@ public void Commit()
Flush();
Dispose(true);
}

private static string GetProductVersion()
{
var assembly = typeof(RepositoryWriter).Assembly;

var assemblyInternationalVersionAttribute = assembly.CustomAttributes.FirstOrDefault(a =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assemblyInternationalVersionAttribute [](start = 16, length = 37)

Nit: Can this be renamed assemblyInformationalVersionAttribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sure

a.AttributeType == typeof(AssemblyInformationalVersionAttribute));

if (assemblyInternationalVersionAttribute == null)
{
throw new ApplicationException($"Cannot determine product version from assembly {assembly.FullName}.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw [](start = 16, length = 5)

Not sure we should throw in this case. Perhaps we should save 0.0.0.0 in this case? Or, alternatively, not include Version.txt in the model?

@eerhardt, @harishsk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only to keep consistency with how it was behaving before - I prefer the approach you have suggested though it should not fail because of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm @eerhardt @harishsk @yaeldekel and I'll make the change.

}

return assemblyInternationalVersionAttribute.ConstructorArguments
.First()
.Value
.ToString();
}
}

[BestFriend]
Expand Down