Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Workflow module #312

Merged
merged 70 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
bdc392a
feat: more test spec added
0hsn Aug 27, 2024
d4060bb
feat: workflow runs as expected for simple workflow
0hsn Aug 28, 2024
0e3c07c
refactor: add url params as separate section
0hsn Aug 29, 2024
136ede7
refactor: to make similar sign as other module
0hsn Aug 29, 2024
75f0434
refactor: handling obj init in contractor
0hsn Aug 31, 2024
a54888e
feat: handle absolute path conversion in ChkwareTask
0hsn Aug 31, 2024
1f26da6
docs: added todo for next update
0hsn Sep 1, 2024
d75bf85
refactor: improve checking
0hsn Sep 2, 2024
c551b83
refactor: move making task to separate function
0hsn Sep 2, 2024
1df2291
chore: remove hence
0hsn Sep 3, 2024
e43c75b
refactor: remove hence usages
0hsn Sep 3, 2024
922bd59
feat: pass variable from wf to validation
0hsn Sep 5, 2024
63d8248
refactor: formatting fix
0hsn Sep 6, 2024
a011ac6
feat: expose data added for wf spec
0hsn Sep 6, 2024
de5591d
feat: chkware task validation
0hsn Sep 6, 2024
fae11ba
feat: enum and task params entity
0hsn Sep 6, 2024
7a52ad6
feat: support for VersionedDocumentV2 on ExposeManager
0hsn Sep 7, 2024
d04a072
refactor: remove ExposableVariables, use Variables instead
0hsn Sep 8, 2024
8aea013
feat: add extra data by category in ExecResponse
0hsn Sep 8, 2024
508905e
feat: new doc version and str dunder added
0hsn Sep 8, 2024
a6b3ec6
feat: return all steps
0hsn Sep 8, 2024
f10a84e
feat: workflow run happy path success
0hsn Sep 8, 2024
13f34ae
refactor: reorder import
0hsn Sep 17, 2024
d69a0f8
feat: move presentation to separate display class
0hsn Sep 17, 2024
2f6110a
feat: add step exposed data to response
0hsn Sep 17, 2024
7bec938
feat: pass step response as list of exec response
0hsn Sep 17, 2024
6a2549f
feat: impl presentation service
0hsn Sep 18, 2024
5e501eb
refactor: normalize code
0hsn Sep 18, 2024
c748fb6
refactor: import reorder
0hsn Sep 18, 2024
fadb0ef
feat: sent fetch expection in exec response
0hsn Sep 18, 2024
b186de0
feat: add exposed data to exec response
0hsn Sep 18, 2024
8435eac
feat: add exposed data to exec response
0hsn Sep 18, 2024
39aaae5
fix: dumping response for validate
0hsn Sep 19, 2024
459a8bf
feat: add report to validate exec response
0hsn Sep 19, 2024
645dc85
feat: save step results
0hsn Sep 19, 2024
ea56e93
feat: pass presentation items
0hsn Sep 20, 2024
0c53a4d
feat: dump str final
0hsn Sep 20, 2024
c83e77f
feat: print displaying wf response
0hsn Sep 21, 2024
ddd8eb0
feat: get_exposed_replaced_data v2
0hsn Sep 23, 2024
6c95b62
refactor: instead of passed task info, pass the task
0hsn Sep 23, 2024
ca09d77
feat: try to covert to dict service method
0hsn Sep 27, 2024
36528f5
feat: update messaging for list for exportables
0hsn Sep 27, 2024
d700be9
refactor: reformation of spacing in output
0hsn Sep 28, 2024
4d5a6cd
feat: using the value of the enum
0hsn Sep 29, 2024
68947cc
refactor: remoce dumping
0hsn Sep 30, 2024
f53acfa
refactor: change fn sign
0hsn Sep 30, 2024
a019696
fix: json object dumping iissue
0hsn Oct 2, 2024
dae7fb8
feat: convert validation doc to v2
0hsn Oct 3, 2024
557dd60
feat: replace dataclass with basemodel
0hsn Oct 3, 2024
d556d69
docs: add feature suggestion
0hsn Oct 3, 2024
a1e95d0
feat: remove templating notation
0hsn Oct 3, 2024
55d6dea
feat: exposing dict based data in validation
0hsn Oct 3, 2024
c2f251c
feat: convert dataclass to basemodel based doc
0hsn Oct 3, 2024
b7ec614
feat: use replace utils ver2
0hsn Oct 3, 2024
e28c993
chore: package version update
0hsn Oct 4, 2024
eae1fd8
feat: add duct converted value
0hsn Oct 4, 2024
be757b6
feat: pass variables
0hsn Oct 4, 2024
f0dcd56
feat: use exposed value for dumping
0hsn Oct 4, 2024
a5c7196
refactor: remove unused func
0hsn Oct 4, 2024
f63bdeb
refactor: remove output data in exposed data uses
0hsn Oct 4, 2024
c6a7e9a
feat: finalize formatted and json dump for wf
0hsn Oct 4, 2024
5adddcc
fix: document type change in test
0hsn Oct 4, 2024
5968179
fix: issues with object type change
0hsn Oct 4, 2024
353fa49
feat: return inner data
0hsn Oct 4, 2024
d288434
fix: tests for wf tasks and services
0hsn Oct 4, 2024
767251f
fix: path issue caught on ci
0hsn Oct 4, 2024
157f9cd
fix: OS neutral path
0hsn Oct 4, 2024
c1642d9
refactor: from str concat to path concat
0hsn Oct 4, 2024
78b9549
refactor: reorder imports
0hsn Oct 4, 2024
8acf3a0
refactor: update paths to OS deps
0hsn Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ defusedxml = "*"
xmltodict = "*"
python-dotenv = "*"
pydantic = "*"
hence = {ref = "v0.10.1", git = "git+https://github.com/0hsn/hence.git"}

[dev-packages]
pytest = "*"
Expand Down
851 changes: 422 additions & 429 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion chk/infrastructure/document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base document and utility
"""

import dataclasses

import cerberus
Expand Down Expand Up @@ -32,7 +33,9 @@ class VersionedDocumentSupport:
"""DocumentVersionSupport"""

@staticmethod
def validate_with_schema(schema: dict, doc: VersionedDocument) -> bool:
def validate_with_schema(
schema: dict, doc: VersionedDocument | VersionedDocumentV2
) -> bool:
"""Validate a document with given schema

Args:
Expand Down
8 changes: 4 additions & 4 deletions chk/infrastructure/file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"""

from __future__ import annotations

import hashlib
from typing import NamedTuple
import json
from pathlib import Path
from typing import NamedTuple

import json
import yaml

from chk.infrastructure.typing_extras import JsonDecodingError
Expand Down Expand Up @@ -110,7 +111,6 @@ def filepath_base_as_path(self) -> Path:
return Path(self.filepath).absolute().parent


# @TODO Need testing
def generate_abs_path(base_: str, target_: str) -> str:
"""Generate absolute path in comparison to base path
Args:
Expand All @@ -136,7 +136,7 @@ def generate_abs_path(base_: str, target_: str) -> str:
if part == "..":
to_path = to_path.parent
else:
to_path = Path(str(to_path) + "/" + part)
to_path = to_path / part

return str(to_path)

Expand Down
11 changes: 11 additions & 0 deletions chk/infrastructure/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Helper functions module
"""

import ast
import re
from collections.abc import Callable
Expand Down Expand Up @@ -158,6 +159,16 @@ def to_auto(var: str) -> Any:

return var

@staticmethod
def try_dict(to_dict: Any, say_exception: bool = False) -> dict | Any:
try:
return dict(to_dict)
except ValueError as ex:
if say_exception:
raise ex
else:
return to_dict


def formatter(message: object, cb: Callable = str, dump: bool = True) -> str:
"""Format message with given callback
Expand Down
54 changes: 43 additions & 11 deletions chk/infrastructure/symbol_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Symbol and variable management
"""

import copy
import enum
import os
import typing
Expand All @@ -11,7 +13,7 @@
from pydantic import BaseModel, ConfigDict, Field

from chk.infrastructure.document import VersionedDocument, VersionedDocumentV2
from chk.infrastructure.file_loader import FileContext, ExecuteContext
from chk.infrastructure.file_loader import ExecuteContext, FileContext
from chk.infrastructure.helper import data_get
from chk.infrastructure.templating import StrTemplate

Expand Down Expand Up @@ -60,30 +62,27 @@ class Variables(UserDict):
"""Holds data for a variable"""


class ExposableVariables(UserDict):
"""Holds data for a expose data"""


class ExecResponse(BaseModel):
"""ExecResponse"""

model_config = ConfigDict(arbitrary_types_allowed=True)

file_ctx: FileContext
exec_ctx: ExecuteContext
variables_exec: ExposableVariables
variables: Variables
variables_exec: Variables
extra: object = Field(default=None)
exception: Exception | None = Field(default=None)
exposed: list | dict = Field(default_factory=list)
report: dict = Field(default_factory=dict)


@typing.overload
def replace_value(doc: dict, var_s: dict) -> dict:
...
def replace_value(doc: dict, var_s: dict) -> dict: ...


@typing.overload
def replace_value(doc: list, var_s: dict) -> list:
...
def replace_value(doc: list, var_s: dict) -> list: ...


def replace_value(doc: dict | list, var_s: dict) -> dict | list:
Expand Down Expand Up @@ -239,7 +238,9 @@ def replace_values(
return replace_callback(expose_doc, values)

@staticmethod
def get_exposed_replaced_data(document: VersionedDocument, store: dict) -> list:
def get_exposed_replaced_data(
document: VersionedDocument | VersionedDocumentV2, store: dict
) -> list:
"""Get expose doc from a `VersionedDocument`, and prepare it from the
value of `Variables`, and `store`, and return

Expand All @@ -257,3 +258,34 @@ def get_exposed_replaced_data(document: VersionedDocument, store: dict) -> list:
return ExposeManager.replace_values(expose_doc, store)

return []

@staticmethod
def get_exposed_replaced_data_v2(
document: VersionedDocumentV2, store: dict
) -> dict:
"""
Get expose doc from a `VersionedDocument`, and prepare it from the
value of `Variables`, and `store`, and return

Args:
document: VersionedDocument to get expose definition from it
store: dict to use as value store

Returns:
dict: list of expose data
"""

file_ctx = FileContext(*document.context)

if expose_doc := ExposeManager.get_expose_doc(file_ctx.document):

exposed_doc_t = copy.copy(expose_doc)
exposed_doc_t = [
str(key).replace("%>", "").replace("<%", "").strip()
for key in exposed_doc_t
]

expose_val = ExposeManager.replace_values(expose_doc, store)
return dict(zip(exposed_doc_t, expose_val))

return {}
11 changes: 11 additions & 0 deletions chk/infrastructure/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@
VERSION_STORE = {
"http": [
"0.7.2",
"0.8.0",
],
"testcase": [
"0.7.2",
"0.8.0",
],
"validation": [
"0.7.2",
"0.8.0",
],
"workflow": [
"0.8.0",
],
}

Expand Down Expand Up @@ -108,6 +114,11 @@ def verify_doc_type_ver(self) -> bool:

return True

def __str__(self) -> str:
"""str dunder"""

return self.original_version_str


class DocumentVersionMaker:
"""Create document version object"""
Expand Down
24 changes: 24 additions & 0 deletions chk/infrastructure/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""View related utility mod"""

import abc
import typing

from pydantic import BaseModel


class PresentationBuilder(BaseModel, abc.ABC):
"""Presentable signature"""

data: typing.Any

@abc.abstractmethod
def dump_fmt(self) -> str:
"""Signature to dump formatted string"""

raise NotImplementedError("Signature to dump formatted string")

@abc.abstractmethod
def dump_json(self) -> str:
"""Signature to dump json"""

raise NotImplementedError("Signature to dump json")
Loading
Loading