-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User side of substantial #### Migration notes None - [ ] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change
- Loading branch information
1 parent
54b487d
commit 58d220f
Showing
23 changed files
with
1,195 additions
and
418 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
use std::path::PathBuf; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct SubstantialRuntimeData { | ||
pub endpoint: String, | ||
pub basic_auth_secret: Option<String>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum WorkflowKind { | ||
Python, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct WorkflowMatData { | ||
pub name: String, | ||
pub file: String, | ||
pub kind: WorkflowKind, | ||
pub deps: Vec<PathBuf>, | ||
} |
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,95 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// TODO: keyword filtering | ||
|
||
use crate::interlude::*; | ||
use crate::*; | ||
|
||
#[derive(Serialize, Deserialize, Debug, garde::Validate)] | ||
pub struct MdkSubstantialGenConfig { | ||
#[serde(flatten)] | ||
#[garde(dive)] | ||
pub base: crate::config::MdkGeneratorConfigBase, | ||
} | ||
|
||
impl MdkSubstantialGenConfig { | ||
pub fn from_json(json: serde_json::Value, workspace_path: &Path) -> anyhow::Result<Self> { | ||
let mut config: MdkSubstantialGenConfig = serde_json::from_value(json)?; | ||
config.base.path = workspace_path.join(config.base.path); | ||
config.base.typegraph_path = config | ||
.base | ||
.typegraph_path | ||
.as_ref() | ||
.map(|path| workspace_path.join(path)); | ||
Ok(config) | ||
} | ||
} | ||
|
||
pub struct Generator { | ||
config: MdkSubstantialGenConfig, | ||
} | ||
|
||
impl Generator { | ||
pub const INPUT_TG: &'static str = "tg_name"; | ||
pub fn new(config: MdkSubstantialGenConfig) -> Result<Self, garde::Report> { | ||
use garde::Validate; | ||
config.validate(&())?; | ||
Ok(Self { config }) | ||
} | ||
} | ||
|
||
impl crate::Plugin for Generator { | ||
fn bill_of_inputs(&self) -> HashMap<String, GeneratorInputOrder> { | ||
[( | ||
Self::INPUT_TG.to_string(), | ||
if let Some(tg_name) = &self.config.base.typegraph_name { | ||
GeneratorInputOrder::TypegraphFromTypegate { | ||
name: tg_name.clone(), | ||
} | ||
} else if let Some(tg_path) = &self.config.base.typegraph_path { | ||
GeneratorInputOrder::TypegraphFromPath { | ||
path: tg_path.clone(), | ||
name: self.config.base.typegraph_name.clone(), | ||
} | ||
} else { | ||
unreachable!() | ||
}, | ||
)] | ||
.into_iter() | ||
.collect() | ||
} | ||
|
||
fn generate( | ||
&self, | ||
// TODO: enable additionnal parameters for metagen | ||
// For example: meta gen --params workflow-name=hello_world | ||
_: HashMap<String, GeneratorInputResolved>, | ||
) -> anyhow::Result<GeneratorOutput> { | ||
let mut files = HashMap::new(); | ||
let base = self.config.base.path.clone(); | ||
files.insert( | ||
base.join("substantial.py"), | ||
GeneratedFile { | ||
contents: include_str!("static/substantial.py").to_owned(), | ||
overwrite: true, | ||
}, | ||
); | ||
files.insert( | ||
base.join("types.py"), | ||
GeneratedFile { | ||
contents: include_str!("static/types.py").to_owned(), | ||
overwrite: true, | ||
}, | ||
); | ||
files.insert( | ||
base.join("workflow.py"), | ||
GeneratedFile { | ||
contents: include_str!("static/workflow.py").to_owned(), | ||
overwrite: false, | ||
}, | ||
); | ||
|
||
Ok(GeneratorOutput(files)) | ||
} | ||
} |
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,33 @@ | ||
from datetime import timedelta | ||
from typing import Any, Callable, Optional | ||
from types import RetryStrategy | ||
|
||
|
||
class Context: | ||
async def save( | ||
self, | ||
f: Callable, | ||
*, | ||
timeout: Optional[timedelta] = None, | ||
retry_strategy: Optional[RetryStrategy] = None, | ||
): | ||
pass | ||
|
||
def handle(self, event_name: str, cb: Callable[[Any], Any]): | ||
pass | ||
|
||
async def ensure(self, f: Callable[[], bool]): | ||
pass | ||
|
||
async def sleep(self, duration: timedelta) -> Any: | ||
pass | ||
|
||
async def receive(name: str): | ||
pass | ||
|
||
|
||
def workflow(): | ||
def wrapper(f): | ||
pass | ||
|
||
return wrapper |
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,9 @@ | ||
from dataclasses import dataclass | ||
from typing import Union | ||
|
||
|
||
@dataclass | ||
class RetryStrategy: | ||
max_retries: int | ||
initial_backoff_interval: Union[int, None] | ||
max_backoff_interval: Union[int, None] |
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,7 @@ | ||
from substantial import workflow, Context # noqa | ||
from substantial.types import RetryStrategy # noqa | ||
|
||
|
||
@workflow() | ||
def workflow_name(c: Context): | ||
raise NotImplementedError |
Oops, something went wrong.