Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JnyJny/bitvector
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.11.0
Choose a base ref
...
head repository: JnyJny/bitvector
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jul 10, 2020

  1. Create python-pytest.yml

    JnyJny authored Jul 10, 2020
    Copy the full SHA
    b3efbd0 View commit details
  2. Update python-pytest.yml

    Start pytest with poetry.
    JnyJny authored Jul 10, 2020
    Copy the full SHA
    82cc9d2 View commit details
  3. Update python-pytest.yml

    Shmaybe 3.7 is the minimum.
    JnyJny authored Jul 10, 2020
    Copy the full SHA
    50cd29c View commit details
  4. Update python-pytest.yml

    JnyJny authored Jul 10, 2020
    Copy the full SHA
    ef82ef4 View commit details
  5. Update python-pytest.yml

    JnyJny authored Jul 10, 2020
    Copy the full SHA
    0bf9f74 View commit details
  6. Update python-pytest.yml

    Sigh.
    JnyJny authored Jul 10, 2020
    Copy the full SHA
    af0d3e9 View commit details
  7. Copy the full SHA
    b3924ea View commit details
  8. Copy the full SHA
    bfe8618 View commit details
  9. Copy the full SHA
    e5b892a View commit details
  10. Added awesome badge.

    JnyJny committed Jul 10, 2020
    Copy the full SHA
    e083ac6 View commit details

Commits on Jul 11, 2020

  1. Switched out functools.partialmethod for real methods.

    Using `function.partialmethod` to define BitVector methods was super
    convenient with the glaring exception that I couldn't set doc
    strings. I feel strongly that pydoc should provide human readable
    content, so I re-wrote all the methods as "real" methods with
    docstrings. Tests past and take roughly the same amount of time,
    but `pydoc bitvector` is now much less cryptic than it was.
    JnyJny committed Jul 11, 2020
    Copy the full SHA
    b776c34 View commit details
  2. Copy the full SHA
    9e85f6e View commit details
  3. 0.12.0

    JnyJny committed Jul 11, 2020
    Copy the full SHA
    59eda7d View commit details
  4. Copy the full SHA
    ee047b6 View commit details
  5. Copy the full SHA
    3a77432 View commit details
  6. 0.13.0

    JnyJny committed Jul 11, 2020
    Copy the full SHA
    28bbba8 View commit details

Commits on Jul 30, 2020

  1. updated dependencies

    JnyJny committed Jul 30, 2020
    Copy the full SHA
    be1e497 View commit details
  2. Added bitvector.bitfield.ReadOnlyBitField

    The ReadOnlyBitField data descriptor is a data descriptor
    whose __set__ method raises TypeError if the user attempts to
    assign a value with the descriptor.
    JnyJny committed Jul 30, 2020
    Copy the full SHA
    10841cd View commit details
  3. Support for ReadOnlyBitField

    JnyJny committed Jul 30, 2020
    Copy the full SHA
    82d62f5 View commit details
  4. Copy the full SHA
    c0dd8cf View commit details
  5. 0.14.0

    JnyJny committed Jul 30, 2020
    Copy the full SHA
    29b7df4 View commit details

Commits on Jan 10, 2021

  1. Copy the full SHA
    0d14d28 View commit details
  2. Copy the full SHA
    4171861 View commit details
  3. Copy the full SHA
    73a28f2 View commit details
  4. Copy the full SHA
    33864c4 View commit details
  5. Copy the full SHA
    c49d3fc View commit details
  6. Added py.typed marker

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    ac81908 View commit details
  7. 0.14.1

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    e0bc30c View commit details
  8. Added matrix pytest for 3.x

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    54d2cc5 View commit details
  9. Removed old test action

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    6e51947 View commit details
  10. Copy the full SHA
    7df48f1 View commit details
  11. Added badges to README

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    87e47dc View commit details
  12. Updated README

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    80ec268 View commit details
  13. Updated README

    JnyJny committed Jan 10, 2021
    Copy the full SHA
    f4f6567 View commit details
  14. Copy the full SHA
    6fb48af View commit details

Commits on Jul 17, 2024

  1. fix: building a wheel

    this fixes two issues when building a wheel using pyproject-build.
    The first issue
    ```
    ERROR Missing dependencies:
      poetry>=0.12
    ```
    can be resolved by requiring poetry-core over poetry>=0.12
    
    The second issue
    ```
    ModuleNotFoundError: No module named 'poetry.masonry'
    ```
    can be resolved by importing the correct module from poetry.core.
    
    see also https://pypi.org/project/poetry-core/
    Conni2461 committed Jul 17, 2024
    Copy the full SHA
    5cb3ce3 View commit details
  2. Merge pull request #1 from helsinki-systems/fix/wheel

    fix: building a wheel
    JnyJny authored Jul 17, 2024
    Copy the full SHA
    1188e3d View commit details
31 changes: 31 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: pytest

on:
push:
tags:
- "*"

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
name: Test BitVector For Humans ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install pip/poetry/pytest
run: |
python -m pip install --upgrade pip
pip install poetry pytest
- name: Install BitVector-For-Humans
run: |
poetry install
- name: Test with pytest
run: |
poetry run pytest
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -60,5 +60,9 @@ minor_release: minor push publish

release: patch_release

mypy: MYPY= mypy
mypy:
$(MYPY) $(TARGET)

clean:
@rm -rf htmlcov
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<!-- python3 bitvector bit vector bits bit-twiddling binary -->
![version][pypi-version]
![pytest][pytest-action]
![license][license]
![monthly-downloads][monthly-downloads]
![Code style: black][code-style-black]



# Bit Vectors For Humans™

This simple bit vector implementation aims to make addressing single
@@ -37,7 +46,7 @@ b'\xcc\xbb\xaa\x95'
## Installation

```console
$ pip install bitvector-for-humans
$ python3 -m pip install bitvector-for-humans
$ pydoc bitvector
...
```
@@ -48,11 +57,11 @@ Or directly from github:
$ pip install git+https://github.com/JnyJny/bitvector.git
```

## Motivation
## Motivations

1. Address sub-byte bits in a less error prone way.
2. Minimize subdependencies.
3. Learn something about descriptors.
2. Minimize subdependencies (zero is minimized right?).
3. Learn something about descriptors: ✅.

## Caveats

@@ -61,7 +70,7 @@ setting / getting code and it could undoubtedly be improved. Pull
requests gladly accepted.

## Other Ways to Implement a Bit Vector

<!-- EJO add links to these other things -->
1. Python builtin `ctypes.Structure` allows sub-byte bit fields
2. Python builtin `struct` provides extensive support for byte manipulations
3. Python3 IntEnums can be used to build bit field masks
@@ -71,6 +80,12 @@ requests gladly accepted.
7. Other good ideas I overlooked, forgot about or just plain don't know.


<!-- badges -->
[pytest-action]: https://github.com/JnyJny/bitvector/workflows/pytest/badge.svg
[code-style-black]: https://img.shields.io/badge/code%20style-black-000000.svg
[pypi-version]: https://img.shields.io/pypi/v/bitvector-for-humans
[license]: https://img.shields.io/pypi/l/bitvector-for-humans
[monthly-downloads]: https://img.shields.io/pypi/dm/bitvector-for-humans



3 changes: 2 additions & 1 deletion bitvector/__init__.py
Original file line number Diff line number Diff line change
@@ -3,5 +3,6 @@

from .bitvector import BitVector
from .bitfield import BitField
from .bitfield import ReadOnlyBitField

__all__ = ["BitVector", "BitField"]
__all__ = ["BitVector", "BitField", "ReadOnlyBitField"]
2 changes: 1 addition & 1 deletion bitvector/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.0"
__version__ = "0.14.1"
42 changes: 23 additions & 19 deletions bitvector/bitfield.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,29 @@
"""


class BitField:
"""Data Descriptor for accessing named fields in a BitVector.
class ReadOnlyBitField:
"""Read-only data descriptor for accessing named fields in a BitVector.
"""

def __init__(self, offset: int, width: int = 1):
"""
:param offset: int
:param width: int
"""
self.field = slice(offset, offset + width)

def __set__(self, obj, value) -> None:
raise TypeError(f"Read-only field '{self.name}'")

def __get__(self, obj, type=None) -> int:
return obj[self.field]

def __set_name__(self, owner, name) -> None:
self.name = name


class BitField(ReadOnlyBitField):
"""Data descriptor for accessing named fields in a BitVector.
```python
> from bitvector import BitVector, BitField
@@ -23,24 +44,7 @@ class BitField:
> mybv
MyBV(value=0x5502ff, length=128)
```
"""

def __init__(self, offset: int, width: int = 1):
"""
:param offset: int
:param width: int
"""
self.field = slice(offset, offset + width)

def __get__(self, obj, type=None) -> int:

value = obj[self.field]
return value

def __set__(self, obj, value) -> None:
prev = obj[self.field]
obj[self.field] = value

def __set_name__(self, owner, name) -> None:
self.name = name
Loading