Skip to content

Commit 8c5565f

Browse files
authored
Merge pull request #121 from timlnx/py39-wrapup
Py39 wrapup
2 parents fe61997 + 15409e0 commit 8c5565f

13 files changed

Lines changed: 172 additions & 648 deletions

CLAUDE.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# CLAUDE.md
2+
3+
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
54+
- `Byte` — byte-based units; subclasses: `KiB MiB GiB TiB PiB EiB` (NIST/base-2) and `kB MB GB TB PB EB ZB YB` (SI/base-10)
55+
- `Bit` — bit-based units; subclasses: `Kib Mib Gib Tib Pib Eib` (NIST) and `kb Mb Gb Tb Pb Eb Zb Yb` (SI)
56+
57+
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
63+
- `parse_string(s)` / `parse_string_unsafe(s, system=SI)` — string → bitmath object
64+
- `query_device_capacity(device_fd)` — POSIX device capacity (Linux/macOS)
65+
66+
**Constants:** `NIST`, `SI`, `NIST_PREFIXES`, `SI_PREFIXES`, `ALL_UNIT_TYPES`
67+
68+
## Testing Notes
69+
70+
- Test runner: `pytest`
71+
- All tests are in `tests/` as `test_*.py` files
72+
- Test case names must be unique across the suite — enforced by `tests/test_unique_testcase_names.sh`
73+
- Coverage: 99% (one branch in `system` property intentionally uncovered)
74+
- `unittest.mock` (stdlib) is used for patching in integration tests

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ docs-venv:
5555
fi
5656
. $(DOCSVENV)/bin/activate && pip install -q -r doc-requirements.txt
5757

58-
docs: docs-venv conf.py $(MANPAGES) docsite/source/index.rst
58+
docs: docs-venv $(MANPAGES) docsite/source/index.rst
5959
. $(DOCSVENV)/bin/activate && cd docsite && make html
6060

6161
# Add examples to the RTD docs by taking it from the README
@@ -94,10 +94,6 @@ viewcover: ci-unittests
9494
xdg-open htmlcov/index.html; \
9595
fi
9696

97-
conf.py: docsite/source/conf.py.in
98-
sed "s/%VERSION%/$(VERSION)/" $< > docsite/source/conf.py
99-
100-
10197
build: clean
10298
@echo "#############################################"
10399
@echo "# Building sdist + wheel"

NEWS.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,35 @@ a major release. Version 2.0.0 is a thorough modernization: the
1717
Python 2 era is officially over, the library picks up several
1818
long-requested features, and the entire project infrastructure has
1919
been rebuilt from scratch. If you've been running bitmath on Python
20-
3.11 or later and quietly wishing it felt more modern — this release
20+
3.9 or later and quietly wishing it felt more modern — this release
2121
is for you.
2222

2323

2424
Breaking Changes
2525
================
2626

2727
**Python support**
28-
Python 3.11+ only. Python 2 and Python 3.7–3.10 are no longer
28+
Python 3.9+ only. Python 2 and Python < 3.9 are no longer
2929
supported or tested.
3030

3131
**parse_string() default system**
32-
The default unit system when ``strict=False`` is now **NIST**
33-
(binary). Previously it defaulted to SI. Code that relied on the
34-
old default for ambiguous strings such as ``"1g"`` will get a
35-
different result. See :ref:`parse-string-non-strict` for full details.
32+
The default unit system when ``strict=False`` is now **NIST** (base-2).
33+
Previously it defaulted to SI (base-10). Code that relied on the old default
34+
for ambiguous strings such as ``"1g"`` could get a different result. See
35+
:ref:`parse-string-non-strict` for full details. All bitmath now consistently
36+
defaults to the NIST system.
3637

3738
**parse_string_unsafe() deprecated**
3839
Use :func:`bitmath.parse_string` with ``strict=False`` instead.
3940
The old name still works but emits a :exc:`DeprecationWarning`.
4041

4142
**bitmath.integrations removed**
42-
The argparse, click, and progressbar integrations have been removed
43+
The ``argparse``, ``click``, and ``progressbar`` integrations have been removed
4344
from the package. Copy-paste replacements are provided in the new
4445
:ref:`Integration Examples <integration_examples>` documentation
4546
chapter. No changes to calling code are required — just a local
4647
copy of the relevant snippet.
4748

48-
**Build and install**
49-
``setup.py`` and ``setup.py.in`` are gone. Installation is
50-
``pip install bitmath``. Source builds use ``python -m build``.
51-
5249
**Byte and Bit display names**
5350
``Byte`` and ``Bit`` now display as ``B`` and ``b`` respectively,
5451
matching the abbreviated style of every other unit. Code that
@@ -57,6 +54,11 @@ Breaking Changes
5754
``"Byte"`` or ``"Bit"`` will need to be updated. The class names
5855
themselves are unchanged.
5956

57+
**Build and install**
58+
``setup.py`` and ``setup.py.in`` are gone. Installation is
59+
``pip install bitmath``. Source builds use ``python -m build``.
60+
61+
6062

6163
Library Improvements
6264
====================
@@ -81,7 +83,7 @@ still works exactly the same way. What 2.0.0 adds on top of that:
8183
<https://github.com/timlnx/bitmath/pull/76>`_.
8284

8385
**bitmath.sum() and built-in sum()**
84-
A new :func:`bitmath.sum` function returns a unit-normalised result
86+
A new :func:`bitmath.sum` function returns a unit-normalized result
8587
when summing mixed-type iterables. For uniform collections, the
8688
built-in :py:func:`sum` now works directly on bitmath sequences
8789
without a ``start=`` argument.

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ supported <https://devguide.python.org/versions/>`_ Python releases.
9999
$ sudo dnf install python3-bitmath
100100
101101
102-
**PyPi**:
102+
**PyPI**:
103103

104-
You could also install bitmath from `PyPi
105-
<https://pypi.python.org/pypi/bitmath>`_ if you like:
104+
You could also install bitmath from `PyPI
105+
<https://pypi.org/project/bitmath/>`_ if you like:
106106

107107
.. code-block:: bash
108108
109-
$ sudo pip install bitmath
109+
$ pip install --user bitmath
110110
111111
112112

0 commit comments

Comments
 (0)