-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 64: [Python] VGRain as pyhton
- feat(Artifact): Start build python vgrain - feat(Artifact): Rename part file to simplify the names from "ArtifactResource" to simply "Artifact" - feat(Python): Implement communication message format between python artifact to democrite controller - feat(Remote): Start remote server between democrite cluster and client (python) - feat(Remote): Finalize external demaon managment and remote commandes - feat(Python): add log send back to democrite - fix(Remote): External code return result but user don't use it. - feat(Remote): Allow hot reload at runtime when debugger is attached and data source is directory - feat(Python): prepare python file to be distributed through PIP - feat(Artifact): Allow uid customization - feat(Sample): Add python sample Related work items: #270, #271
- Loading branch information
1 parent
766484c
commit acf8543
Showing
100 changed files
with
4,653 additions
and
1,469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Template used to compile the pkg number version | ||
|
||
parameters: | ||
- name: ReleasePublic | ||
displayName: Release Public | ||
type: boolean | ||
default: false | ||
values: | ||
- true | ||
- false | ||
|
||
variables: | ||
- group: democrite-frameworks-variables | ||
|
||
- name: PkgVersionMajor | ||
value: $(PackageVersionMajor) | ||
|
||
- name: PkgVersionMinor | ||
value: $(PackageVersionMinor) | ||
|
||
- name: PkgVersionPatch | ||
value: $(PackageVersionPatch) | ||
|
||
- ${{ if eq(parameters.ReleasePublic, true) }}: | ||
- name: PkgVersionBuild | ||
value: "" | ||
|
||
- name: PkgVersionPrerelease | ||
value: "" | ||
|
||
- ${{ if ne(parameters.ReleasePublic, true) }}: | ||
|
||
- name: PkgVersionBuild | ||
value: ".$(Build.BuildId)" | ||
|
||
- name: PkgVersionPrerelease | ||
value: "-prerelease" | ||
|
||
- name: FinalPkgVersionNumber | ||
value: ${{ variables.PkgVersionMajor }}.${{ variables.PkgVersionMinor }}.${{ variables.PkgVersionPatch }}${{ variables.PkgVersionBuild }} | ||
|
||
- name : FinalPkgVersion | ||
value: ${{ variables.FinalPkgVersionNumber }}${{ variables.PkgVersionPrerelease }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# process -> https://packaging.python.org/en/latest/tutorials/packaging-projects/ | ||
|
||
trigger: none | ||
|
||
pool: | ||
vmImage: ubuntu-latest | ||
|
||
parameters: | ||
- name: ReleasePublic | ||
displayName: Release Public | ||
type: boolean | ||
default: false | ||
values: | ||
- true | ||
- false | ||
|
||
variables: | ||
- template: Templates/azure-pipeline-pkg-version.yml | ||
|
||
- name: localReleasePublic | ||
value: $(ReleasePublic) | ||
|
||
- ${{ if eq(parameters.ReleasePublic, true) }}: | ||
- group: pip-repository-variables-release | ||
|
||
- ${{ if ne(parameters.ReleasePublic, true) }}: | ||
- group: pip-repository-variables-test | ||
|
||
- name: repoAlias | ||
${{ if eq(parameters.ReleasePublic, true) }}: | ||
value: pypi | ||
${{ else }}: | ||
value: testpypi | ||
|
||
|
||
|
||
- name: PythonPkgFolder | ||
value: "./src/Extensions/Dist/Python/" | ||
|
||
steps: | ||
|
||
- task: UsePythonVersion@0 | ||
inputs: | ||
versionSpec: '3.x' | ||
displayName: 'Use Python 3.x' | ||
|
||
- script: python -m pip install --upgrade pip | ||
displayName: 'Install pip & dependencies' | ||
|
||
- script: python -m pip install --upgrade build | ||
displayName: 'Python package builder' | ||
|
||
- script: sed -i 's/__VERSION__/${{ variables.FinalPkgVersionNumber }}/' pyproject.toml | ||
workingDirectory: ${{ variables.PythonPkgFolder }} | ||
displayName: 'Setup pkg version : ${{ variables.FinalPkgVersionNumber }}' | ||
|
||
- script: python -m build | ||
workingDirectory: ${{ variables.PythonPkgFolder }} | ||
displayName: 'Build python package' | ||
|
||
- script: python -m pip install --upgrade twine | ||
workingDirectory: ${{ variables.PythonPkgFolder }} | ||
displayName: 'Python package twine' | ||
|
||
# https://twine.readthedocs.io/en/stable/#twine-upload | ||
- script: python3 -m twine upload -r ${{ variables.repoAlias }} -u '$(pythonRepoUsername)' -p '$(pythonRepoPassword)' dist/* | ||
workingDirectory: ${{ variables.PythonPkgFolder }} | ||
displayName: 'Upload package to repository ${{ variables.repoAlias }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<!-- Democrite --> | ||
<PackageVersion Include="Democrite.Framework.Node" Version="0.2.2.205-prerelease" /> | ||
<PackageVersion Include="Democrite.Framework.Builders" Version="0.2.2.205-prerelease" /> | ||
<!-- Utilities --> | ||
<PackageVersion Include="Swashbuckle.AspNetCore" version="6.5.0" /> | ||
<PackageVersion Include="HtmlAgilityPack" Version="1.11.57" /> | ||
</ItemGroup> | ||
</Project> |
8 changes: 8 additions & 0 deletions
8
samples/PythonVGrains/PythonCalculatorApi/GlobalSuppressions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is used by Code Analysis to maintain SuppressMessage | ||
// attributes that are applied to this project. | ||
// Project-level suppressions either have no target or are given | ||
// a specific target and scoped to a namespace, type, member, etc. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage("Style", "IDE0053:Use expression body for lambda expression", Justification = "<Pending>")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
namespace Python | ||
{ | ||
using Democrite.Framework.Builders; | ||
using Democrite.Framework.Builders.Artifacts; | ||
using Democrite.Framework.Core.Abstractions; | ||
using Democrite.Framework.Core.Abstractions.Artifacts; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.OpenApi.Models; | ||
|
||
public static class Program | ||
{ | ||
[GenerateSerializer] | ||
public record ComplexResult(string formula, double result); | ||
|
||
public static async Task Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
|
||
builder.Services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo | ||
{ | ||
Title = "Democrite sample", | ||
Version = "v1" | ||
}); | ||
}).AddEndpointsApiExplorer(); | ||
|
||
// Slim python config | ||
var oneShotDef = await Artifact.VGrain("OneShotCalc", uid: new Guid("1B7331F0-3121-43B8-87F7-9B22226D24F8")) | ||
.Python("./Scripts/OneShot", "Calculator.py") | ||
.CompileAsync(); | ||
|
||
// Python config with helper | ||
var deamonDef = await Artifact.VGrain("demonCalc", uid: new Guid("EA23C491-D708-4BF4-88E3-3D95118C10D5")) | ||
.Python() | ||
.Directory("./Scripts") | ||
.ExecuteFile("Deamon/Calculator.py") | ||
.Persistent() | ||
.CompileAsync(); | ||
|
||
// Python config with helper and without Directory helper | ||
var complexDef = await Artifact.VGrain("demonCalc", uid: new Guid("6E24D646-2A9F-4467-942D-64DD4CE53770")) | ||
.Python() | ||
.From("./Scripts", ArtifactPackageTypeEnum.Directory, (string?)null) | ||
.ExecuteFile("Complex/ComplexCompute.py") | ||
.Persistent() | ||
.CompileAsync(); | ||
|
||
// Python config withouts helper | ||
var noResultDef = await Artifact.VGrain("demonCalc", uid: new Guid("3D7B54EE-8A77-42B5-AE84-C7CD091A0AF2")) | ||
.ExecuteBy("Python", new Version("3.12.1")) | ||
.From("./Scripts", ArtifactPackageTypeEnum.Directory, (string?)null) | ||
.ExecuteFile("NoResult/NoResultCompute.py") | ||
.CompileAsync(); | ||
|
||
builder.Host.UseDemocriteNode(b => | ||
{ | ||
b.WizardConfig() | ||
.NoCluster() | ||
.ConfigureLogging(c => c.AddConsole()) | ||
.AddInMemoryMongoDefinitionProvider(p => | ||
{ | ||
p.SetupArtifacts(oneShotDef, deamonDef, complexDef, noResultDef); | ||
}); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSwagger(); | ||
|
||
app.MapGet("/calc", ([FromServices] IDemocriteExecutionHandler handler, [FromQuery] string operation) => | ||
{ | ||
return handler.VGrain<IGenericArtifactExecutableVGrain>() | ||
.SetInput(operation) | ||
.SetConfiguration(oneShotDef.Uid) // Call one shot script | ||
.Call((g, i, ctx) => g.RunAsync<double, string>(i, ctx)) | ||
.RunAsync(); | ||
}); | ||
|
||
app.MapGet("/calc/dontuseresult", ([FromServices] IDemocriteExecutionHandler handler, [FromQuery] string operation) => | ||
{ | ||
return handler.VGrain<IGenericArtifactExecutableVGrain>() | ||
.SetInput(operation) | ||
.SetConfiguration(oneShotDef.Uid) // Call one shot script | ||
.Call((g, i, ctx) => g.RunWithInputAsync<string>(i, ctx)) | ||
.RunAsync(); | ||
}); | ||
|
||
app.MapGet("/calc/deamon", ([FromServices] IDemocriteExecutionHandler handler, [FromQuery] string operation) => | ||
{ | ||
return handler.VGrain<IGenericArtifactExecutableVGrain>() | ||
.SetInput(operation) | ||
.SetConfiguration(deamonDef.Uid) // Call persistant script | ||
.Call((g, i, ctx) => g.RunAsync<double, string>(i, ctx)) | ||
.RunAsync(); | ||
}); | ||
|
||
app.MapGet("/calc/complex", ([FromServices] IDemocriteExecutionHandler handler, [FromQuery] string operation) => | ||
{ | ||
return handler.VGrain<IGenericArtifactExecutableVGrain>() | ||
.SetInput(operation) | ||
.SetConfiguration(complexDef.Uid) // Call persistant complexDef script | ||
.Call((g, i, ctx) => g.RunAsync<ComplexResult, string>(i, ctx)) | ||
.RunAsync(); | ||
}); | ||
|
||
app.MapGet("/calc/noresult", ([FromServices] IDemocriteExecutionHandler handler, [FromQuery] string operation) => | ||
{ | ||
return handler.VGrain<IGenericArtifactExecutableVGrain>() | ||
.SetInput(operation) | ||
.SetConfiguration(noResultDef.Uid) // Call persistant noResultDef script | ||
.Call((g, i, ctx) => g.RunWithInputAsync(i, ctx)) | ||
.RunAsync(); | ||
}); | ||
|
||
app.UseSwaggerUI(); | ||
app.Run(); | ||
} | ||
} | ||
} |
Oops, something went wrong.