Skip to content
Open

v1.0 #42

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9b4edbf
Upgrade test dependencies
dargueta Sep 15, 2024
b8f4f9f
Drop support for 3.9, make `const` a boolean, other stuff
dargueta Sep 15, 2024
27dff69
Upgrade dependencies, simplify CI a bit
dargueta Nov 23, 2024
748c98a
Upgrade test dependencies
dargueta Dec 6, 2024
3c78a1d
Update use of `const` and `default`
dargueta Dec 6, 2024
492bc8d
Upgrade test dependencies
dargueta Dec 21, 2024
924f0f1
Lint stuff
dargueta Dec 21, 2024
aa825cb
Upgrade test dependencies
dargueta Jan 12, 2025
1e849de
Update copyright year and changelog
dargueta Jan 12, 2025
5901d22
f-string stuff and other linting offenses
dargueta Feb 13, 2025
9d7a188
Update test dependencies
dargueta Feb 13, 2025
88b9723
Lint, fix accidental deletion of @property on `default`
dargueta Feb 13, 2025
7dfd707
Poetry 2 removed --no-update
dargueta Feb 13, 2025
558263f
(BROKEN) So many test fixes...
dargueta Feb 13, 2025
710ade2
Upgrade test dependencies
dargueta May 16, 2025
249f5dc
Use new pyproject.toml metadata format
dargueta May 16, 2025
11b983f
Split out all test stuff from pyproject.toml
dargueta May 16, 2025
d9f3b40
Lint
dargueta May 16, 2025
1c2516a
Update test dependencies
dargueta May 23, 2025
be2c5bf
Upgrade test dependencies, simplify linting
dargueta Jun 24, 2025
11d4a85
(BROKEN) Lint fixes
dargueta Jun 24, 2025
39837c6
Enforce formatting in CI
dargueta Jun 26, 2025
a5d9ca4
Docstring fixes from linter
dargueta Jun 26, 2025
0872112
Upgrade test dependencies
dargueta Jul 5, 2025
d7fee80
Upgrade test dependencies
dargueta Aug 2, 2025
5b7bbfb
Update test dependencies
dargueta Aug 7, 2025
386b17c
Lint stuff
dargueta Aug 7, 2025
959cd90
Upgrade dependencies and MyPy settings
dargueta Sep 23, 2025
c886337
Drop 3.11, add 3.14
dargueta Nov 17, 2025
ab97cb6
Upgrade Ruff
dargueta Nov 17, 2025
10e5b0c
Change Makefile to fix imports on `make format`
dargueta Nov 17, 2025
06705f1
Update test requirements
dargueta Dec 8, 2025
f02e6d2
Make this a beta release
dargueta Dec 27, 2025
e4b07e0
Update test dependencies
dargueta Dec 27, 2025
ee84911
Fix more lint stuff
dargueta Dec 27, 2025
58ceacc
Update copyright year
dargueta Jan 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,29 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: "3.9"
tox-env: py39
- python-version: "3.10"
tox-env: py310
- python-version: "3.11"
tox-env: py311
- python-version: "3.12"
tox-env: py312
- python-version: "3.13.0-rc.1"
- python-version: "3.13"
tox-env: py313
- python-version: "pypy-3.9"
tox-env: pypy39
- python-version: "pypy-3.10"
tox-env: pypy310
- python-version: "3.12"
- python-version: "3.13"
tox-env: mypy
- python-version: "3.12"
- python-version: "3.13"
tox-env: lint
- python-version: "3.13"
tox-env: format
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5.2.0
uses: actions/setup-python@v5.3.0
with:
python-version: ${{ matrix.python-version }}
- name: Pre-installation requirements
run: pip3 install -U pip wheel setuptools
- name: Install dependencies
run: pip3 install -Ur dev-requirements.txt
run: pip3 install -U pip wheel setuptools -r dev-requirements.txt
- name: Run tests
run: tox -e ${{ matrix.tox-env }}
24 changes: 24 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[mypy]
allow_untyped_globals = false
allow_redefinition = false
check_untyped_defs = true
disallow_any_decorated = false
disallow_any_generics = true
disallow_any_unimported = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
follow_untyped_imports = true
ignore_missing_imports = false
implicit_reexport = false
no_implicit_optional = true
pretty = true
show_error_codes = true
strict_optional = true
warn_no_return = true
warn_unreachable = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_return_any = true
20 changes: 20 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[pytest]
addopts =
-vv
--cov=binobj
--import-mode importlib
filterwarnings =
always::DeprecationWarning


[coverage:run]
branch = true
source = binobj
plugins =
coverage_pyver_pragma

[coverage:report]
show_missing = true
skip_covered = true
fail_under = 96.9
precision = 1
52 changes: 52 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
target-version = "py310"

[lint]
exclude = ["docs/*"]
select = ["ALL"]
extend-ignore = [
"ANN401",
"COM812",
"CPY001", # Requires copyright notice in every file
"D105",
"D107",
"DTZ",
"EM",
"ERA001",
"FBT",
"FIX002",
"PLR2004",
"TD003",
"TRY003",
]

[lint.pyupgrade]
keep-runtime-typing = true

[lint.per-file-ignores]
"__init__.py" = ["F403", "PLC0414"]
"tests/*" = [
"ANN",
"D", # Forces docstrings and such
"PLR6301", # Method could be a function, class method, or static method
"S101",
"S311",
]
"tests/pep526_*.py" = ["N802", "N803", "I002"]
"tests/full_examples/cpio_test.py" = ["PLR6301"]
"tests/validators_test.py" = ["PLR6301"]

[lint.isort]
force-single-line = true
known-first-party = ["binobj"]
lines-after-imports = 2
order-by-type = false
required-imports = ["from __future__ import annotations"]

[lint.mccabe]
max-complexity = 9

[lint.flake8-annotations]
mypy-init-return = true

[lint.pydocstyle]
convention = "google"
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017-2024, Diego Argueta
Copyright (c) 2017-2026, Diego Argueta
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ PIP := python3 -m pip


poetry.lock: pyproject.toml
poetry lock --no-update
# Poetry 2.0 removed --no-update
poetry lock --no-update || poetry lock
touch $@

# Coverage file gets changed on every test run so we can use it to see when the
Expand All @@ -32,6 +33,11 @@ setup:
lint: $(SOURCEFILES)
tox -e lint

.PHONY: format
format:
poetry run ruff check --select I --fix binobj tests
poetry run ruff format binobj tests

.PHONY: clean
clean:
-$(MAKE) -C $(DOCSDIR) clean
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ binobj
.. |build-status| image:: https://github.com/dargueta/binobj/actions/workflows/ci.yml/badge.svg
:alt: Build status

.. |python-versions| image:: https://img.shields.io/badge/python-3.9,%203.10,%203.11,%203.12,%203.13-blue.svg
.. |python-versions| image:: https://img.shields.io/badge/python-3.10,%203.11,%203.12,%203.13-blue.svg
:alt: Python versions

.. |installs-month| image:: https://pepy.tech/badge/binobj/month
Expand Down Expand Up @@ -50,7 +50,7 @@ The same example rewritten using ``binobj``:

magic: Bytes = b"BM"
file_size: UInt32
_reserved: binobj.Bytes(const=b"\0\0\0\0", discard=True)
_reserved: binobj.Bytes(const=True, default=b"\0\0\0\0", discard=True)
pixels_offset: UInt32

# Legacy DIB header
Expand Down Expand Up @@ -81,7 +81,7 @@ System Requirements

- This package will *not* work on a `mixed-endian`_ system. Those are pretty rare
nowadays so chances are you won't have a problem.
- This has been tested on CPython 3.9-3.13, PyPy 3.9-3.10.
- This has been tested on CPython 3.10-3.13, and PyPy 3.10.

.. _mixed-endian: https://en.wikipedia.org/wiki/Endianness#Mixed

Expand Down
8 changes: 4 additions & 4 deletions binobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import importlib.metadata
from typing import NamedTuple
from typing import Optional

from .errors import *
from .fields import *
Expand All @@ -18,7 +17,7 @@ class VersionInfo(NamedTuple):
major: int
minor: int
patch: int
suffix: Optional[str]
suffix: str | None

@classmethod
def from_string(cls, version: str) -> VersionInfo:
Expand All @@ -29,11 +28,12 @@ def from_string(cls, version: str) -> VersionInfo:
return cls(int(major), int(minor), int(patch), suffix or None)

def __str__(self) -> str:
version = f"{self.major}.{self.minor}.{self.patch}"
# Having a version suffix is rare for this library, so we'll tell pycoverage to
# ignore this branch.
if self.suffix: # pragma: no cover
return "%d.%d.%d-%s" % (self.major, self.minor, self.patch, self.suffix)
return "%d.%d.%d" % (self.major, self.minor, self.patch)
return version + f"-{self.suffix}"
return version


__version__ = importlib.metadata.version("binobj")
Expand Down
8 changes: 3 additions & 5 deletions binobj/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
from __future__ import annotations

import functools
from typing import Callable
from typing import Optional
from typing import TYPE_CHECKING
from typing import Union


if TYPE_CHECKING: # pragma: no cover
from collections.abc import Callable
from collections.abc import Iterable
from typing import Any

Expand All @@ -29,13 +27,13 @@ class ValidatorMethodWrapper:
"""

def __init__(
self, func: Union[FieldValidator, StructValidator], field_names: Iterable[str]
self, func: FieldValidator | StructValidator, field_names: Iterable[str]
):
self.func = func
self.field_names = tuple(field_names or ())
functools.wraps(func)(self)

def __call__(self, *args: Any) -> Optional[bool]:
def __call__(self, *args: Any) -> bool | None:
"""Execute the wrapped function."""
return self.func(*args)

Expand Down
Loading
Loading