| 1 |
# AGENTS.md |
| 2 |
|
| 3 |
> Guidelines for AI coding agents working in the `aiowebdav2` repository. |
| 4 |
|
| 5 |
## Project Overview |
| 6 |
|
| 7 |
Async Python WebDAV client library. Python 3.11+, fully typed (`py.typed`), published to PyPI. |
| 8 |
Package source lives in `aiowebdav2/`, tests in `tests/`. |
| 9 |
|
| 10 |
## Build & Environment |
| 11 |
|
| 12 |
```bash |
| 13 |
# Install dependencies (requires uv - https://docs.astral.sh/uv/) |
| 14 |
uv sync --group dev |
| 15 |
|
| 16 |
# Node.js (only for Prettier on non-Python files) |
| 17 |
npm install |
| 18 |
``` |
| 19 |
|
| 20 |
## Test Commands |
| 21 |
|
| 22 |
```bash |
| 23 |
# Run all tests (--cov is in addopts by default) |
| 24 |
uv run pytest |
| 25 |
|
| 26 |
# Run a single test file |
| 27 |
uv run pytest tests/test_client.py |
| 28 |
|
| 29 |
# Run a single test function (use --no-cov for speed) |
| 30 |
uv run pytest tests/test_client.py::test_list_files -v --no-cov |
| 31 |
|
| 32 |
# Run tests matching a keyword pattern |
| 33 |
uv run pytest -k "test_quota" --no-cov |
| 34 |
|
| 35 |
# Run a specific parametrized case |
| 36 |
uv run pytest tests/test_client.py::test_list_files -k "server_path0" --no-cov |
| 37 |
``` |
| 38 |
|
| 39 |
**Important:** `asyncio_mode = "auto"` — async test functions are detected automatically. |
| 40 |
No `@pytest.mark.asyncio` decorator needed. |
| 41 |
|
| 42 |
## Lint & Format Commands |
| 43 |
|
| 44 |
```bash |
| 45 |
# Linting |
| 46 |
uv run ruff check . # Lint (all rules enabled) |
| 47 |
uv run ruff check --fix . # Lint with auto-fix |
| 48 |
uv run ruff format . # Format Python code |
| 49 |
uv run ruff format --check . # Check formatting without modifying |
| 50 |
|
| 51 |
# Type checking (strict mode) |
| 52 |
uv run mypy aiowebdav2 |
| 53 |
|
| 54 |
# Additional linters |
| 55 |
uv run pylint aiowebdav2 # Pylint (ignores tests/) |
| 56 |
uv run codespell --ignore-words-list=fo,incomfort,nam,bloc,ue |
| 57 |
uv run yamllint . |
| 58 |
|
| 59 |
# Non-Python formatting (JSON, YAML, Markdown) |
| 60 |
npm run prettier |
| 61 |
``` |
| 62 |
|
| 63 |
## Pre-commit Hooks |
| 64 |
|
| 65 |
Uses `prek` (not `pre-commit`). Run all hooks: `uv run prek run --all-files`. |
| 66 |
|
| 67 |
## Code Style |
| 68 |
|
| 69 |
### Formatting |
| 70 |
|
| 71 |
- **Formatter:** Ruff (`ruff format`) |
| 72 |
- **Line length:** 88 characters |
| 73 |
- **Indentation:** 4 spaces |
| 74 |
- **Quotes:** Double quotes (`"`) |
| 75 |
- **Trailing commas:** On multi-line structures |
| 76 |
- **End of file:** Single newline, no trailing whitespace |
| 77 |
|
| 78 |
### Imports |
| 79 |
|
| 80 |
Three groups separated by blank lines, sorted alphabetically within each: |
| 81 |
|
| 82 |
```python |
| 83 |
import asyncio # 1. Standard library |
| 84 |
from pathlib import Path |
| 85 |
|
| 86 |
import aiofiles # 2. Third-party |
| 87 |
from aiohttp import BasicAuth |
| 88 |
|
| 89 |
from .exceptions import WebDavError # 3. Local (relative imports) |
| 90 |
from .models import Property |
| 91 |
``` |
| 92 |
|
| 93 |
- Use **relative imports** within the `aiowebdav2` package |
| 94 |
- Use **absolute imports** in tests (`from aiowebdav2 import Client`) |
| 95 |
- Test helpers use relative imports (`from . import load_responses`) |
| 96 |
|
| 97 |
### Type Annotations |
| 98 |
|
| 99 |
- **All functions** must have full type annotations including return types |
| 100 |
- Use modern union syntax: `str | None` (not `Optional[str]`) |
| 101 |
- Use `collections.abc` for abstract types: `AsyncIterable`, `Callable`, `Generator` |
| 102 |
- Use `typing` for special forms: `IO`, `Any`, `ClassVar`, `Self`, `Protocol` |
| 103 |
- Mypy runs in strict mode — no untyped defs, no `Any` generics, strict optional |
| 104 |
|
| 105 |
### Naming Conventions |
| 106 |
|
| 107 |
| Element | Convention | Example | |
| 108 |
| ----------------- | -------------------- | --------------------------------------- | |
| 109 |
| Variables | `snake_case` | `remote_path`, `local_file` | |
| 110 |
| Functions/methods | `snake_case` | `list_files()`, `execute_request()` | |
| 111 |
| Private members | `_snake_case` | `_list_raw()`, `_get_auth()` | |
| 112 |
| Classes | `PascalCase` | `Client`, `ClientOptions` | |
| 113 |
| Exceptions | `PascalCase + Error` | `WebDavError`, `NoConnectionError` | |
| 114 |
| Constants | `UPPER_SNAKE_CASE` | `DEFAULT_ROOT = "/"` | |
| 115 |
| Module loggers | `_LOGGER` | `_LOGGER = logging.getLogger(__name__)` | |
| 116 |
| Files/directories | `snake_case` | `typing_helper.py`, `test_client.py` | |
| 117 |
|
| 118 |
### Dataclasses |
| 119 |
|
| 120 |
Always use the strict configuration: |
| 121 |
|
| 122 |
```python |
| 123 |
@dataclass(frozen=True, slots=True, kw_only=True) |
| 124 |
class ClientOptions: |
| 125 |
send_speed: int | None = None |
| 126 |
``` |
| 127 |
|
| 128 |
### Error Handling |
| 129 |
|
| 130 |
- Custom exception hierarchy rooted in `WebDavError` (see `exceptions.py`) |
| 131 |
- Map HTTP status codes to specific exceptions in request handling |
| 132 |
- Use exception chaining: `raise NoConnectionError(url) from err` |
| 133 |
- Assign error messages to `msg` before raising: |
| 134 |
```python |
| 135 |
msg = f"module {__name__!r} has no attribute {name!r}" |
| 136 |
raise AttributeError(msg) |
| 137 |
``` |
| 138 |
|
| 139 |
### Logging |
| 140 |
|
| 141 |
Use `%s` placeholders (not f-strings) for lazy evaluation: |
| 142 |
|
| 143 |
```python |
| 144 |
_LOGGER.debug("Request to %s with method %s", url, method) |
| 145 |
``` |
| 146 |
|
| 147 |
### String Formatting |
| 148 |
|
| 149 |
Use f-strings for everything except logging: |
| 150 |
|
| 151 |
```python |
| 152 |
f"Bearer {self._options.token}" |
| 153 |
``` |
| 154 |
|
| 155 |
### Exports |
| 156 |
|
| 157 |
- Explicit `__all__` in `__init__.py` listing every public symbol |
| 158 |
- `__init__.py` re-exports from submodules (barrel pattern) |
| 159 |
|
| 160 |
## Testing Conventions |
| 161 |
|
| 162 |
- **Framework:** pytest with `pytest-asyncio` (auto mode) and `aioresponses` |
| 163 |
- **File naming:** `test_<module_name>.py` mirroring source modules |
| 164 |
- **Docstrings:** Every test function must have a one-line docstring |
| 165 |
- **Assertions:** Plain `assert` statements (no `self.assertEqual`) |
| 166 |
- **Exception testing:** `pytest.raises` with `match=` parameter |
| 167 |
- **Parametrize:** `@pytest.mark.parametrize` with tuple-based test IDs |
| 168 |
- **Fixtures:** Defined in `conftest.py`, use `name=` parameter for renaming |
| 169 |
- **HTTP mocking:** `aioresponses` library (not `unittest.mock`) |
| 170 |
- **Test data:** XML fixtures in `tests/responses/`, loaded via `load_responses()` |
| 171 |
- **Coverage:** Minimum 50% enforced (`fail_under = 50`) |
| 172 |
|
| 173 |
```python |
| 174 |
async def test_list_files(client: Client, responses: aioresponses) -> None: |
| 175 |
"""Test list files.""" |
| 176 |
responses.add(url, "PROPFIND", status=200, body=load_responses("get_list.xml")) |
| 177 |
files = await client.list_files("/test_dir/") |
| 178 |
assert len(files) == 2 |
| 179 |
``` |
| 180 |
|
| 181 |
### Test-specific Ruff Overrides (`tests/ruff.toml`) |
| 182 |
|
| 183 |
Tests allow: `assert` statements, password detection strings, private member |
| 184 |
access, moving type-only imports used by pytest (`TC002`), and overwriting |
| 185 |
functions with many arguments (`PLR0913`). |
| 186 |
|
| 187 |
## CI/CD |
| 188 |
|
| 189 |
GitHub Actions includes PR/push workflows and release-only workflows: |
| 190 |
|
| 191 |
- **tests.yml** — pytest on Python 3.11, 3.12, 3.13 |
| 192 |
- **linting.yml** — ruff, codespell, pylint, yamllint, prettier |
| 193 |
- **typing.yml** — mypy strict checking |
| 194 |
- **release.yml** — builds and publishes to PyPI on GitHub release (`release.published`) |