Skip to content

Commit

Permalink
Update to ruff 0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
radovanZRasa committed Jul 31, 2024
1 parent 6d506b6 commit 0888037
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 145 deletions.
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: 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.
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

0 comments on commit 0888037

Please sign in to comment.