forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
252 lines (226 loc) · 10.8 KB
/
Program.cs
File metadata and controls
252 lines (226 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using HtmlAgilityPack;
namespace ReleaseBot
{
class Program
{
private const string V = "1.34"; // <--- numpy.net version!
private const string PythonNetVersion = "3.0.1";
private const string PythonVersion = "3.11"; // relevant only for Numpy with included binaries
private const string NumpyVersion = "1.23.5";
private const string ProjectPath = "../../../Numpy";
private const string ProjectName = "Numpy.csproj";
private const string ProjectPath2 = "../../../Numpy.Bare";
private const string ProjectName2 = "Numpy.Bare.csproj";
private const string Description = "C# bindings for NumPy on {0} - a fundamental library for scientific computing, machine learning and AI. Does require Python {1} with NumPy {2} installed!";
private const string Tags = "Data science, Machine Learning, ML, AI, Scientific Computing, NumPy, Linear Algebra, FFT, SVD, BLAS, Vector, Matrix, Python";
static void Main(string[] args)
{
// ==> Numpy
ProcessNumpy();
// ==> Numpy Bare
// TODO: release numpy bare for the new Pythonnet 3.0.0
//// first delete old packages as to not upload them again
//foreach (var nuget in Directory.GetFiles(Path.Combine(ProjectPath2, "bin", "Release"), "*.nupkg"))
//{
// File.Delete(nuget);
//}
//var specs = new ReleaseSpec[]
//{
// // linux
// new ReleaseSpec() { CPythonVersion = "2.7", Platform="Linux", },
// new ReleaseSpec() { CPythonVersion = "3.5", Platform="Linux", },
// new ReleaseSpec() { CPythonVersion = "3.6", Platform="Linux", },
// new ReleaseSpec() { CPythonVersion = "3.8", Platform="Linux", },
// new ReleaseSpec() { CPythonVersion = "3.7", Platform="Linux", },
// // mac
// new ReleaseSpec() { CPythonVersion = "2.7", Platform="OSX", },
// new ReleaseSpec() { CPythonVersion = "3.5", Platform="OSX", },
// new ReleaseSpec() { CPythonVersion = "3.6", Platform="OSX", },
// new ReleaseSpec() { CPythonVersion = "3.8", Platform="OSX", },
// new ReleaseSpec() { CPythonVersion = "3.7", Platform="OSX", },
// // win
// new ReleaseSpec() { CPythonVersion = "2.7", Platform="Win64", },
// new ReleaseSpec() { CPythonVersion = "3.5", Platform="Win64", },
// new ReleaseSpec() { CPythonVersion = "3.6", Platform="Win64", },
// new ReleaseSpec() { CPythonVersion = "3.8", Platform="Win64", },
// new ReleaseSpec() { CPythonVersion = "3.7", Platform="Win64", },
//};
//foreach (var spec in specs)
//{
// spec.Version = $"{spec.CPythonVersion}.{V}";
// spec.PythonNetVersion = $"{PythonNetVersion}";
// spec.NumpyVersion = NumpyVersion;
// spec.Description = string.Format(Description, spec.Platform, spec.CPythonVersion, spec.NumpyVersion);
// spec.PackageTags = Tags;
// spec.RelativeProjectPath = ProjectPath2;
// spec.ProjectName = ProjectName2;
// var py = spec.CPythonVersion.Replace(".", "");
// switch (spec.Platform)
// {
// case "Linux":
// spec.PackageId = "Numpy.Bare.Mono";
// spec.PythonNet = $"pythonnet_netstandard_py{py}_linux";
// break;
// case "OSX":
// spec.PackageId = "Numpy.Bare.OSX";
// spec.PythonNet = $"pythonnet_netstandard_py{py}_osx";
// break;
// case "Win64":
// spec.PackageId = "Numpy.Bare";
// spec.PythonNet = $"pythonnet_netstandard_py{py}_win";
// break;
// }
// spec.Process();
//}
var key = File.ReadAllText("../../nuget.key").Trim();
foreach (var nuget in Directory.GetFiles(Path.Combine(ProjectPath2, "bin", "Release"), "*.nupkg"))
{
Console.WriteLine("Push " + nuget);
var arg = $"push -Source https://api.nuget.org/v3/index.json -ApiKey {key} {nuget}";
var p = new Process() { StartInfo = new ProcessStartInfo("nuget.exe", arg) { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false } };
p.OutputDataReceived += (x, data) => Console.WriteLine(data.Data);
p.ErrorDataReceived += (x, data) => Console.WriteLine("Error: " + data.Data);
p.Start();
p.WaitForExit();
Console.WriteLine("... pushed");
}
Thread.Sleep(3000);
}
private static void ProcessNumpy()
{
// first delete old packages as to not upload them again
foreach (var nuget in Directory.GetFiles(Path.Combine(ProjectPath, "bin", "Release"), "*.nupkg"))
{
File.Delete(nuget);
}
var spec = new ReleaseSpec()
{
Version = $"{PythonVersion}.{V}",
ProjectName = ProjectName,
RelativeProjectPath = ProjectPath,
PackageId = "Numpy",
Description = @"C# bindings for NumPy - a fundamental library for scientific computing, machine learning and AI. Does not require a local Python installation!",
PackageTags = "Data science, Machine Learning, ML, AI, Scientific Computing, NumPy, Linear Algebra, FFT, SVD, Matrix, Python",
UsePythonIncluded = true,
};
spec.Process();
// nuget
var key = File.ReadAllText("../../nuget.key").Trim();
foreach (var nuget in Directory.GetFiles(Path.Combine(ProjectPath, "bin", "Release"), "*.nupkg"))
{
Console.WriteLine("Push " + nuget);
var arg = $"push -Source https://api.nuget.org/v3/index.json -ApiKey {key} {nuget}";
var p = new Process() { StartInfo = new ProcessStartInfo("nuget.exe", arg) { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false } };
p.OutputDataReceived += (x, data) => Console.WriteLine(data.Data);
p.ErrorDataReceived += (x, data) => Console.WriteLine("Error: " + data.Data);
p.Start();
p.WaitForExit();
Console.WriteLine("... pushed");
}
}
}
public class ReleaseSpec
{
/// <summary>
/// The assembly / nuget package version
/// </summary>
public string Version;
public string CPythonVersion;
public string Platform;
/// <summary>
/// Project description
/// </summary>
public string Description;
/// <summary>
/// Project description
/// </summary>
public string PackageTags;
/// <summary>
/// Nuget package id
/// </summary>
public string PackageId;
/// <summary>
/// PythonNet package name
/// </summary>
public string PythonNet;
/// <summary>
/// PythonNet Version
/// </summary>
public string PythonNetVersion;
/// <summary>
/// Name of the csproj file
/// </summary>
public string ProjectName;
/// <summary>
/// Path to the csproj file, relative to the execution directory of ReleaseBot
/// </summary>
public string RelativeProjectPath;
public string FullProjectPath => Path.Combine(RelativeProjectPath, ProjectName);
/// <summary>
/// Uses Python.Included
/// </summary>
public bool UsePythonIncluded { get; set; }
// Numpy Version
public string NumpyVersion { get; set; }
public void Process()
{
if (!File.Exists(FullProjectPath))
throw new InvalidOperationException("Project not found at: " + FullProjectPath);
// modify csproj
var doc = new HtmlDocument() { OptionOutputOriginalCase = true, OptionWriteEmptyNodes = true };
doc.Load(FullProjectPath);
var group0 = doc.DocumentNode.Descendants("propertygroup").FirstOrDefault();
SetInnerText(group0.Element("version"), Version);
Console.WriteLine("Version: " + group0.Element("version").InnerText);
SetInnerText(group0.Element("description"), Description);
Console.WriteLine("Description: " + group0.Element("description").InnerText);
if (!UsePythonIncluded)
{
SetInnerText(group0.Element("packageid"), PackageId);
var group1 = doc.DocumentNode.Descendants("itemgroup").FirstOrDefault(g => g.Element("packagereference") != null);
var reference = group1.Descendants("packagereference").ToArray()[1];
reference.Attributes["Include"].Value = PythonNet;
reference.Attributes["Version"].Value = PythonNetVersion;
}
doc.Save(FullProjectPath);
// now build in release mode
RestoreNugetDependencies();
Build();
}
private void RestoreNugetDependencies()
{
Console.WriteLine("Fetch Nugets " + Description);
var p = new Process()
{
StartInfo = new ProcessStartInfo("dotnet", "restore")
{ WorkingDirectory = Path.GetFullPath(RelativeProjectPath) }
};
p.Start();
p.WaitForExit();
}
private void Build()
{
Console.WriteLine("Build " + Description);
var p = new Process()
{
StartInfo = new ProcessStartInfo("dotnet", "build -c Release")
{ WorkingDirectory = Path.GetFullPath(RelativeProjectPath) }
};
p.Start();
p.WaitForExit();
}
private void SetInnerText(HtmlNode node, string text)
{
node.ReplaceChild(HtmlTextNode.CreateNode(text), node.FirstChild);
}
}
}