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

[WIP] #26

Merged
merged 23 commits into from
Nov 9, 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
62 changes: 62 additions & 0 deletions .github/workflows/check_code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Check Code Quality

on:
pull_request:
branches:
- develop
- main

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip

- name: Run formatter
run: make format

- name: Commit changes
run: |
if [ -n "$(git status --porcelain)" ]; then
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "🎨 Format code with isort and black"
git push
fi

lint:
needs: format # formatジョブの完了後に実行
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip

- name: Run linter
run: make lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ format:
lint:
pip install -e .[lint]
python -m flake8 $(FORMAT_DIR)
# python -m mypy $(FORMAT_DIR) --install-types --non-interactive
python -m mypy $(FORMAT_DIR) --install-types --non-interactive

PHONY: build release release_from-develop format commit
12 changes: 12 additions & 0 deletions src/wikidot/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ class ForbiddenException(WikidotException):

def __init__(self, message):
super().__init__(message)


# ---
# 処理エラー関連
# ---


class NoElementException(WikidotException):
"""要素が存在しないときの例外"""

def __init__(self, message):
super().__init__(message)
16 changes: 10 additions & 6 deletions src/wikidot/connector/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def request(
return_exceptions: bool = False,
site_name: str | None = None,
site_ssl_supported: bool | None = None,
) -> tuple[BaseException | Any]:
) -> tuple[httpx.Response | Exception]:
"""ajax-module-connector.phpへのリクエストを行う

Parameters
Expand Down Expand Up @@ -215,6 +215,7 @@ async def _request(_body: dict[str, Any]) -> httpx.Response:

# リクエスト実行
try:
response = None
# Semaphoreで同時実行数制御
async with semaphore_instance:
async with httpx.AsyncClient() as client:
Expand All @@ -236,18 +237,21 @@ async def _request(_body: dict[str, Any]) -> httpx.Response:
retry_count += 1

# リトライ回数上限に達した場合は例外送出
if retry_count >= self.config.attempt_limit:
if retry_count > self.config.attempt_limit:
wd_logger.error(
f"AMC is respond HTTP error code: {response.status_code} -> {_body}"
f"AMC is respond HTTP error code: "
f"{response.status_code if response is not None else 'timeout'} -> {_body}"
)
raise AMCHttpStatusCodeException(
f"AMC is respond HTTP error code: {response.status_code}",
response.status_code,
f"AMC is respond HTTP error code: "
f"{response.status_code if response is not None else 'timeout'} -> {_body}",
response.status_code if response is not None else 999,
) from e

# 間隔を空けてリトライ
wd_logger.info(
f"AMC is respond status: {response.status_code} (retry: {retry_count}) -> {_body}"
f"AMC is respond status: {response.status_code if response is not None else 'timeout'} "
f"(retry: {retry_count}) -> {_body}"
)
await asyncio.sleep(self.config.retry_interval)
continue
Expand Down
4 changes: 2 additions & 2 deletions src/wikidot/module/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import httpx

from wikidot.common.exceptions import SessionCreateException
from ..common.exceptions import SessionCreateException

if TYPE_CHECKING:
from wikidot.module.client import Client
from .client import Client


class HTTPAuthentication:
Expand Down
18 changes: 9 additions & 9 deletions src/wikidot/module/client.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from wikidot.common import wd_logger
from wikidot.common.exceptions import LoginRequiredException
from wikidot.connector.ajax import AjaxModuleConnectorClient, AjaxModuleConnectorConfig
from wikidot.module.auth import HTTPAuthentication
from wikidot.module.private_message import (
from ..common import wd_logger
from ..common.exceptions import LoginRequiredException
from ..connector.ajax import AjaxModuleConnectorClient, AjaxModuleConnectorConfig
from .auth import HTTPAuthentication
from .private_message import (
PrivateMessage,
PrivateMessageCollection,
PrivateMessageInbox,
PrivateMessageSentBox,
)
from wikidot.module.site import Site
from wikidot.module.user import User, UserCollection
from .site import Site
from .user import AbstractUser, User, UserCollection


class ClientUserMethods:
def __init__(self, client: "Client"):
self.client = client

def get(self, name: str, raise_when_not_found: bool = False) -> User:
def get(self, name: str, raise_when_not_found: bool = False) -> "AbstractUser":
"""ユーザー名からユーザーオブジェクトを取得する

Parameters
Expand All @@ -37,7 +37,7 @@ def get(self, name: str, raise_when_not_found: bool = False) -> User:

def get_bulk(
self, names: list[str], raise_when_not_found: bool = False
) -> list[User]:
) -> UserCollection:
"""ユーザー名からユーザーオブジェクトを取得する

Parameters
Expand Down
62 changes: 0 additions & 62 deletions src/wikidot/module/forum.py

This file was deleted.

Loading