diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 21321b0..97159df 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -1,4 +1,6 @@ name: Python package +env: + PYTHON_VERSION: 3.8 on: push: @@ -12,10 +14,10 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Install dependencies run: | python -m pip install black isort flake8 bandit[toml] @@ -29,14 +31,14 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 with: submodules: true - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: python-version: ${{ matrix.python-version }} - name: Install @@ -57,19 +59,19 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 with: submodules: true - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Install dependencies run: | python -m pip install setuptools wheel cython cibuildwheel==2.3.0 - name: Build wheels run: | python -m cibuildwheel --output-dir wheelhouse - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v7 with: path: ./wheelhouse/*.whl @@ -80,19 +82,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 with: submodules: true - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: - python-version: 3.8 + python-version: ${{ env.PYTHON_VERSION }} - name: Install dependencies run: | python -m pip install build - name: Build dists run: | python -m build --sdist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v7 with: path: dist/*.tar.gz @@ -105,7 +107,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v8 with: name: artifact path: dist diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61a144c..a30d201 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-json - id: check-toml @@ -15,44 +15,44 @@ repos: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.13.0 + rev: v2.16.0 hooks: - id: pretty-format-yaml args: [--autofix] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.7.0 + rev: v2.25.3 hooks: - id: pyproject-fmt - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.3 + rev: v22.1.8 hooks: - id: clang-format - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.21.2 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/MarcoGorelli/cython-lint - rev: v0.16.2 + rev: v0.21.0 hooks: - id: cython-lint - id: double-quote-cython-strings - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.4.0 + rev: 26.5.1 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.13.2 + rev: 8.0.1 hooks: - id: isort - repo: https://github.com/PyCQA/bandit - rev: 1.7.8 + rev: 1.9.4 hooks: - id: bandit args: [-c, pyproject.toml] additional_dependencies: ['.[toml]'] - repo: https://github.com/pycqa/flake8 - rev: 7.0.0 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: @@ -62,6 +62,10 @@ repos: - flake8-mutable - flake8-simplify - repo: https://github.com/Yelp/detect-secrets - rev: v1.4.0 + rev: v1.5.0 hooks: - id: detect-secrets +- repo: https://github.com/tox-dev/tox-ini-fmt + rev: 1.8.0 + hooks: + - id: tox-ini-fmt diff --git a/MANIFEST.in b/MANIFEST.in index 8ec70e6..85363e2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include MetroHash/src/*.h -global-include *.pyx +recursive-include src/metrohash *.pyx *.pyi py.typed diff --git a/README.md b/README.md index 64b854e..0402edd 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Python bindings for the fast non-cryptograpical hash function MetroHash. MetroHa ## Requirements -The library has been tested on Linux Python 3.6, and on Windows Python 3.6, 3.7. +The library has been tested on Linux Python ^3.7, and on Windows Python ^3.7. ## Install -``` +```console pip install metrohash-python ``` diff --git a/setup.py b/setup.py index 483dd16..6b45b0e 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ "MetroHash/src/metrohash128.cpp", ] -INT_SOURCES = ["metrohash.pyx"] +INT_SOURCES = ["src/metrohash/_metrohash.pyx"] machine = platform.machine().lower() x86 = ("x86_64", "amd64", "i386", "x86", "i686") @@ -27,7 +27,7 @@ extensions = [ Extension( - "metrohash", + "metrohash._metrohash", sources=EXT_SOURCES + INT_SOURCES, extra_compile_args=cflags, include_dirs=["MetroHash/src"], @@ -41,7 +41,7 @@ setup( author="Dobatymo", name="metrohash-python", - version="1.1.3.3", + version="1.1.3.4", url="https://github.com/Dobatymo/metrohash-python", description="Python bindings for MetroHash", long_description=long_description, @@ -62,4 +62,13 @@ ext_modules=cythonize(extensions), python_requires=">=3.7", zip_safe=False, + package_dir={"": "src"}, + packages=["metrohash"], + package_data={ + "metrohash": ["*.pyi", "py.typed"], + }, + exclude_package_data={ + "metrohash": ["*.pyx", "*.cpp", "*.c"], + }, + include_package_data=True, ) diff --git a/src/metrohash/__init__.py b/src/metrohash/__init__.py new file mode 100644 index 0000000..af46b38 --- /dev/null +++ b/src/metrohash/__init__.py @@ -0,0 +1,8 @@ +from ._metrohash import MetroHash64, MetroHash128, metrohash64, metrohash128 + +__all__ = [ + "MetroHash128", + "MetroHash64", + "metrohash128", + "metrohash64", +] diff --git a/src/metrohash/__init__.pyi b/src/metrohash/__init__.pyi new file mode 100644 index 0000000..794605f --- /dev/null +++ b/src/metrohash/__init__.pyi @@ -0,0 +1,42 @@ +import typing as t + +from _typeshed import ReadableBuffer + +__all__: t.Final[t.List[str]] = [ + "MetroHash128", + "MetroHash64", + "metrohash128", + "metrohash64", +] + +def metrohash128(data: ReadableBuffer, seed: int = 0) -> bytes: ... +def metrohash64(data: ReadableBuffer, seed: int = 0) -> bytes: ... +@t.final +class MetroHash128: + @property + def block_size(self) -> int: ... + @property + def digest_size(self) -> int: ... + @property + def name(self) -> str: ... + @classmethod + def __init__(cls, *, seed: int = 0) -> None: ... + def copy(self) -> MetroHash128: ... + def digest(self) -> bytes: ... + def hexdigest(self) -> str: ... + def update(self, data: ReadableBuffer) -> None: ... + +@t.final +class MetroHash64: + @property + def block_size(self) -> int: ... + @property + def digest_size(self) -> int: ... + @property + def name(self) -> str: ... + @classmethod + def __init__(cls, *, seed: int = 0) -> None: ... + def copy(self) -> MetroHash64: ... + def digest(self) -> bytes: ... + def hexdigest(self) -> str: ... + def update(self, data: ReadableBuffer) -> None: ... diff --git a/metrohash.pyx b/src/metrohash/_metrohash.pyx similarity index 100% rename from metrohash.pyx rename to src/metrohash/_metrohash.pyx diff --git a/src/metrohash/py.typed b/src/metrohash/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini index 0361504..52ab4ea 100644 --- a/tox.ini +++ b/tox.ini @@ -1,3 +1,14 @@ +[tox] +requires = + tox>=4.2 +env_list = + py3.{15, 14, 13, 12, 11, 10, 9, 8, 7} +skip_missing_interpreters = true + +[testenv] +commands = + python -m unittest discover -s tests + [flake8] max-line-length = 120 select = B, E7, E9, W2, W3, W6, F