You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
6
+
## Project Overview
7
+
8
+
**bitmath** is a pure-Python library (no external runtime dependencies) for representing and converting file sizes across SI (decimal) and NIST (binary) unit systems. It supports arithmetic, rich comparisons, bitwise ops, parsing, formatting, and f-string/format() support.
9
+
10
+
## Project Direction
11
+
bitmath has been around for almost 12 years, and over that lifetime it promised to deliver backwards compatibility. It delivered on that promise and gathered a strong supporting of people and eventual "critical infrastructure" project status on the PyPI.org website.
12
+
13
+
As of January 2023 the project maintainer (me) has stated in this issue https://github.com/timlnx/bitmath/issues/99 that the project is still alive and the next release will be python 3 support only.
14
+
15
+
Much of that porting work has already happened in the `2023-01-26-no-more-py2` branch https://github.com/timlnx/bitmath/tree/2023-01-26-no-more-py2
16
+
17
+
### Current State (as of 2.0.0)
18
+
19
+
Phases 1 (maintenance 1.4.0) and 2 (bitmath 2.0.0) are complete. The project:
20
+
21
+
- Supports **Python 3.9 and newer only** (`requires-python = ">=3.9"` in `pyproject.toml`)
22
+
- Uses `hatchling` as the build backend (replaces `setup.py`)
23
+
- Uses `pytest` as the test runner (292 tests, 99% coverage — one branch in `system` property intentionally uncovered)
24
+
- Is published on PyPI as version 2.0.0
25
+
- Drop-in compatible with the 1.x public API
26
+
27
+
## Common Commands
28
+
29
+
```bash
30
+
# Run the full test suite with coverage (creates venv, runs pytest + linting)
31
+
make ci
32
+
33
+
# Run linting only
34
+
ruff check bitmath/ tests/
35
+
36
+
# Build a wheel
37
+
make build
38
+
39
+
# Install in development mode
40
+
pip install -e .
41
+
```
42
+
43
+
Run a single test file:
44
+
```bash
45
+
python -m pytest tests/test_arithmetic.py -v
46
+
```
47
+
48
+
## Architecture
49
+
50
+
Almost all logic lives in a single file: `bitmath/__init__.py` (~1650 lines).
51
+
52
+
**Class hierarchy:**
53
+
-`Bitmath` — base class with all arithmetic, comparison, bitwise, formatting, and conversion logic
All unit values are normalized to bits internally; conversion between units happens at construction time via `_norm_value` and class-level `_base_value` / `_unit_value` constants.
58
+
59
+
**Key module-level functions:**
60
+
-`best_prefix(value, system=NIST)` — pick the most human-readable unit for a raw byte value
61
+
-`getsize(path, ...)` — file size with automatic prefix selection
62
+
-`listdir(search_base, ...)` — recursive directory listing with sizes
0 commit comments