Skip to content

Commit d9e0568

Browse files
committed
docs: adds docstrings and improves readme
1 parent bf2e873 commit d9e0568

4 files changed

Lines changed: 73 additions & 30 deletions

File tree

README.md

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ The core `AFKParser` uses [parsedatetime](https://pypi.org/project/parsedatetime
1212
- "afk on monday"
1313

1414

15+
## Table of contents
16+
17+
- [Features](#features)
18+
- [Installation](#installation)
19+
- [Quick start](#quick-start)
20+
- [Supported phrase patterns](#supported-phrase-patterns-examples)
21+
- [Development](#development)
22+
- [Testing](#testing)
23+
- [Project structure](#project-structure)
24+
- [API reference](#api-reference)
25+
- [Requirements](#requirements)
26+
- [Limitations and notes](#limitations-and-notes)
27+
- [Contributing](#contributing)
28+
- [License](#license)
29+
30+
1531
### Features
1632

1733
- **Natural language parsing** powered by [parsedatetime](https://pypi.org/project/parsedatetime/)
@@ -22,25 +38,26 @@ The core `AFKParser` uses [parsedatetime](https://pypi.org/project/parsedatetime
2238

2339
## Installation
2440

25-
### From source (recommended until first PyPI release)
41+
### From source
2642

2743
```bash
2844
git clone https://github.com/astr0n0mer/afk_parser.git
2945
cd afk_parser
30-
python -m venv .venv && . .venv/bin/activate
31-
pip install -r requirements.txt
46+
uv sync
3247
```
3348

34-
For development (linters, tests, tooling):
49+
This creates a local `.venv` and installs the package with its locked dependencies.
50+
51+
For runtime dependencies only:
3552

3653
```bash
37-
make install_dev
54+
uv sync --no-dev
3855
```
3956

4057
### From PyPI (once published)
4158

4259
```bash
43-
pip install afk_parser
60+
uv add afk-parser
4461
```
4562

4663

@@ -74,7 +91,7 @@ Notes:
7491
Run the helper script with your phrase. It automatically infers your local UTC offset.
7592

7693
```bash
77-
python main.py "afk from 5pm"
94+
uv run python main.py "afk from 5pm"
7895
```
7996

8097
Example output (two lines; ISO-8601 repr may vary):
@@ -100,24 +117,30 @@ These examples are covered by tests and illustrate the behavior. Actual values d
100117

101118
## Development
102119

103-
This repository includes a `Makefile` to simplify common tasks. Use a virtual environment.
120+
Use `uv` to scaffold the environment and install dependencies from `pyproject.toml` and `uv.lock`.
104121

105122
```bash
106-
python -m venv .venv
107-
. .venv/bin/activate
123+
# Install runtime + dev dependencies
124+
uv sync
108125

109-
# Install runtime deps
110-
make install
111-
112-
# Install dev deps (pytest, ruff, pyright, etc.)
113-
make install_dev
126+
# Install runtime dependencies only
127+
uv sync --no-dev
114128
```
115129

116130
Useful commands:
117131

118-
- `make requirements` — regenerate `requirements.txt` and `requirements-dev.txt` from `requirements.in` files
119-
- `make install` — install runtime dependencies
120-
- `make install_dev` — install runtime + dev dependencies
132+
- `uv sync` — create/update `.venv` with runtime and dev dependencies
133+
- `uv sync --no-dev` — install runtime dependencies only
134+
- `uv sync --upgrade` — upgrade locked dependencies
135+
- `uv run python main.py "afk from 5pm"` — run the source CLI
136+
- `uv run pytest ./afk_parser/tests -vv` — run the test suite
137+
- `uv run pyright .` — run type checks
138+
- `uv run ruff format .` — format the codebase
139+
140+
The `Makefile` wraps the same common tasks if you prefer `make`:
141+
142+
- `make install` — run `uv sync --no-dev`
143+
- `make install_dev` — run `uv sync`
121144
- `make test` — run the test suite
122145
- `make lint` — run type checks with Pyright
123146
- `make format` — format with Ruff
@@ -128,14 +151,13 @@ Useful commands:
128151
Run the full test suite:
129152

130153
```bash
131-
make test
154+
uv run pytest ./afk_parser/tests -vv
132155
```
133156

134-
Or directly via pytest:
157+
Or via the Makefile:
135158

136159
```bash
137-
. .venv/bin/activate
138-
python -m pytest ./afk_parser/tests -vv
160+
make test
139161
```
140162

141163

@@ -150,7 +172,8 @@ afk_parser/
150172
test_afk_parser.py
151173
main.py # Simple CLI wrapper (from source)
152174
Makefile # Dev tasks (install, test, lint, format)
153-
requirements*.txt
175+
pyproject.toml # Project metadata and dependencies
176+
uv.lock # Locked dependency versions
154177
setup.py
155178
```
156179

@@ -169,8 +192,9 @@ class AFKParser:
169192

170193
## Requirements
171194

172-
- Python 3.10+
173-
- `parsedatetime` (installed via requirements)
195+
- Python 3.14+
196+
- `uv`
197+
- `parsedatetime` (installed by `uv sync`)
174198

175199

176200
## Limitations and notes
@@ -185,14 +209,12 @@ class AFKParser:
185209
Issues and PRs are welcome. Before opening a PR, please:
186210

187211
```bash
188-
make format
189-
make lint
190-
make test
212+
uv run ruff format .
213+
uv run pyright .
214+
uv run pytest ./afk_parser/tests -vv
191215
```
192216

193217

194218
## License
195219

196220
MIT © Imran Khan. See [LICENSE](./LICENSE) for details.
197-
198-

afk_parser/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""AFK parser package."""

afk_parser/afk_parser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1+
"""Parse AFK phrases into timezone-aware datetime windows."""
2+
13
from datetime import datetime, time, timedelta, timezone
24
import logging
35

46
from parsedatetime import Calendar, VERSION_CONTEXT_STYLE, pdtContext
57

68

79
class AFKParser:
10+
"""Convert natural-language AFK status phrases into start/end datetimes."""
11+
812
def __init__(self, logging_level: int = logging.INFO):
13+
"""Configure parser logging.
14+
15+
Args:
16+
logging_level: Standard library logging level used for parse failures.
17+
"""
918
logging.basicConfig(level=logging_level)
1019

1120
def parse_dates(
1221
self, phrase: str, tz_offset: float = 0
1322
) -> tuple[datetime, datetime] | None:
23+
"""Parse an AFK phrase into a timezone-aware `(start, end)` pair.
24+
25+
Args:
26+
phrase: Natural-language AFK phrase, such as "afk for 30 min".
27+
tz_offset: Offset from UTC in seconds for the returned datetimes.
28+
29+
Returns:
30+
A `(start_datetime, end_datetime)` tuple, or `None` when no date/time
31+
expression can be parsed from the phrase.
32+
"""
1433
custom_timezone = timezone(timedelta(seconds=tz_offset))
1534
start_datetime = end_datetime = datetime.now(tz=custom_timezone)
1635
cal = Calendar(version=VERSION_CONTEXT_STYLE)

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def main():
8+
"""Run the source CLI for parsing a single AFK phrase."""
89
if len(sys.argv) != 2:
910
print(f'Usage: python {__file__}.py "afk from 5pm"')
1011

0 commit comments

Comments
 (0)