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

Add codespell support (config, workflow to detect/not fix) and make it fix few typos #19

Merged
merged 5 commits into from
Nov 25, 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
25 changes: 25 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Codespell configuration is within pyproject.toml
---
name: Codespell

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Annotate locations with typos
uses: codespell-project/codespell-problem-matcher@v1
- name: Codespell
uses: codespell-project/actions-codespell@v2
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ repos:
entry: pdm run lint-mypy
pass_filenames: false
language: system
- repo: https://github.com/codespell-project/codespell
# Configuration for codespell is in pyproject.toml
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli
2 changes: 1 addition & 1 deletion examples/4_service_to_service/example_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Client for service to service example.

Kicks off exmaple by sending message to service one, and then
Kicks off example by sending message to service one, and then
waits for an event from service one to confirm the messages were passed between the two services properly.

"""
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ exclude_also = [
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
skip = '.git*,*.lock'
check-hidden = true
# ignore-regex = ''
# ignore-words-list = ''
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def publish(self, topic: str, payload: bytes, persist: bool) -> None:
topic: The topic on which to publish the message as a string.
payload: The message to publish, as raw bytes.
persist: Determine if the message should live until queue consumers or available (True), or
if it should be removed immediatedly (False)
if it should be removed immediately (False)
"""
# NOTE: RabbitMQ only works with QOS of 1 and 0, and seems to convert QOS2 to QOS1
self._connection.publish(topic, payload, qos=2 if persist else 0)
Expand Down
2 changes: 1 addition & 1 deletion src/intersect_sdk/_internal/event_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def definition_metadata_differences(
) -> list[tuple[str, str, str]]:
"""Return a list of differences between 'definition' and 'metadata'.

First tuple value = defintion key
First tuple value = definition key
Second tuple value = second value
Third tuple value = already cached value
"""
Expand Down
2 changes: 1 addition & 1 deletion src/intersect_sdk/_internal/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_external_request(
response_handler: INTERSECT_SERVICE_RESPONSE_CALLBACK_TYPE | None = None,
timeout: float = 300.0,
) -> UUID:
"""Observed entity (capabilitiy) tells observer (i.e. service) to send an external request.
"""Observed entity (capability) tells observer (i.e. service) to send an external request.

Params:
- request: the request we want to send out, encapsulated as an IntersectDirectMessageParams object
Expand Down
2 changes: 1 addition & 1 deletion src/intersect_sdk/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def get_schema_and_functions_from_capability_implementations(
if cap_status_fn_name and cap_status_schema and cap_status_type_adapter:
if status_function_name is not None:
# TODO may want to change this later
die('Only one capabilitiy may have an @intersect_status function')
die('Only one capability may have an @intersect_status function')
status_function_cap = capability_type
status_function_name = cap_status_fn_name
status_function_schema = cap_status_schema
Expand Down
2 changes: 1 addition & 1 deletion src/intersect_sdk/config/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


class HierarchyConfig(BaseModel):
"""Configuration for registring this service in a system-of-system architecture."""
"""Configuration for registering this service in a system-of-system architecture."""

service: Annotated[str, Field(pattern=HIERARCHY_REGEX)]
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def some_func(self) -> bool: ...
assert len(errors) == 1
assert {'type': 'missing', 'loc': ('event_type',)} in errors

# special case: we have a custom vaildator for event_type which fails on some common instantiations
# special case: we have a custom validator for event_type which fails on some common instantiations
with pytest.raises(ValidationError) as ex:

class BadEventArgs4(IntersectBaseCapabilityImplementation):
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_schema_invalids.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class PydanticUnparsableInner:
three: str

@intersect_message()
def cant_parse_annotation(self, unparseable: PydanticUnparsableInner) -> None: ...
def cant_parse_annotation(self, unparsable: PydanticUnparsableInner) -> None: ...
Copy link
Collaborator

@Lance-Drane Lance-Drane Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the assertion statement of this test on line 140, we'll need to change parameter 'unparseable' to parameter 'unparsable' to make sure it passes the test. I think this is the only reason the tests are failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha -- thanks for catching. I didn't know about this nuance! Apparently codespell, while determining words, includes ' as part of the word.

Proposed

and now digging deeper there :-(


with pytest.raises(SystemExit):
get_schema_helper([PydanticUnparsable])
assert (
"On capability 'PydanticUnparsable', parameter 'unparseable' type annotation" in caplog.text
"On capability 'PydanticUnparsable', parameter 'unparsable' type annotation" in caplog.text
)
assert "on function 'cant_parse_annotation' is invalid" in caplog.text

Expand All @@ -158,7 +158,7 @@ def mock_message(self) -> object: ...

def test_disallow_object_subtyping(caplog: pytest.LogCaptureFixture):
# should fail because return type has a subtyping object (dynamic typing)
# note that 'object' is evalutated exactly like it is as a root type
# note that 'object' is evaluated exactly like it is as a root type
class MockObjectSubtype(IntersectBaseCapabilityImplementation):
intersect_sdk_capability_name = 'unused'

Expand Down Expand Up @@ -456,7 +456,7 @@ def mock_message(self, param: Inner) -> None: ...


def test_disallow_ambiguous_typealiastype(caplog: pytest.LogCaptureFixture):
# should fail because the TypeVar is ambigous and would resolve to "Any"
# should fail because the TypeVar is ambiguous and would resolve to "Any"
class AmbiguousTypeAliasType(IntersectBaseCapabilityImplementation):
intersect_sdk_capability_name = 'unused'
T = TypeVar('T')
Expand Down Expand Up @@ -975,4 +975,4 @@ def status_function_2(self) -> str: ...

with pytest.raises(SystemExit):
get_schema_helper([CapabilityName1, CapabilityName2])
assert 'Only one capabilitiy may have an @intersect_status function' in caplog.text
assert 'Only one capability may have an @intersect_status function' in caplog.text
Loading