Skip to content

Commit

Permalink
build everything with avx
Browse files Browse the repository at this point in the history
add more formatters and linters
  • Loading branch information
Dobatymo committed Apr 15, 2024
1 parent 1319fc5 commit 1865fb7
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 94 deletions.
69 changes: 40 additions & 29 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,47 @@ on:
pull_request:
release:
types:
- published
- published

jobs:
test:
lint:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install black isort flake8 bandit[toml]
- run: python -m black . --check
- run: python -m isort . --check-only
- run: python -m flake8 .
- run: python -m bandit . --recursive -c pyproject.toml

test:
needs: lint
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install setuptools wheel cython
- name: Build
- name: Install
run: |
python setup.py build_ext --inplace
python -m pip install .
- name: Run tests
run: |
python test.py
cd tests
python -m unittest discover
build-wheels:
if: github.event_name == 'release' && github.event.action == 'published'
Expand All @@ -44,11 +57,10 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
Expand All @@ -68,20 +80,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.8
uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install setuptools cython
python -m pip install build
- name: Build dists
run: |
python setup.py sdist
- uses: actions/upload-artifact@v2
python -m build --sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

Expand All @@ -94,12 +105,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
100 changes: 66 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,67 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: check-case-conflict
- id: check-added-large-files
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=no"]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: ["--markdown-linebreak-ext=md"]
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.29.1'
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/psf/black
rev: '21.11b1'
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/PyCQA/isort
rev: '5.10.1'
hooks:
- id: isort
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: check-case-conflict
- id: check-added-large-files
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=no]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-yaml
args: [--autofix]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.7.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.3
hooks:
- id: clang-format
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.2
hooks:
- id: cython-lint
- id: double-quote-cython-strings
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
hooks:
- id: bandit
args: [-c, pyproject.toml]
additional_dependencies: ['.[toml]']
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-annotations
- flake8-bugbear
- flake8-eradicate
- flake8-mutable
- flake8-simplify
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
14 changes: 2 additions & 12 deletions metrohash.pyx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# distutils: language=c++

import sys

from cython.operator cimport dereference as deref
from libc.stdint cimport uint8_t, uint64_t
from libcpp cimport bool


cdef extern from "metrohash.h" nogil:
Expand All @@ -29,13 +26,6 @@ cdef extern from "metrohash.h" nogil:

__all__ = ["MetroHash128", "MetroHash64", "metrohash128", "metrohash64"]

if sys.version_info < (3, ):
def bytes2hex(b):
return b.encode("hex")
else:
def bytes2hex(b):
return b.hex()

cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL):

cdef bytearray out = bytearray(8)
Expand Down Expand Up @@ -91,7 +81,7 @@ cdef class MetroHash64(object):
return bytes(_hash)

def hexdigest(self):
return bytes2hex(self.digest())
return self.digest().hex()

def copy(self):
return MetroHash64(self)
Expand Down Expand Up @@ -139,7 +129,7 @@ cdef class MetroHash128(object):
return bytes(_hash)

def hexdigest(self):
return bytes2hex(self.digest())
return self.digest().hex()

def copy(self):
return MetroHash128(self)
22 changes: 20 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
[build-system]
requires = ["setuptools", "wheel", "Cython"]
requires = [
"Cython",
"setuptools",
"wheel",
]

[tool.black]
line-length = 120

[tool.ruff]
line-length = 120

[tool.isort]
profile = "black"
src_paths = ["."]
line_length = 120

[tool.mypy]
allow_redefinition = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.bandit]
skips = ["B101"]

[tool.cython-lint]
max-line-length = 120
ignore = ["W191"]
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

INT_SOURCES = ["metrohash.pyx"]

machine = platform.machine().lower()
x86 = ("x86_64", "amd64", "i386", "x86", "i686")

if sys.platform == "win32":
cflags = ["/O2", "/arch:AVX2"]
if machine in x86:
cflags = ["/O2", "/arch:AVX"]
else:
cflags = ["/O2"]
else:
if platform.machine().lower() in ("x86_64", "amd64"):
cflags = ["-O3", "-msse4.2"]
if machine in x86:
cflags = ["-O2", "-mavx"]
else:
cflags = ["-O3", "-march=native"]
cflags = ["-O2"]

extensions = [
Extension(
Expand Down Expand Up @@ -54,7 +60,6 @@
"Topic :: Utilities",
],
ext_modules=cythonize(extensions),
python_requires=">=3.6",
use_2to3=False,
python_requires=">=3.7",
zip_safe=False,
)
Loading

0 comments on commit 1865fb7

Please sign in to comment.