Skip to content

Commit

Permalink
Merged PR 64: [Python] VGRain as pyhton
Browse files Browse the repository at this point in the history
- 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
MickaelThumerel committed Jan 18, 2024
1 parent 766484c commit acf8543
Show file tree
Hide file tree
Showing 100 changed files with 4,653 additions and 1,469 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
bin/**/artifacts/

# Publish
.publish
Expand Down
11 changes: 11 additions & 0 deletions Democrite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Democrite.Framework.Node.Mo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Democrite.Framework.Node.Mongo", "src\Extensions\Democrite.Framework.Node.Mongo\Democrite.Framework.Node.Mongo.csproj", "{ADAF23A8-3574-4F9E-94C9-BF046AA26CF2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dist", "Dist", "{D52F0DA3-F60F-40AA-BDDD-EFE133485A3F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Python", "Python", "{8CD6E17A-6E84-47B9-B069-C5ED19253ED1}"
ProjectSection(SolutionItems) = preProject
src\Extensions\Dist\Python\democrite.py = src\Extensions\Dist\Python\democrite.py
src\Extensions\Dist\Python\pyproject.toml = src\Extensions\Dist\Python\pyproject.toml
src\Extensions\Dist\Python\README.md = src\Extensions\Dist\Python\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -261,6 +270,8 @@ Global
{AA1C66AC-4910-443E-ABA9-76F1E581EA78} = {D53F80C8-5B1F-4153-989A-A10DD890B9D2}
{A181A232-49C5-47EF-A199-3BE0A19192A3} = {2F1AD903-9D49-4E20-9673-C93C5F85185B}
{ADAF23A8-3574-4F9E-94C9-BF046AA26CF2} = {2F1AD903-9D49-4E20-9673-C93C5F85185B}
{D52F0DA3-F60F-40AA-BDDD-EFE133485A3F} = {2F1AD903-9D49-4E20-9673-C93C5F85185B}
{8CD6E17A-6E84-47B9-B069-C5ED19253ED1} = {D52F0DA3-F60F-40AA-BDDD-EFE133485A3F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89BCBB25-4DD3-406C-91A9-BB2F978C23F2}
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,22 @@ This allow :
> You can access those grain usign the classic orleans [IGrainFactory]() way. <br />
> **BUT** it is better to use [IDemocriteExecutionHandler](#consume-democrite-cluster) who will use correctly and automatically the correct GrainId.

### External Code VGrain

With Democrite we can use other satellite program or script to perform jobs.<br />

To do so you need simple steps:
- Create Code artifact definitions
- Using through a vgrain
- Use generic vgrain in the library **IGenericArtifactExecutableVGrain**
- Create your own vgrain by inherite from **ArtifactExecutableBaseVGrain<>** instead of **VGrainBase**

#### Python

A python package exist to handle the communication protocol with democrite [README.md](/src/Extensions/Dist/Python/README.md) <br />
You can found a full sample [Here](/samples/PythonVGrains/) <br />


## Quick Start

### Nuget Packages
Expand Down
15 changes: 15 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ Release Notes

# Alpha

## 0.2.2-prerelease

In this version we mainly:
- Add Python VGrain support

### Features

- **Artifact** : Extended resource needed to democrite node to work (code, png, licences, pfx ...)
- Create, build and add artifact
- Define code artifact to be used as grain

- **Code Artifact** : Artifact use to configure the external code, for example python scripts
- **External Code Remote controller** : Controller using artifact code definition to launch, maintain and communicate to another program
- **Python Package** : Package deployed on [Pypi](https://pypi.org/project/democrite/) and [TestPypi](https://test.pypi.org/project/democrite/) (cf. [Python/README.md](/src/Extensions/Dist/Python/README.md))

## 0.2.1-prerelease

In this version we mainly:
Expand Down
43 changes: 43 additions & 0 deletions eng/Templates/azure-pipeline-pkg-version.yml
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 }}
24 changes: 2 additions & 22 deletions eng/azure-pipeline-release-nugets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,25 @@ variables:
- group: democrite-frameworks-variables
- group: azure-api

- template: Templates/azure-pipeline-pkg-version.yml

- name: SolutionFolder
value: "./"

- name: PublishNuget
value: ".publish/nuget"

- name: PkgVersionMajor
value: $(PackageVersionMajor)

- name: PkgVersionMinor
value: $(PackageVersionMinor)

- name: PkgVersionPatch
value: $(PackageVersionPatch)

- ${{ if eq(variables['ReleasePublic'], true) }}:
- name: PkgVersionBuild
value: ""

- name: NugetPackageFilter
value: "Democrite.Framework.*.nupkg"

- name: PkgVersionPrerelease
value: ""

- ${{ if ne(variables['ReleasePublic'], true) }}:

- name: PkgVersionBuild
value: ".$(Build.BuildId)"

- name: NugetPackageFilter
value: "Democrite.Framework.*.symbols.nupkg"

- name: PkgVersionPrerelease
value: "-prerelease"

- name : FinalPkgVersion
value: ${{ variables.PkgVersionMajor }}.${{ variables.PkgVersionMinor }}.${{ variables.PkgVersionPatch }}${{ variables.PkgVersionBuild }}${{ variables.PkgVersionPrerelease }}

steps:
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
Expand Down
68 changes: 68 additions & 0 deletions eng/azure-pipeline-release-pip.yml
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 }}'
13 changes: 13 additions & 0 deletions samples/PythonVGrains/Directory.Packages.props
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>
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>")]
121 changes: 121 additions & 0 deletions samples/PythonVGrains/PythonCalculatorApi/Program.cs
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();
}
}
}
Loading

0 comments on commit acf8543

Please sign in to comment.