Skip to content

Commit

Permalink
Merge branch 'dev' into feat/chart_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthenian8 committed Nov 15, 2023
2 parents 1e55095 + a2a1c58 commit 80d954b
Show file tree
Hide file tree
Showing 67 changed files with 658 additions and 241 deletions.
3 changes: 1 addition & 2 deletions dff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401


__author__ = "Denis Kuznetsov"
__email__ = "[email protected]"
__version__ = "0.6.1"
__version__ = "0.6.2"


import nest_asyncio
Expand Down
1 change: 0 additions & 1 deletion dff/context_storages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .database import DBContextStorage, threadsafe_method, context_storage_factory
from .json import JSONContextStorage, json_available
Expand Down
1 change: 0 additions & 1 deletion dff/messengers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/messengers/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .interface import MessengerInterface, PollingMessengerInterface, CallbackMessengerInterface, CLIMessengerInterface
from .types import PipelineRunnerFunction, PollingInterfaceLoopFunction
1 change: 0 additions & 1 deletion dff/messengers/telegram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

try:
import telebot
Expand Down
1 change: 0 additions & 1 deletion dff/pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401


from .conditions import (
Expand Down
1 change: 0 additions & 1 deletion dff/pipeline/pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/pipeline/service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/script/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .core.context import Context
from .core.keywords import (
Expand Down
1 change: 0 additions & 1 deletion dff/script/conditions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .std_conditions import (
exact_match,
Expand Down
1 change: 0 additions & 1 deletion dff/script/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/script/extras/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/script/extras/conditions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/script/extras/slots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/script/labels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .std_labels import repeat, previous, to_start, to_fallback, forward, backward
1 change: 0 additions & 1 deletion dff/script/responses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .std_responses import choice
1 change: 0 additions & 1 deletion dff/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
Expand Down
1 change: 0 additions & 1 deletion dff/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/utils/db_benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
from dff.utils.db_benchmark.benchmark import (
time_context_read_write,
DBFactory,
Expand Down
1 change: 0 additions & 1 deletion dff/utils/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
1 change: 0 additions & 1 deletion dff/utils/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
from .common import is_interactive_mode, check_happy_path, run_interactive_mode
from .toy_script import TOY_SCRIPT, TOY_SCRIPT_ARGS, HAPPY_PATH
from .response_comparers import default_comparer
Expand Down
1 change: 0 additions & 1 deletion dff/utils/turn_caching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401

from .singleton_turn_caching import cache_clear, lru_cache, cache
1 change: 0 additions & 1 deletion dff/utils/viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# flake8: noqa: F401
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
author = "DeepPavlov"

# The full version, including alpha/beta/rc tags
release = "0.6.1"
release = "0.6.2"


# -- General configuration ---------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SHELL = /bin/bash
PYTHON = python3
VENV_PATH = venv
VERSIONING_FILES = setup.py makefile docs/source/conf.py dff/__init__.py
CURRENT_VERSION = 0.6.1
CURRENT_VERSION = 0.6.2
TEST_COVERAGE_THRESHOLD=95
TEST_ALLOW_SKIP=all # for more info, see tests/conftest.py

Expand Down Expand Up @@ -34,13 +34,13 @@ venv:

format: venv
black --line-length=120 --exclude='venv|build|tutorials' .
black --line-length=100 tutorials
black --line-length=80 tutorials
.PHONY: format

lint: venv
flake8 --max-line-length=120 --exclude venv,build,tutorials .
flake8 --max-line-length=100 tutorials
@set -e && black --line-length=120 --check --exclude='venv|build|tutorials' . && black --line-length=100 --check tutorials || ( \
flake8 --max-line-length=120 --exclude venv,build,tutorials --per-file-ignores='**/__init__.py:F401' .
flake8 --max-line-length=100 --per-file-ignores='**/3_load_testing_with_locust.py:E402 **/4_streamlit_chat.py:E402' tutorials
@set -e && black --line-length=120 --check --exclude='venv|build|tutorials' . && black --line-length=80 --check tutorials || ( \
echo "================================"; \
echo "Bad formatting? Run: make format"; \
echo "================================"; \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def merge_req_lists(*req_lists: List[str]) -> List[str]:

setup(
name="dff",
version="0.6.1",
version="0.6.2",
description=description,
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/context_storages/1_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

if __name__ == "__main__":
check_happy_path(pipeline, HAPPY_PATH)
# This is a function for automatic tutorial running (testing) with HAPPY_PATH
# a function for automatic tutorial running (testing) with HAPPY_PATH

# This runs tutorial in interactive mode if not in IPython env
# and if `DISABLE_INTERACTIVE_MODE` is not set
Expand Down
4 changes: 3 additions & 1 deletion tutorials/context_storages/4_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


# %%
db_uri = "redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")
db_uri = "redis://{}:{}@localhost:6379/{}".format(
"", os.environ["REDIS_PASSWORD"], "0"
)
db = context_storage_factory(db_uri)


Expand Down
4 changes: 3 additions & 1 deletion tutorials/context_storages/8_db_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@
"""

# %%
benchmark.report(file=tutorial_dir / "Shelve.json", display={"name", "config", "metrics"})
benchmark.report(
file=tutorial_dir / "Shelve.json", display={"name", "config", "metrics"}
)

# %% [markdown]
"""
Expand Down
14 changes: 10 additions & 4 deletions tutorials/messengers/telegram/1_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ class and [telebot](https://pytba.readthedocs.io/en/latest/index.html)
script = {
"greeting_flow": {
"start_node": {
TRANSITIONS: {"greeting_node": cnd.exact_match(Message(text="/start"))},
TRANSITIONS: {
"greeting_node": cnd.exact_match(Message(text="/start"))
},
},
"greeting_node": {
RESPONSE: Message(text="Hi"),
TRANSITIONS: {lbl.repeat(): cnd.true()},
},
"fallback_node": {
RESPONSE: Message(text="Please, repeat the request"),
TRANSITIONS: {"greeting_node": cnd.exact_match(Message(text="/start"))},
TRANSITIONS: {
"greeting_node": cnd.exact_match(Message(text="/start"))
},
},
}
}
Expand All @@ -74,13 +78,15 @@ class and [telebot](https://pytba.readthedocs.io/en/latest/index.html)
script=script,
start_label=("greeting_flow", "start_node"),
fallback_label=("greeting_flow", "fallback_node"),
messenger_interface=interface, # The interface can be passed as a pipeline argument.
messenger_interface=interface,
# The interface can be passed as a pipeline argument.
)


def main():
pipeline.run()


if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building
if __name__ == "__main__" and is_interactive_mode():
# prevent run during doc building
main()
35 changes: 26 additions & 9 deletions tutorials/messengers/telegram/2_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ class is used to represent telegram message,
"start": {
TRANSITIONS: {
("general", "native_keyboard"): (
lambda ctx, _: ctx.last_request.text in ("/start", "/restart")
lambda ctx, _: ctx.last_request.text
in ("/start", "/restart")
),
},
},
"fallback": {
RESPONSE: TelegramMessage(text="Finishing test, send /restart command to restart"),
RESPONSE: TelegramMessage(
text="Finishing test, send /restart command to restart"
),
TRANSITIONS: {
("general", "native_keyboard"): (
lambda ctx, _: ctx.last_request.text in ("/start", "/restart")
lambda ctx, _: ctx.last_request.text
in ("/start", "/restart")
),
},
},
Expand All @@ -80,12 +84,16 @@ class is used to represent telegram message,
),
),
TRANSITIONS: {
("general", "success"): cnd.exact_match(TelegramMessage(text="4")),
("general", "success"): cnd.exact_match(
TelegramMessage(text="4")
),
("general", "fail"): cnd.true(),
},
},
"success": {
RESPONSE: TelegramMessage(**{"text": "Success!", "ui": RemoveKeyboard()}),
RESPONSE: TelegramMessage(
**{"text": "Success!", "ui": RemoveKeyboard()}
),
TRANSITIONS: {("root", "fallback"): cnd.true()},
},
"fail": {
Expand Down Expand Up @@ -120,7 +128,10 @@ class is used to represent telegram message,
),
(
TelegramMessage(text="5"),
TelegramMessage(text="Incorrect answer, type anything to try again", ui=RemoveKeyboard()),
TelegramMessage(
text="Incorrect answer, type anything to try again",
ui=RemoveKeyboard(),
),
),
(
TelegramMessage(text="ok"),
Expand All @@ -136,10 +147,15 @@ class is used to represent telegram message,
),
),
),
(TelegramMessage(text="4"), TelegramMessage(text="Success!", ui=RemoveKeyboard())),
(
TelegramMessage(text="4"),
TelegramMessage(text="Success!", ui=RemoveKeyboard()),
),
(
TelegramMessage(text="Yay!"),
TelegramMessage(text="Finishing test, send /restart command to restart"),
TelegramMessage(
text="Finishing test, send /restart command to restart"
),
),
(
TelegramMessage(text="/start"),
Expand Down Expand Up @@ -171,5 +187,6 @@ def main():
pipeline.run()


if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building
if __name__ == "__main__" and is_interactive_mode():
# prevent run during doc building
main()
29 changes: 21 additions & 8 deletions tutorials/messengers/telegram/3_buttons_with_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ class is used to represent telegram message,
"start": {
TRANSITIONS: {
("general", "keyboard"): (
lambda ctx, _: ctx.last_request.text in ("/start", "/restart")
lambda ctx, _: ctx.last_request.text
in ("/start", "/restart")
),
},
},
"fallback": {
RESPONSE: TelegramMessage(text="Finishing test, send /restart command to restart"),
RESPONSE: TelegramMessage(
text="Finishing test, send /restart command to restart"
),
TRANSITIONS: {
("general", "keyboard"): (
lambda ctx, _: ctx.last_request.text in ("/start", "/restart")
lambda ctx, _: ctx.last_request.text
in ("/start", "/restart")
)
},
},
Expand All @@ -81,16 +85,22 @@ class is used to represent telegram message,
}
),
TRANSITIONS: {
("general", "success"): cnd.exact_match(TelegramMessage(callback_query="correct")),
("general", "fail"): cnd.exact_match(TelegramMessage(callback_query="wrong")),
("general", "success"): cnd.exact_match(
TelegramMessage(callback_query="correct")
),
("general", "fail"): cnd.exact_match(
TelegramMessage(callback_query="wrong")
),
},
},
"success": {
RESPONSE: TelegramMessage(text="Success!"),
TRANSITIONS: {("root", "fallback"): cnd.true()},
},
"fail": {
RESPONSE: TelegramMessage(text="Incorrect answer, type anything to try again"),
RESPONSE: TelegramMessage(
text="Incorrect answer, type anything to try again"
),
TRANSITIONS: {("general", "keyboard"): cnd.true()},
},
},
Expand Down Expand Up @@ -132,7 +142,9 @@ class is used to represent telegram message,
),
(
TelegramMessage(text="Yay!"),
TelegramMessage(text="Finishing test, send /restart command to restart"),
TelegramMessage(
text="Finishing test, send /restart command to restart"
),
),
(
TelegramMessage(text="/restart"),
Expand Down Expand Up @@ -164,5 +176,6 @@ def main():
pipeline.run()


if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building
if __name__ == "__main__" and is_interactive_mode():
# prevent run during doc building
main()
Loading

0 comments on commit 80d954b

Please sign in to comment.