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

Update to ruff 0.3.7 #1128

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
- [ ] added some tests for the functionality
- [ ] updated the documentation in the [rasaHQ/rasa](https://github.com/rasaHQ/rasa)
- [ ] updated the changelog (please check [changelog](https://github.com/RasaHQ/rasa-sdk/tree/main/changelog) for instructions)
- [ ] reformat files using `black` (please check [Readme](https://github.com/RasaHQ/rasa-sdk#code-style) for instructions)
- [ ] reformat files using `ruff` (please check [Readme](https://github.com/RasaHQ/rasa-sdk#code-style) for instructions)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ types: ## check types
poetry run mypy rasa_sdk

formatter: ## format code
poetry run black rasa_sdk tests
poetry run ruff format rasa_sdk tests

lint: ## check style with ruff and black
poetry run ruff check rasa_sdk tests --ignore D
poetry run black --exclude="rasa_sdk/grpc_py" --check rasa_sdk tests
poetry run ruff format --check rasa_sdk tests
make lint-docstrings
make check-generate-grpc-code-in-sync

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ make install

## Code Style

To ensure a standardized code style we use the formatter [black](https://github.com/ambv/black).
To ensure a standardized code style we use the formatter [ruff](https://github.com/astral-sh/ruff).
If your code is not formatted properly, GitHub CI will fail to build.

If you want to automatically format your code on every commit, you can use [pre-commit](https://pre-commit.com/).
Expand Down
2 changes: 2 additions & 0 deletions changelog/1128.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update ruff to 0.3.7.
Switch to ruff as code formatter.
1 change: 1 addition & 0 deletions grpc-standalone-server-integration-test-results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="14" time="0.502" timestamp="2024-08-07T07:14:11.276215" hostname="d04752f62534"><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_action_client-executor_result0-expected_keys0]" time="0.018" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_action_client-executor_result1-expected_keys1]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_action_client-executor_result2-expected_keys2]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_action_client-executor_result3-expected_keys3]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_tls_action_client-executor_result0-expected_keys0]" time="0.004" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_tls_action_client-executor_result1-expected_keys1]" time="0.004" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_tls_action_client-executor_result2-expected_keys2]" time="0.004" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_webhook[grpc_tls_action_client-executor_result3-expected_keys3]" time="0.004" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_action_missing_domain[grpc_action_client-exception0-DOMAIN]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_action_missing_domain[grpc_action_client-exception1-ACTION]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_action_missing_domain[grpc_tls_action_client-exception0-DOMAIN]" time="0.004" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_action_missing_domain[grpc_tls_action_client-exception1-ACTION]" time="0.003" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_healthcheck[grpc_healthcheck_client]" time="0.002" /><testcase classname="integration_tests.test_standalone_grpc_server" name="test_grpc_server_healthcheck[grpc_tls_healthcheck_client]" time="0.004" /></testsuite></testsuites>
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
requires = [ "poetry-core>=1.0.4",]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 88
target-version = [ "py37", "py38", "py39", "py310",]
exclude = "((.eggs | .git | .mypy_cache | .pytest_cache | build | dist ))"

[tool.poetry]
name = "rasa-sdk"
version = "3.9.0"
Expand Down Expand Up @@ -70,10 +65,13 @@ warn_unused_ignores = true
exclude = "rasa_sdk/grpc_py"

[tool.ruff]
ignore = [ "D100", "D104", "D105", "RUF005",]
line-length = 88
target-version = "py38"
exclude = [ "rasa_sdk/grpc_py", "eggs", ".git", ".pytest_cache", "build", "dist", ".DS_Store"]

[tool.ruff.lint]
ignore = [ "D100", "D101", "D102", "D103", "D104", "D105", "RUF005",]
select = [ "D", "E", "F", "W", "RUF",]
exclude = [ "rasa_sdk/grpc_py",]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
Expand Down Expand Up @@ -107,14 +105,14 @@ semantic_version = "^2.8.5"
mypy = "^1.5"
sanic-testing = "^22.12"

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.pytest.ini_options]
python_functions = "test_"
asyncio_mode = "auto"

[tool.poetry.group.dev.dependencies]
ruff = ">=0.0.256,<0.0.286"
ruff = ">=0.3.5,<0.4.0"
pytest-asyncio = "^0.21.0"
types-protobuf = "4.25.0.20240417"
35 changes: 26 additions & 9 deletions rasa_sdk/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def get_latest_entity_values(
entity_role: Optional[Text] = None,
entity_group: Optional[Text] = None,
) -> Iterator[Text]:
"""Get entity values found for the passed entity type and optional role and
group in latest message.
"""Get entity values found for the passed entity type.

Optionally role and group of the entities in the last message can be specified.

If you are only interested in the first entity of a given type use
`next(tracker.get_latest_entity_values("my_entity_name"), None)`.
Expand Down Expand Up @@ -222,9 +223,17 @@ def filter_function(e: Dict[Text, Any]) -> bool:
def applied_events(self) -> List[Dict[Text, Any]]:
"""Returns all actions that should be applied - w/o reverted events."""

def undo_till_previous(event_type: Text, done_events: List[Dict[Text, Any]]):
"""Removes events from `done_events` until the first
occurrence `event_type` is found which is also removed.
def undo_till_previous(
event_type: Text, done_events: List[Dict[Text, Any]]
) -> None:
"""Removes events from `done_events` until `event_type` is found.

Removes all events until first occurrence of an `event_type` is found
including the `event_type`.

Args:
event_type: The type of event to remove.
done_events: The list of events to remove the event from.
"""
# list gets modified - hence we need to copy events!
for e in reversed(done_events[:]):
Expand Down Expand Up @@ -357,34 +366,41 @@ def __str__(self) -> Text:


class ActionExecutionRejection(Exception):
"""Raising this exception will allow other policies
to predict another action
.
"""
"""Raising this exception will allow other policies to predict another action."""

def __init__(self, action_name: Text, message: Optional[Text] = None) -> None:
"""Create a rejection exception.

Args:
action_name: Name of the action that should be rejected.
message: Optional message to provide more information
"""
self.action_name = action_name
self.message = message or f"Custom action '{action_name}' rejected execution."

def __str__(self) -> Text:
"""Return the string representation of the exception."""
return self.message


class ActionNotFoundException(Exception):
def __init__(self, action_name: Text, message: Optional[Text] = None) -> None:
"""Create an exception for when an action is not found."""
self.action_name = action_name
self.message = (
message or f"No registered action found for name '{action_name}'."
)

def __str__(self) -> Text:
"""Return the string representation of the exception."""
return self.message


class ActionMissingDomainException(Exception):
"""Raising this exception when the domain is missing."""

def __init__(self, action_name: Text, message: Optional[Text] = None) -> None:
"""Create an exception for when the domain is missing."""
self.action_name = action_name
self.message = (
message
Expand All @@ -394,4 +410,5 @@ def __init__(self, action_name: Text, message: Optional[Text] = None) -> None:
)

def __str__(self) -> Text:
"""Return the string representation of the exception."""
return self.message
37 changes: 21 additions & 16 deletions rasa_sdk/knowledge_base/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


class ActionQueryKnowledgeBase(Action):
"""
Action that queries the knowledge base for objects and attributes of an object.
"""Action that queries the knowledge base for objects and attributes of an object.

The action needs to be inherited and the knowledge base needs to be set.
In order to actually query the knowledge base you need to:
- create your knowledge base
Expand All @@ -39,10 +39,12 @@ class ActionQueryKnowledgeBase(Action):
def __init__(
self, knowledge_base: KnowledgeBase, use_last_object_mention: bool = True
) -> None:
"""Creates an action that queries the knowledge base."""
self.knowledge_base = knowledge_base
self.use_last_object_mention = use_last_object_mention

def name(self) -> Text:
"""Returns the unique identifier of this action."""
return "action_query_knowledge_base"

def utter_attribute_value(
Expand All @@ -52,12 +54,10 @@ def utter_attribute_value(
attribute_name: Text,
attribute_value: Text,
):
"""
Utters a response that informs the user about the attribute value of the
attribute of interest.
"""Utters a response that informs the user about the value of an attribute.

Args:
dispatcher: the dispatcher
dispatcher: the collecting dispatcher
object_name: the name of the object
attribute_name: the name of the attribute
attribute_value: the value of the attribute
Expand All @@ -83,8 +83,7 @@ async def utter_objects(
object_type: Text,
objects: List[Dict[Text, Any]],
):
"""
Utters a response to the user that lists all found objects.
"""Utters a response to the user that lists all found objects.

Args:
dispatcher: the dispatcher
Expand Down Expand Up @@ -113,11 +112,13 @@ async def run(
tracker: Tracker,
domain: "DomainDict",
) -> List[Dict[Text, Any]]:
"""
Executes this action. If the user ask a question about an attribute,
the knowledge base is queried for that attribute. Otherwise, if no
attribute was detected in the latest request it assumes user is talking
about a new object type and, multiple objects of the requested type are
"""Executes the action.

If the user ask a question about an attribute,
the knowledge base is queried for that attribute.
Otherwise, if no attribute was detected in the latest
request it assumes user is talking about a new object type and,
multiple objects of the requested type are
returned from the knowledge base.

Args:
Expand All @@ -126,7 +127,6 @@ async def run(
domain: the domain

Returns: list of slots

"""
object_type = tracker.get_slot(SLOT_OBJECT_TYPE)
last_object_type = tracker.get_slot(SLOT_LAST_OBJECT_TYPE)
Expand Down Expand Up @@ -168,13 +168,15 @@ async def run(
async def _query_objects(
self, dispatcher: CollectingDispatcher, object_type: Text, tracker: Tracker
) -> List[Dict]:
"""
"""Queries the knowledge base for objects of the requested object type.

Queries the knowledge base for objects of the requested object type and
outputs those to the user. The objects are filtered by any attribute the
user mentioned in the request.

Args:
dispatcher: the dispatcher
object_type: the object types
tracker: the tracker

Returns: list of slots
Expand Down Expand Up @@ -227,12 +229,15 @@ async def _query_attribute(
attribute: Text,
tracker: Tracker,
) -> List[Dict]:
"""
"""Query the knowledge base using value of the attribute of the object.

Queries the knowledge base for the value of the requested attribute of the
mentioned object and outputs it to the user.

Args:
dispatcher: the dispatcher
object_type: the object type
attribute: the requested attribute
tracker: the tracker

Returns: list of slots
Expand Down
Loading
Loading