Update to longwei 2.0.0 #13

Closed
opened 2026-06-13 02:05:31 +00:00 by coding-agent-marvin8 · 1 comment
coding-agent-marvin8 commented 2026-06-13 02:05:31 +00:00 (Migrated from codeberg.org)

longwei 2.0 is a major release with two categories of breaking changes that require updates across taibai.

Breaking change 1: APClient API

APClient.create() no longer accepts an external httpx client. It now manages its own HTTP client and is used as an async context manager:

Old: ap = await APClient.create(instance_url, http_client, access_token)
New: async with await APClient.create(instance=instance_url, access_token=access_token) as ap:

The static auth methods (create_app, validate_authorization_code) also drop the http_client parameter, and the code argument to validate_authorization_code is renamed to authorization_code.

The INSTANCE_TYPE_MASTODON constant moves from longwei.constants to the longwei top-level import.

Breaking change 2: HTTP library change

longwei 2.0 replaces httpx with httpx2 (pydantic's HTTP client). This means pytest-httpx (which targets httpx==0.28.*) no longer works for tests. The replacement is pytest-httpx2~=1.0, which wraps respx and provides an httpx2_mock fixture with a different route-builder API.

longwei 2.0 is a major release with two categories of breaking changes that require updates across taibai. ## Breaking change 1: APClient API APClient.create() no longer accepts an external httpx client. It now manages its own HTTP client and is used as an async context manager: Old: ap = await APClient.create(instance_url, http_client, access_token) New: async with await APClient.create(instance=instance_url, access_token=access_token) as ap: The static auth methods (create_app, validate_authorization_code) also drop the http_client parameter, and the code argument to validate_authorization_code is renamed to authorization_code. The INSTANCE_TYPE_MASTODON constant moves from longwei.constants to the longwei top-level import. ## Breaking change 2: HTTP library change longwei 2.0 replaces httpx with httpx2 (pydantic's HTTP client). This means pytest-httpx (which targets httpx==0.28.*) no longer works for tests. The replacement is pytest-httpx2~=1.0, which wraps respx and provides an httpx2_mock fixture with a different route-builder API.
coding-agent-marvin8 commented 2026-06-13 02:05:53 +00:00 (Migrated from codeberg.org)

Findings

longwei 2.0.0 on PyPI declares dependency httpx2[http2]~=2.3 (pydantic's HTTP client) and imports from httpx2 import AsyncClient internally. This makes pytest-httpx incompatible — it targets httpx==0.28.* only.

Plan of attack

Commit 1 — dep bump: pyproject.toml: longwei~=1.5.0 → longwei~=2.0.0; regenerate uv.lock and pylock.toml.

Commit 2 — source migration: All 16 command files: remove import httpx, replace async with httpx.AsyncClient() block with async with await APClient.create(instance=..., access_token=...) as ap:. commands/init.py: drop http_client from create_app() and validate_authorization_code() (renamed code → authorization_code). commands/trending.py: fix INSTANCE_TYPE_MASTODON import path.

Commit 3 — test migration: pyproject.toml: swap pytest-httpx → pytest-httpx2~=1.0. All async-layer test files (~18): rename httpx_mock fixture to httpx2_mock, update add_instance_mock helper in conftest.py, convert httpx_mock.add_response(method=..., url=..., json=...) to httpx2_mock.get(...).respond(json=...) etc. tests/test_init.py: update APClient.create patch to return async context manager.

Commit 4 — release notes update.

Key files: pyproject.toml, src/taibai/commands/.py (all), tests/conftest.py, tests/test_.py (all async-layer).

## Findings longwei 2.0.0 on PyPI declares dependency httpx2[http2]~=2.3 (pydantic's HTTP client) and imports from httpx2 import AsyncClient internally. This makes pytest-httpx incompatible — it targets httpx==0.28.* only. ## Plan of attack **Commit 1 — dep bump:** pyproject.toml: longwei~=1.5.0 → longwei~=2.0.0; regenerate uv.lock and pylock.toml. **Commit 2 — source migration:** All 16 command files: remove import httpx, replace async with httpx.AsyncClient() block with async with await APClient.create(instance=..., access_token=...) as ap:. commands/init.py: drop http_client from create_app() and validate_authorization_code() (renamed code → authorization_code). commands/trending.py: fix INSTANCE_TYPE_MASTODON import path. **Commit 3 — test migration:** pyproject.toml: swap pytest-httpx → pytest-httpx2~=1.0. All async-layer test files (~18): rename httpx_mock fixture to httpx2_mock, update add_instance_mock helper in conftest.py, convert httpx_mock.add_response(method=..., url=..., json=...) to httpx2_mock.get(...).respond(json=...) etc. tests/test_init.py: update APClient.create patch to return async context manager. **Commit 4 — release notes update.** Key files: pyproject.toml, src/taibai/commands/*.py (all), tests/conftest.py, tests/test_*.py (all async-layer).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/taibai#13
No description provided.