Skip to content

Commit

Permalink
fix(JobPathArgument): improve ToUserFriendlyString()
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Nov 10, 2023
1 parent 53f8095 commit 43edf46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/PollinationSDK/ManuallyAdded/Model/JobPathArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,26 @@ public string CloudProjectSlug()
return null;
}

public string ToUserFriendlyString()
public string ToUserFriendlyString(bool withProjectSlug)
{
var uploaded = this.IsAssetUploaded();
var hint = uploaded ? "CLOUD" : "PATH";

var p = (this.Source.Obj as ProjectFolder)?.Path;
p = uploaded ? p : System.IO.Path.GetFileName(p);
var hint = "PATH";
if (uploaded)
{
hint = "CLOUD";
if (withProjectSlug)
{
var slug = this.CloudProjectSlug();
hint = string.IsNullOrEmpty(slug) ? hint : $"{hint}:{slug}";
}
}
else
{
p = System.IO.Path.GetFileName(p);
}

return $"#{this.Name}:${hint}/{p}";

}
Expand Down
2 changes: 1 addition & 1 deletion src/PollinationSDK/Wrapper/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<CloudJob> RunOnCloudAsync(Project project, Action<string> prog
{

// check if all cloud path artifacts are within the same project
var invalidCloudAssets = job.Arguments.SelectMany(_ => _.OfType<JobPathArgument>()).Where(_ => _.IsAssetUploaded() && _.CloudProjectSlug() != project.Slug).Select(_=> $"{_.ToUserFriendlyString()}@{_.CloudProjectSlug()}").Distinct();
var invalidCloudAssets = job.Arguments.SelectMany(_ => _.OfType<JobPathArgument>()).Where(_ => _.IsAssetUploaded() && _.CloudProjectSlug() != project.Slug).Select(_=> $"{_.ToUserFriendlyString(true)}").Distinct();
if (invalidCloudAssets.Any())
{
var error = $"Following cloud assets cannot be uploaded to project {project.Slug}:\n\n{string.Join(Environment.NewLine, invalidCloudAssets)}";
Expand Down
2 changes: 1 addition & 1 deletion src/PollinationSDK/Wrapper/LocalRunArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LocalRunArguments
public LocalRunArguments(List<AnyOf<JobArgument, JobPathArgument>> arguments)
{
// check if there are any cloud path artifacts
var invalidCloudAssets = arguments.OfType<JobPathArgument>().Where(_ => _.IsAssetUploaded()).Select(_ => $"{_.ToUserFriendlyString()}@{_.CloudProjectSlug()}").Distinct();
var invalidCloudAssets = arguments.OfType<JobPathArgument>().Where(_ => _.IsAssetUploaded()).Select(_ => $"{_.ToUserFriendlyString(true)}").Distinct();
if (invalidCloudAssets.Any())
{
var error = $"Cannot run a local study with cloud assets:\n\n{string.Join(Environment.NewLine, invalidCloudAssets)}";
Expand Down

0 comments on commit 43edf46

Please sign in to comment.