Skip to content

Commit 81aeafd

Browse files
authored
Merge pull request #137 from timlnx/dynamic-analysis
Dynamic analysis
2 parents 49a6bc8 + 80fdaca commit 81aeafd

20 files changed

Lines changed: 347 additions & 242 deletions

.github/workflows/bandit.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bandit Security Scan
3+
4+
on:
5+
push:
6+
branches: ["master"]
7+
pull_request:
8+
branches: ["master"]
9+
schedule:
10+
- cron: "0 0 * * 0"
11+
workflow_dispatch:
12+
13+
jobs:
14+
analyze:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
security-events: write
18+
env:
19+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v6.0.2
23+
24+
- name: Perform Bandit Analysis
25+
uses: PyCQA/bandit-action@v1
26+
with:
27+
targets: "bitmath/ tests/"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ docsite/build/doctrees
5353
bitmathenv3
5454
bitmathenv2
5555
bitmath2
56+
.vscode

CLAUDE.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ Phases 1 (maintenance 1.4.0) and 2 (bitmath 2.0.0) are complete. The project:
2727
## Common Commands
2828

2929
```bash
30-
# Run the full test suite with coverage (creates venv, runs pytest + linting)
30+
# Run the full test suite with coverage (creates venv, runs pytest + linting + bandit)
3131
make ci
3232

33+
# Run security scan only
34+
make ci-bandit
35+
3336
# Run linting only
34-
ruff check bitmath/ tests/
37+
make ci-pylint
3538

3639
# Build a wheel
3740
make build
@@ -66,6 +69,14 @@ All unit values are normalized to bits internally; conversion between units happ
6669

6770
**Constants:** `NIST`, `SI`, `NIST_PREFIXES`, `SI_PREFIXES`, `ALL_UNIT_TYPES`
6871

72+
## Versioning
73+
74+
The single source of truth for the version is the `VERSION` file. `pyproject.toml` reads it dynamically via `[tool.hatch.version]` — do not edit the version in `pyproject.toml` directly. The `Makefile` also reads `VERSION` for docs, man pages, and RPM builds. To bump the version, edit `VERSION` only.
75+
76+
## Security Scanning
77+
78+
Bandit runs as part of `make ci` via the `ci-bandit` target, scanning both `bitmath/` and `tests/`. It also runs as a GitHub Actions workflow (`.github/workflows/bandit.yml`) on push/PR to master and weekly. No issues were present as of 2.0.2.
79+
6980
## Testing Notes
7081

7182
- Test runner: `pytest`

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,12 @@ ci-pylint:
216216
@echo "#################################################"
217217
. $(NAME)env3/bin/activate && pylint bitmath/__init__.py
218218

219-
ci: clean uniquetestnames virtualenv ci-list-deps ci-pycodestyle ci-pylint ci-unittests
219+
ci-bandit:
220+
@echo ""
221+
@echo "#############################################"
222+
@echo "# Running Bandit Security Scan in virtualenv"
223+
@echo "#############################################"
224+
. $(NAME)env3/bin/activate && bandit -r -v bitmath/ tests/
225+
226+
ci: clean uniquetestnames virtualenv ci-list-deps ci-pycodestyle ci-pylint ci-bandit ci-unittests
220227
:

NEWS.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,80 @@ NEWS
55
:depth: 1
66
:local:
77

8+
.. _bitmath-2.1.0:
9+
10+
bitmath-2.1.0
11+
*************
12+
13+
*Unreleased*
14+
15+
bitmath 2.1.0 is a focused follow-up to the 2.0.0 modernization. It
16+
finishes the last of the Python 2 cleanup, tightens the project's
17+
quality tooling, and retires one piece of legacy API surface.
18+
19+
20+
Breaking Changes
21+
================
22+
23+
**Internal representation is uniformly floating-point**
24+
Every bitmath instance now stores its size as a 64-bit float, no
25+
matter which constructor created it. Previously the ``bytes=`` and
26+
``bits=`` keyword constructors, along with the bit-family value
27+
constructors such as ``Kib(N)``, leaked Python ``int`` values
28+
through the ``.bytes`` and ``.bits`` properties. Those properties
29+
now always return ``float``, matching the long-documented
30+
floating-point measurement design described in the :ref:`Rules for
31+
Math <appendix_math>` appendix. Equality, ordering, ``repr()``, and
32+
arithmetic results are unchanged; only code that inspected
33+
``type(instance.bytes)`` or ``type(instance.bits)`` directly will
34+
observe the difference.
35+
36+
**listdir() is deprecated**
37+
:func:`bitmath.listdir` now emits a :exc:`DeprecationWarning` on
38+
every call and will be removed in a future release. Iterate with
39+
:py:func:`os.walk` and call :func:`bitmath.getsize` directly
40+
instead. Closes `issue #27
41+
<https://github.com/timlnx/bitmath/issues/27>`_.
42+
43+
44+
Library Improvements
45+
====================
46+
47+
**pathlib support**
48+
:func:`bitmath.getsize` and :func:`bitmath.listdir` now accept
49+
:class:`pathlib.Path` objects, not just strings, for their path
50+
and ``search_base`` arguments.
51+
52+
53+
Project Infrastructure
54+
======================
55+
56+
**Linting moved to pylint**
57+
pylint replaces flake8/pyflakes across the CI workflow and the
58+
local toolchain, and the library is held at a 10.00/10 score.
59+
pycodestyle is retained for the PEP 8 whitespace checks pylint
60+
does not cover.
61+
62+
**Security scanning with bandit**
63+
bandit runs as part of ``make ci`` and as a dedicated GitHub
64+
Actions workflow that fires on every push, every pull request, and
65+
on a weekly schedule, scanning both ``bitmath/`` and ``tests/``.
66+
67+
**100% test coverage**
68+
The remaining coverage gaps were closed, including the
69+
platform-specific :func:`bitmath.query_device_capacity` branches,
70+
bringing the suite to 100% measured coverage on every supported
71+
platform.
72+
73+
**SPDX license headers**
74+
Every source and test file now carries ``SPDX-License-Identifier``
75+
and ``SPDX-FileCopyrightText`` headers.
76+
77+
**Single-sourced version**
78+
The package version is read dynamically from the ``VERSION`` file
79+
by hatchling, so bumping that one file propagates everywhere.
80+
81+
882
.. _bitmath-2.0.0:
983

1084
bitmath-2.0.0

README.rst

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
.. image:: https://readthedocs.org/projects/bitmath/badge/?version=latest
2-
:target: http://bitmath.rtfd.org/
3-
:align: right
4-
:height: 19
5-
:width: 77
6-
71
.. image:: https://github.com/timlnx/bitmath/actions/workflows/python.yml/badge.svg
82
:target: https://github.com/timlnx/bitmath/actions/workflows/python.yml
3+
.. image:: https://img.shields.io/pypi/v/bitmath.svg
4+
:target: https://pypi.org/project/bitmath/
5+
:alt: Latest Version
6+
.. image:: https://img.shields.io/pypi/dm/bitmath?style=flat-square
7+
:target: https://pypistats.org/packages/bitmath
8+
:alt: PyPI - Package Downloads
9+
.. image:: https://img.shields.io/pypi/implementation/bitmath?style=flat-square
10+
:alt: PyPI - Implementation
11+
.. image:: https://img.shields.io/pypi/pyversions/bitmath?style=flat-square
12+
:alt: PyPI - Python Version
913

14+
.. image:: https://readthedocs.org/projects/bitmath/badge/?version=latest
15+
:target: http://bitmath.rtfd.org/
16+
.. image:: https://github.com/timlnx/bitmath/actions/workflows/bandit.yml/badge.svg
17+
:target: https://github.com/timlnx/bitmath/actions/workflows/bandit.yml
18+
:alt: Bandit Security Scan
1019
.. image:: https://img.shields.io/github/issues/timlnx/bitmath?style=flat-square
1120
:target: https://github.com/timlnx/bitmath/issues
1221
:alt: Open issues
13-
1422
.. image:: https://img.shields.io/github/issues-pr/timlnx/bitmath?style=flat-square
1523
:target: https://github.com/timlnx/bitmath/pulls
1624
:alt: Open pull requests
17-
18-
.. image:: https://img.shields.io/pypi/dm/bitmath?style=flat-square
19-
:target: https://pypistats.org/packages/bitmath
20-
:alt: PyPI - Package Downloads
21-
2225
.. image:: https://img.shields.io/github/stars/timlnx/bitmath?style=flat-square
23-
:target: https://pypistats.org/packages/bitmath
26+
:target: https://github.com/timlnx/bitmath
2427
:alt: GitHub Project Popularity
25-
26-
.. image:: https://img.shields.io/pypi/l/bitmath?style=flat-square
27-
:target: https://opensource.org/licenses/MIT
28-
:alt: PyPI - License
29-
30-
.. image:: https://img.shields.io/pypi/implementation/bitmath?style=flat-square
31-
:alt: PyPI - Implementation
32-
33-
.. image:: https://img.shields.io/pypi/pyversions/bitmath?style=flat-square
34-
:alt: PyPI - Python Version
28+
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
29+
:target: https://github.com/timlnx/bitmath/blob/master/LICENSE
30+
:alt: License
3531

3632

3733
bitmath
3834
=======
3935

36+
* Free software: MIT License
37+
* Documentation: https://bitmath.readthedocs.io/en/latest/
38+
* Source: https://github.com/timlnx/bitmath
39+
* Bugs: https://github.com/timlnx/bitmath/issues
40+
* Contributing: https://bitmath.readthedocs.io/en/latest/contributing.html
41+
4042
`bitmath <http://bitmath.readthedocs.org/en/latest/>`_ simplifies many
4143
facets of interacting with file sizes in various units. Originally
4244
focusing on file size unit conversion, functionality now includes:
@@ -88,44 +90,33 @@ issues.
8890
Installation
8991
============
9092

91-
The easiest way to install bitmath is via ``dnf`` (or ``yum``) if
92-
you're on a Fedora/RHEL based distribution. bitmath is available in
93-
the main Fedora repositories, as well as EPEL Repositories. As of 2023
94-
bitmath is only developed, tested, and supported for `currently
95-
supported <https://devguide.python.org/versions/>`_ Python releases.
96-
97-
98-
.. code-block:: bash
99-
100-
$ sudo dnf install python3-bitmath
93+
.. admonition:: Seeking a Debian Maintainer
10194

95+
bitmath is not currently packaged for Debian or Ubuntu. If you're
96+
interested in maintaining the package for those distributions, please
97+
see `issue #117 <https://github.com/timlnx/bitmath/issues/117>`_.
10298

103-
**PyPI**:
99+
Requires Python 3.9 or newer. No runtime dependencies outside the
100+
standard library.
104101

105-
You could also install bitmath from `PyPI
106-
<https://pypi.org/project/bitmath/>`_ if you like:
102+
**PyPI** (the typical path):
107103

108104
.. code-block:: bash
109105
110-
$ pip install --user bitmath
111-
112-
113-
114-
**Source**:
106+
pip install bitmath
115107
116-
To install from source, clone the repository and use pip:
108+
**Fedora and EPEL**
117109

118110
.. code-block:: bash
119111
120-
$ git clone https://github.com/timlnx/bitmath.git
121-
$ cd bitmath
122-
$ pip install .
112+
sudo dnf install python3-bitmath
123113
124-
To also install the ``bitmath`` manpage:
114+
**From source**
125115

126116
.. code-block:: bash
127117
128-
$ sudo make install
118+
git clone https://github.com/timlnx/bitmath.git
119+
pip install ./bitmath
129120
130121
131122
Documentation

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.1.0

bitmath.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: bitmath
33
.\" Author: [see the "AUTHOR" section]
44
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5-
.\" Date: 05/04/2026
5+
.\" Date: 05/15/2026
66
.\" Manual: python-bitmath
7-
.\" Source: bitmath 2.0.1
7+
.\" Source: bitmath 2.1.0
88
.\" Language: English
99
.\"
10-
.TH "BITMATH" "1" "05/04/2026" "bitmath 2\&.0\&.1" "python\-bitmath"
10+
.TH "BITMATH" "1" "05/15/2026" "bitmath 2\&.1\&.0" "python\-bitmath"
1111
.\" -----------------------------------------------------------------
1212
.\" * Define some portability stuff
1313
.\" -----------------------------------------------------------------

0 commit comments

Comments
 (0)