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/add docker image #384

Open
wants to merge 42 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
481fd55
qol: add attachments to cli interface
RLKRo Feb 11, 2024
973abaa
qol: make keywords upper case
RLKRo Feb 11, 2024
98692f9
qol: accept list of attachments as `Message.attachment`
RLKRo Feb 11, 2024
a9bbbb9
qol: make choice function accept responses as args
RLKRo Feb 11, 2024
d25fd30
qol: import script objects inside `dff/__init__.py`
RLKRo Feb 11, 2024
e8fc8f6
json import draft
RLKRo Feb 12, 2024
dfd61b5
add json import examples
RLKRo Feb 12, 2024
66b3bb0
add submodule aliases
RLKRo Feb 20, 2024
9637110
update resolve_target_object to use submodule aliases
RLKRo Feb 20, 2024
c4f04ba
add function to retrieve dff object mapping
RLKRo Feb 20, 2024
cfda4f7
small fixes
RLKRo Feb 22, 2024
0e5f72a
capitalize messages
RLKRo Mar 20, 2024
56755b9
improve import system for custom objects
RLKRo Mar 20, 2024
4b4cf69
make custom_dir standard way to address custom dir
RLKRo Mar 22, 2024
ce18579
prepare parser for dev release
RLKRo May 27, 2024
702ddc8
Merge branch 'master' into 'chore/slots2parser'
Ramimashkouk Jul 18, 2024
0c53232
Merge branch 'master' into chore/slots2parser
Ramimashkouk Jul 22, 2024
d787906
feat: Integrate slots parsing
Ramimashkouk Jul 22, 2024
8a4781d
chore: Add pre-transitions to script example
Ramimashkouk Jul 23, 2024
486a432
refactor: Use a consistent approach with slots
Ramimashkouk Aug 15, 2024
12c5913
feat: Add dockerfile image
Ramimashkouk Aug 15, 2024
cb0348d
refactor: Separate dockerfiles each in dir
Ramimashkouk Aug 22, 2024
8a49408
chore: Add chatsky to compose.yml
Ramimashkouk Aug 22, 2024
4f1c35f
chore: Add command to compose
Ramimashkouk Aug 28, 2024
f7faf1e
chore: Copy default pipeline to dockerfile
Ramimashkouk Aug 28, 2024
748aaec
feat: Add HTTPMessengerInterface
Ramimashkouk Aug 28, 2024
85f55ff
ci: Add workflow to build & publish docker image
Ramimashkouk Aug 28, 2024
3b8391b
fix: Make image workflow work
Ramimashkouk Sep 5, 2024
710d361
Merge branch 'feat/add-http-interface' into feat/add-docker-image
Ramimashkouk Sep 5, 2024
84a6630
chore: Publish docker image to ghrc
Ramimashkouk Sep 19, 2024
3e9e9d8
fix: Update dockerfile to find the built wheel
Ramimashkouk Sep 19, 2024
6af361b
Merge branch 'dev' into feat/add-docker-image
Ramimashkouk Sep 19, 2024
4a406c0
chore: Continue merge
Ramimashkouk Sep 19, 2024
7d15ab1
fix: Install dependencies in dokcerfile
Ramimashkouk Sep 19, 2024
6d17536
push poetry lock
Ramimashkouk Sep 19, 2024
a20de2c
chore: lock poetry
Ramimashkouk Nov 14, 2024
a0394eb
Merge branch 'dev' into feat/add-docker-image
Ramimashkouk Nov 14, 2024
d4296f0
fix: Import Message properly
Ramimashkouk Nov 14, 2024
029da89
chore: Get http_interface port from .env
Ramimashkouk Nov 18, 2024
51bc913
chore: Get port
Ramimashkouk Nov 18, 2024
584d06b
feat: Add http_interace health check
Ramimashkouk Nov 20, 2024
7e8f261
fix: Provide ctx_id for HttpInterface
Ramimashkouk Dec 2, 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
Prev Previous commit
Next Next commit
improve import system for custom objects
RLKRo committed Mar 20, 2024
commit 56755b9ecac4facf16edcff573c1a5cc132df2f7
2 changes: 1 addition & 1 deletion dff/pipeline/pipeline/pipeline.py
Original file line number Diff line number Diff line change
@@ -291,7 +291,7 @@ def from_file(
):
pre_services = [] if pre_services is None else pre_services
post_services = [] if post_services is None else post_services
script = JSONImporter.from_file(file).import_script()
script = JSONImporter(file).import_script()

def to_tuple(i):
if isinstance(i, list):
95 changes: 68 additions & 27 deletions dff/pipeline/pipeline/script_parsing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Union, Dict, Optional
from typing import Union, Optional, Sequence
import importlib
import importlib.util
import importlib.machinery
import sys
import logging
from pathlib import Path
import json
@@ -27,24 +30,76 @@ class JSONImporter:
CONFIG_KEY = "CONFIG"
TRANSITION_ITEM_KEYS = {"lbl", "cnd"}

def __init__(self, script: Dict[str, JsonValue]):
def __init__(self, file: Union[str, Path]):
if isinstance(file, str):
file = Path(file)

if file.suffix == ".json":
with open(file, "r") as fd:
script = json.load(fd)
elif file.suffix in (".yaml", ".yml"):
with open(file, "r") as fd:
script = yaml.load(fd, Loader=Loader)
else:
raise JSONImportError("File should have a `.json`, `.yaml` or `.yml` extension")
logger.info(f"Loaded file {file}")

self.script = script
config = self.script.get(self.CONFIG_KEY)
if not isinstance(config, dict):
raise JSONImportError("Config is not found -- your script has to define a CONFIG dictionary")
self.config = config

custom_dir = config.get(self.CUSTOM_DIR_CONFIG_OPTION, "custom_dir")
if "." in custom_dir:
raise JSONImportError("custom dir cannot contain `.`")
if not Path(custom_dir).exists():
raise JSONImportError(f"could not find directory {custom_dir}")
self.custom_dir_prefix = custom_dir + "."

@staticmethod
def resolve_target_object(obj: str):
module_name, object_name = obj.rsplit(".", maxsplit=1)
module = importlib.import_module(module_name)
return module.__getattribute__(object_name)
if not isinstance(custom_dir, str):
raise JSONImportError("CUSTOM_DIR must be a string")
custom_dir_path = Path(custom_dir)
if not custom_dir_path.is_absolute():
custom_dir_path = (file.parent / custom_dir_path).resolve(strict=False)

if not custom_dir_path.exists():
raise JSONImportError(f"Could not find directory {custom_dir_path}. custom_dir: {custom_dir}")

logger.info(f"CUSTOM_DIR set to {custom_dir_path}")
self.custom_dir_prefix = custom_dir_path.stem + "."

self._custom_dir_location = str(custom_dir_path.parent)
self._custom_modules = {}

def import_custom_module(self, module_name: str, paths: Optional[Sequence[str]] = None):
if module_name in self._custom_modules:
return self._custom_modules[module_name]

if paths is None:
paths = [self._custom_dir_location]

parent_name, _, child_name = module_name.rpartition(".")

if parent_name:
parent_module = self.import_custom_module(parent_name, paths)

paths = parent_module.__spec__.submodule_search_locations

for finder in sys.meta_path:
spec = finder.find_spec(child_name, paths)
if spec is not None:
break
else:
raise ModuleNotFoundError(f"No module named {child_name!r} at {paths!r}")

module = importlib.util.module_from_spec(spec)
self._custom_modules[module_name] = module
spec.loader.exec_module(module)
return module

def resolve_target_object(self, obj: str):
module_name, _, obj_name = obj.rpartition(".")

if obj.startswith(self.DFF_NAMESPACE_PREFIX):
module = importlib.import_module(module_name)
else:
module = self.import_custom_module(module_name)
return getattr(module, obj_name)

def import_script(self):
return self.replace_script_objects(self.script)
@@ -130,20 +185,6 @@ def replace_script_objects(self, obj: JsonValue):
return self.replace_string_values(obj)
return obj

@classmethod
def from_file(cls, file: Union[str, Path]):
if isinstance(file, str):
file = Path(file)

if file.suffix == ".json":
with open(file, "r") as fd:
return cls(json.load(fd))
elif file.suffix in (".yaml", ".yml"):
with open(file, "r") as fd:
return cls(yaml.load(fd, Loader=Loader))
else:
raise JSONImportError("file should have a `.json`, `.yaml` or `.yml` extension")


def get_dff_objects():
def get_objects_from_submodule(submodule_name: str, alias: Optional[str] = None):