From 05a24247d9e61165bb519aec6bbfb9a71d41e677 Mon Sep 17 00:00:00 2001 From: m0wer Date: Fri, 15 May 2026 05:00:47 +0200 Subject: [PATCH] chore: modernize project tooling and packaging Add PEP 621 pyproject.toml with declarative metadata, dynamic version, and configuration for ruff, mypy, and pytest. Reduce setup.py to a thin shim for callers that still invoke it directly. Add .pre-commit-config.yaml wiring ruff, ruff-format, mypy, and standard file hygiene hooks so contributors get the same checks locally and in CI. Remove run_flake8.sh and run_mypy.sh, both of which are superseded by the ruff and mypy hooks. --- .pre-commit-config.yaml | 30 ++++++++++++++ pyproject.toml | 87 +++++++++++++++++++++++++++++++++++++++++ run_flake8.sh | 3 -- run_mypy.sh | 10 ----- setup.py | 41 ++++--------------- 5 files changed, 124 insertions(+), 47 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml delete mode 100755 run_flake8.sh delete mode 100755 run_mypy.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..c21d665c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +default_language_version: + python: python3.11 + +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.9 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-added-large-files + - id: check-merge-conflict + - id: debug-statements + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.11.2 + hooks: + - id: mypy + additional_dependencies: [typing-extensions>=4.7.0] + args: [--config-file=pyproject.toml] + # Mirror run_mypy.sh: type-check the library and the examples directory. + files: ^(bitcointx|examples)/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..e8627b1f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,87 @@ +[build-system] +requires = ["setuptools>=68.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "python-bitcointx" +description = "A library for handling Bitcoin transactions and associated data" +readme = "README.md" +requires-python = ">=3.11" +license = {text = "LGPL-3.0-or-later"} +keywords = ["bitcoin"] +classifiers = [ + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", + "Topic :: Security :: Cryptography", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dynamic = ["version"] +# Runtime dependencies: none. Native dependencies (loaded at runtime via ctypes): +# - libsecp256k1 >= 0.3.0 and < 1.0.0 (tested with 0.4.0; 0.7.0+ supported via +# compatibility shim that detects both the old `secp256k1_ec_privkey_*` +# and the new `secp256k1_ec_seckey_*` symbol names). +# - libbitcoinconsensus (optional). +dependencies = [] + +[project.urls] +Homepage = "https://github.com/Simplexum/python-bitcointx" +Issues = "https://github.com/Simplexum/python-bitcointx/issues" + +[project.optional-dependencies] +dev = [ + "pytest>=7.4.0", + "coverage>=7.0.0", + "ruff>=0.6.0", + "mypy>=1.10.0", + "typing-extensions>=4.7.0", + "pre-commit>=3.7.0", +] + +[tool.setuptools.dynamic] +version = {attr = "bitcointx.__version__"} + +[tool.setuptools.packages.find] +include = ["bitcointx*"] + +[tool.setuptools.package-data] +bitcointx = ["py.typed"] + +[tool.ruff] +line-length = 100 +target-version = "py311" +extend-exclude = ["doc", "build", "dist"] + +[tool.ruff.lint] +# Conservative starting set, keeping diffs small on legacy code. +select = ["E", "F", "I", "W", "UP", "B"] +ignore = [ + "E501", # line too long (long lines exist in legacy code and crypto tables) + "E741", # ambiguous variable names (used in cryptographic spec translations) + "B008", # do not perform function call in argument defaults + "B904", # raise from ... (legacy code raises plain exceptions) + "UP006", # PEP 585 syntax (kept consistent with existing typing imports) + "UP007", # PEP 604 syntax (same reason) + "UP035", # deprecated import (typing aliases used intentionally) +] + +[tool.ruff.lint.per-file-ignores] +"bitcointx/core/_ripemd160.py" = ["E226", "E741"] +"bitcointx/core/sha256.py" = ["E226", "E741"] +"bitcointx/tests/*" = ["B011"] + +[tool.mypy] +python_version = "3.11" +strict = true +files = ["bitcointx", "examples"] +warn_unused_ignores = true +warn_redundant_casts = true +show_error_codes = true + +[tool.pytest.ini_options] +testpaths = ["bitcointx/tests"] +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] diff --git a/run_flake8.sh b/run_flake8.sh deleted file mode 100755 index 543b6171..00000000 --- a/run_flake8.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec flake8 --ignore E501,E221,E226,W503,W504 --exclude "./doc/*" diff --git a/run_mypy.sh b/run_mypy.sh deleted file mode 100755 index 6443726f..00000000 --- a/run_mypy.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env sh -#-*-mode: sh; encoding: utf-8-*- - -_MY_DIR="$( cd "$( dirname "${0}" )" && pwd )" -set -ex -[ -d "${_MY_DIR}" ] -[ "${_MY_DIR}/run_mypy.sh" -ef "${0}" ] -cd "${_MY_DIR}" - -mypy --strict ./bitcointx ./examples diff --git a/setup.py b/setup.py index 6405ac01..1e128064 100755 --- a/setup.py +++ b/setup.py @@ -1,37 +1,10 @@ -#!/usr/bin/env python +"""Legacy setup shim. -import os +All project metadata lives in ``pyproject.toml``. This file remains only so +that ``python setup.py `` invocations continue to work for tools that +have not yet switched to the PEP 517 build interface. +""" -from setuptools import setup, find_packages +from setuptools import setup -from bitcointx import __version__ - -here = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(here, 'README.md')) as f: - README = f.read() - -requires = [] - -setup( - name='python-bitcointx', - version=__version__, - description='A library for handling Bitcoin transactions and associated data', - long_description=README, - long_description_content_type='text/markdown', - classifiers=[ - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", - ], - python_requires='>=3.7', - url='https://github.com/Simplexum/python-bitcointx', - keywords='bitcoin', - packages=find_packages(), - zip_safe=False, - install_requires=requires, - test_suite="bitcointx.tests", - package_data={"bitcointx": ["py.typed"]} -) +setup()