Skip to content

Commit

Permalink
More linting fixes and updating schemas for Pydantic 2.0 (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
JudsonStevens authored Oct 1, 2023
1 parent 1ab4f5e commit 85f321f
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 118 deletions.
12 changes: 8 additions & 4 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ DISABLE:
- TEKTON
DISABLE_LINTERS:
- JSON_PRETTIER
- REPOSITORY_GITLEAKS
- SPELL_CSPELL
- SPELL_PROSELINT
- PYTHON_BANDIT
- PYTHON_FLAKE8
# We use MyPy
- PYTHON_PYLINT
- PYTHON_PYRIGHT
- REPOSITORY_GITLEAKS
- SPELL_CSPELL
- SPELL_LYCHEE
- SPELL_PROSELINT
DISABLE_ERRORS_LINTERS:
- REPOSITORY_DEVSKIM
- REPOSITORY_SEMGREP
DOCKERFILE_HADOLINT_ARGUMENTS: "--ignore DL3008 --ignore DL3018 --ignore DL3013 --ignore DL3059 --ignore DL3005"
COPYPASTE_JSCPD_ARGUMENTS:
- "--ignore '**/handlers/**,**/vector*'"
MARKDOWN_MARKDOWN_LINK_CHECK_CONFIG_FILE: ".markdown-link-check-config.json"
MARKDOWN_MARKDOWN_LINK_CHECK_DISABLE_ERRORS: true
PRINT_ALL_FILES: false
Expand All @@ -35,9 +38,10 @@ PYTHON_MYPY_ARGUMENTS:
"--disallow-any-generics",
]
PYTHON_MYPY_CONFIG_FILE: "pyproject.toml"
PYTHON_RUFF_CONFIG_FILE: "pyproject.toml"
REPOSITORY_DEVSKIM_ARGUMENTS: ["-g", ".mypy_cache/*"]
SHOW_ELAPSED_TIME: true
SPELL_MISSPELL_FILTER_REGEX_EXCLUDE: '(\.automation/generated|docs/descriptors)'
YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: '(templates/\.mega-linter\.yml/tests)'
YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: '(templates/\.mega-linter\.yml/tests/**\/tests\/**)'
YAML_PRETTIER_FILTER_REGEX_EXCLUDE: '(templates/\.mega-linter\.yml|mkdocs\.yml)'
YAML_V8R_FILTER_REGEX_EXCLUDE: '(descriptors|templates/\.mega-linter\.yml|\.codecov\.yml)'
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ repos:
- --install-types
- --non-interactive
- --strict-optional
- --disallow-any-generics
- --disallow-any-generics
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
[![Twitter Follow](https://img.shields.io/twitter/follow/operation_code.svg?style=social&label=Follow&style=social)](https://twitter.com/operation_code)
[![Code-style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)


[![CircleCI](https://circleci.com/gh/OperationCode/operationcode-pybot.svg?style=svg)](https://circleci.com/gh/OperationCode/operationcode-pybot)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://contributor-covenant.org/)

# OperationCode-Pybot
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ services:
image: pybot:latest
container_name: pybot01
ports:
- "8010:8010"
- "8010:8010"

ngrok:
image: wernight/ngrok:latest
environment:
- NGROK_PORT=pybot:8010
- NGROK_PORT=pybot:8010
ports:
- "4040:4040"
- "4040:4040"
5 changes: 3 additions & 2 deletions docker/docker-compose.weaviate.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
version: '3.4'
services:
weaviate:
image: semitechnologies/weaviate:1.19.6
ports:
- "8055:8080"
- "8055:8080"
environment:
QUERY_DEFAULTS_LIMIT: 20
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
Expand All @@ -15,4 +16,4 @@ services:
t2v-transformers:
image: semitechnologies/transformers-inference:sentence-transformers-all-mpnet-base-v2
environment:
ENABLE_CUDA: 1
ENABLE_CUDA: 1
3 changes: 2 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: '3.9'

services:
Expand All @@ -9,4 +10,4 @@ services:
dockerfile: docker/Dockerfile
command: uvicorn main:api -host 0.0.0.0 --port 5001 --reload --log-level 'debug'
ports:
- "5001:5001"
- "5001:5001"
14 changes: 12 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,29 @@ async def healthz() -> Response: # noqa: D103


@app.command("/mentor_request")
async def handle_mentor_request_command( # noqa: D103
async def handle_mentor_request_command(
context: AsyncBoltContext,
body: dict[str, Any],
) -> None:
"""Handle the /mentor_request command.
:param context: The context of the request from the Bolt framework
:param body: The body of the request
"""
logger.info("STAGE: Processing mentorship request...")
await handle_mentor_request(SlackCommandRequestBody(**body), context)


@app.view("mentorship_request_form_submit")
async def handle_mentorship_request_form_view_submit( # noqa: D103
async def handle_mentorship_request_form_view_submit(
body: dict[str, Any],
context: AsyncBoltContext,
) -> None:
"""Handle the submission of the mentorship request form.
:param body: The body of the request
:param context: The context of the request from the Bolt framework
"""
logger.info("STAGE: Processing mentorship form submission...")
await handle_mentorship_request_form_submit(SlackViewRequestBody(**body), context)

Expand Down
7 changes: 6 additions & 1 deletion modules/handlers/mentorship_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@ async def handle_mentorship_request_form_submit( # noqa: D103
)


async def handle_mentorship_request_claim( # noqa: D103
async def handle_mentorship_request_claim(
parsed_body: SlackActionRequestBody,
context: AsyncBoltContext,
) -> None:
"""Handle a mentorship request claim submission from Slack.
:param parsed_body: The parsed body of the Slack request.
:param context: The context object for the Slack request.
"""
logger.info("STAGE: Handling mentorship request claim...")
await context.ack()
blocks = parsed_body.message.blocks
Expand Down
9 changes: 6 additions & 3 deletions modules/models/greeting_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from pydantic import BaseModel, Field # noqa: D100
"""Models for the greeting module."""
from pydantic import BaseModel, Field


class UserInfo(BaseModel): # noqa: D101
id: str = Field( # noqa: A003
class UserInfo(BaseModel):
"""User info schema."""

id: str = Field(
...,
example="U02RK2AL5LZ",
description="The Slack ID of the new user",
Expand Down
2 changes: 1 addition & 1 deletion modules/models/shared_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ValidEnum(str, Enum):
class AirtableUser(BaseModel):
"""Model for Airtable user."""

id: str = Field( # noqa: A003
id: str = Field(
...,
example="usrAuExK7DEWFNiI6",
description="Airtable provided unique ID of the user",
Expand Down
6 changes: 4 additions & 2 deletions modules/models/slack_models/action_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
)


class SlackActionRequestBody(BasicSlackRequest): # noqa: D101
type: str = Field(..., example="block_actions", description="The type of action") # noqa: A003
class SlackActionRequestBody(BasicSlackRequest):
"""The body of a Slack action request."""

type: str = Field(..., example="block_actions", description="The type of action")
user: SlackUserInfo = Field(
...,
description="The user who triggered the action request",
Expand Down
9 changes: 7 additions & 2 deletions modules/models/slack_models/command_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from modules.models.slack_models.shared_models import BasicSlackRequest


class SlackCommandRequestBody(BasicSlackRequest): # noqa: D101
class SlackCommandRequestBody(BasicSlackRequest):
"""The body of a Slack command request.
These are typically received from the Slack application after a slash command is used.
"""

command: str = Field(
...,
example="/mentor_request",
Expand All @@ -29,7 +34,7 @@ class SlackCommandRequestBody(BasicSlackRequest): # noqa: D101
example="directmessage",
description="The name of the channel where the command was triggered",
)
response_url: str = Field(
response_url: str | None = Field(
None,
example="https://hooks.slack.com/actions/T01SBLfdsaQ57A/2902419552385/BiWpNhRSURKF9CvqujZ3x1MQ",
description="The URL to send the response to that will automatically put the response in the right place",
Expand Down
12 changes: 8 additions & 4 deletions modules/models/slack_models/event_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from modules.models.slack_models.shared_models import SlackMessageInfo


class MemberJoinedChannelEvent(BaseModel): # noqa: D101
type: str = Field( # noqa: A003
class MemberJoinedChannelEvent(BaseModel):
"""The body of a Slack member_joined_channel event."""

type: str = Field(
...,
example="member_joined_channel",
description="The type of event, should always be member_joined_channel",
Expand Down Expand Up @@ -32,7 +34,9 @@ class MemberJoinedChannelEvent(BaseModel): # noqa: D101
)


class MessageReceivedChannelEvent(BaseModel): # noqa: D101
class MessageReceivedChannelEvent(BaseModel):
"""The body of a Slack message event."""

team_id: str = Field(
...,
example="T024BE7LD",
Expand All @@ -47,7 +51,7 @@ class MessageReceivedChannelEvent(BaseModel): # noqa: D101
...,
description="The information about the message that was received",
)
type: str = Field( # noqa: A003
type: str = Field(
...,
example="event_callback",
description="The type of event, should always be event_callback",
Expand Down
2 changes: 1 addition & 1 deletion modules/models/slack_models/message_models.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# noqa: D100
"""Models for messages. Unused for now."""
Loading

0 comments on commit 85f321f

Please sign in to comment.