Skip to content

Commit 1865fb7

Browse files
committed
build everything with avx
add more formatters and linters
1 parent 1319fc5 commit 1865fb7

File tree

7 files changed

+150
-94
lines changed

7 files changed

+150
-94
lines changed

.github/workflows/pythonpackage.yml

+40-29
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,47 @@ on:
55
pull_request:
66
release:
77
types:
8-
- published
8+
- published
99

1010
jobs:
11-
test:
11+
lint:
12+
runs-on: ubuntu-20.04
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: 3.8
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install black isort flake8 bandit[toml]
22+
- run: python -m black . --check
23+
- run: python -m isort . --check-only
24+
- run: python -m flake8 .
25+
- run: python -m bandit . --recursive -c pyproject.toml
1226

27+
test:
28+
needs: lint
1329
strategy:
1430
matrix:
1531
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
32+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
1733
runs-on: ${{ matrix.os }}
1834

1935
steps:
20-
- uses: actions/checkout@v2
36+
- uses: actions/checkout@v4
2137
with:
2238
submodules: true
23-
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v2
39+
- uses: actions/setup-python@v5
2540
with:
2641
python-version: ${{ matrix.python-version }}
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install setuptools wheel cython
30-
- name: Build
42+
- name: Install
3143
run: |
32-
python setup.py build_ext --inplace
44+
python -m pip install .
3345
- name: Run tests
3446
run: |
35-
python test.py
47+
cd tests
48+
python -m unittest discover
3649
3750
build-wheels:
3851
if: github.event_name == 'release' && github.event.action == 'published'
@@ -44,11 +57,10 @@ jobs:
4457
runs-on: ${{ matrix.os }}
4558

4659
steps:
47-
- uses: actions/checkout@v2
60+
- uses: actions/checkout@v4
4861
with:
4962
submodules: true
50-
- name: Set up Python ${{ matrix.python-version }}
51-
uses: actions/setup-python@v2
63+
- uses: actions/setup-python@v5
5264
with:
5365
python-version: 3.8
5466
- name: Install dependencies
@@ -68,20 +80,19 @@ jobs:
6880
runs-on: ubuntu-latest
6981

7082
steps:
71-
- uses: actions/checkout@v2
83+
- uses: actions/checkout@v4
7284
with:
7385
submodules: true
74-
- name: Set up Python 3.8
75-
uses: actions/setup-python@v2
86+
- uses: actions/setup-python@v5
7687
with:
7788
python-version: 3.8
7889
- name: Install dependencies
7990
run: |
80-
python -m pip install setuptools cython
91+
python -m pip install build
8192
- name: Build dists
8293
run: |
83-
python setup.py sdist
84-
- uses: actions/upload-artifact@v2
94+
python -m build --sdist
95+
- uses: actions/upload-artifact@v3
8596
with:
8697
path: dist/*.tar.gz
8798

@@ -94,12 +105,12 @@ jobs:
94105
runs-on: ubuntu-latest
95106

96107
steps:
97-
- uses: actions/download-artifact@v2
98-
with:
99-
name: artifact
100-
path: dist
108+
- uses: actions/download-artifact@v2
109+
with:
110+
name: artifact
111+
path: dist
101112

102-
- uses: pypa/gh-action-pypi-publish@master
103-
with:
104-
user: __token__
105-
password: ${{ secrets.pypi_password }}
113+
- uses: pypa/gh-action-pypi-publish@release/v1
114+
with:
115+
user: __token__
116+
password: ${{ secrets.pypi_password }}

.pre-commit-config.yaml

+66-34
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,67 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
4-
hooks:
5-
- id: check-json
6-
- id: check-toml
7-
- id: check-yaml
8-
- id: check-case-conflict
9-
- id: check-added-large-files
10-
- id: debug-statements
11-
- id: end-of-file-fixer
12-
- id: mixed-line-ending
13-
args: ["--fix=no"]
14-
- id: requirements-txt-fixer
15-
- id: trailing-whitespace
16-
args: ["--markdown-linebreak-ext=md"]
17-
- repo: https://github.com/asottile/pyupgrade
18-
rev: 'v2.29.1'
19-
hooks:
20-
- id: pyupgrade
21-
args: ["--py36-plus"]
22-
- repo: https://github.com/psf/black
23-
rev: '21.11b1'
24-
hooks:
25-
- id: black
26-
language_version: python3 # Should be a command that runs python3.6+
27-
- repo: https://github.com/PyCQA/isort
28-
rev: '5.10.1'
29-
hooks:
30-
- id: isort
31-
language_version: python3
32-
- repo: https://gitlab.com/pycqa/flake8
33-
rev: 4.0.1
34-
hooks:
35-
- id: flake8
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-json
6+
- id: check-toml
7+
- id: check-yaml
8+
- id: check-case-conflict
9+
- id: check-added-large-files
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
- id: mixed-line-ending
13+
args: [--fix=no]
14+
- id: requirements-txt-fixer
15+
- id: trailing-whitespace
16+
args: [--markdown-linebreak-ext=md]
17+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
18+
rev: v2.13.0
19+
hooks:
20+
- id: pretty-format-yaml
21+
args: [--autofix]
22+
- repo: https://github.com/tox-dev/pyproject-fmt
23+
rev: 1.7.0
24+
hooks:
25+
- id: pyproject-fmt
26+
- repo: https://github.com/pre-commit/mirrors-clang-format
27+
rev: v18.1.3
28+
hooks:
29+
- id: clang-format
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: v3.15.2
32+
hooks:
33+
- id: pyupgrade
34+
args: [--py37-plus]
35+
- repo: https://github.com/MarcoGorelli/cython-lint
36+
rev: v0.16.2
37+
hooks:
38+
- id: cython-lint
39+
- id: double-quote-cython-strings
40+
- repo: https://github.com/psf/black-pre-commit-mirror
41+
rev: 24.4.0
42+
hooks:
43+
- id: black
44+
- repo: https://github.com/PyCQA/isort
45+
rev: 5.13.2
46+
hooks:
47+
- id: isort
48+
- repo: https://github.com/PyCQA/bandit
49+
rev: 1.7.8
50+
hooks:
51+
- id: bandit
52+
args: [-c, pyproject.toml]
53+
additional_dependencies: ['.[toml]']
54+
- repo: https://github.com/pycqa/flake8
55+
rev: 7.0.0
56+
hooks:
57+
- id: flake8
58+
additional_dependencies:
59+
- flake8-annotations
60+
- flake8-bugbear
61+
- flake8-eradicate
62+
- flake8-mutable
63+
- flake8-simplify
64+
- repo: https://github.com/Yelp/detect-secrets
65+
rev: v1.4.0
66+
hooks:
67+
- id: detect-secrets

metrohash.pyx

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# distutils: language=c++
22

3-
import sys
4-
53
from cython.operator cimport dereference as deref
64
from libc.stdint cimport uint8_t, uint64_t
7-
from libcpp cimport bool
85

96

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

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

32-
if sys.version_info < (3, ):
33-
def bytes2hex(b):
34-
return b.encode("hex")
35-
else:
36-
def bytes2hex(b):
37-
return b.hex()
38-
3929
cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL):
4030

4131
cdef bytearray out = bytearray(8)
@@ -91,7 +81,7 @@ cdef class MetroHash64(object):
9181
return bytes(_hash)
9282

9383
def hexdigest(self):
94-
return bytes2hex(self.digest())
84+
return self.digest().hex()
9585

9686
def copy(self):
9787
return MetroHash64(self)
@@ -139,7 +129,7 @@ cdef class MetroHash128(object):
139129
return bytes(_hash)
140130

141131
def hexdigest(self):
142-
return bytes2hex(self.digest())
132+
return self.digest().hex()
143133

144134
def copy(self):
145135
return MetroHash128(self)

pyproject.toml

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "Cython"]
2+
requires = [
3+
"Cython",
4+
"setuptools",
5+
"wheel",
6+
]
37

48
[tool.black]
59
line-length = 120
610

11+
[tool.ruff]
12+
line-length = 120
13+
714
[tool.isort]
815
profile = "black"
9-
src_paths = ["."]
1016
line_length = 120
17+
18+
[tool.mypy]
19+
allow_redefinition = true
20+
warn_unused_configs = true
21+
warn_unused_ignores = true
22+
23+
[tool.bandit]
24+
skips = ["B101"]
25+
26+
[tool.cython-lint]
27+
max-line-length = 120
28+
ignore = ["W191"]

setup.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111

1212
INT_SOURCES = ["metrohash.pyx"]
1313

14+
machine = platform.machine().lower()
15+
x86 = ("x86_64", "amd64", "i386", "x86", "i686")
16+
1417
if sys.platform == "win32":
15-
cflags = ["/O2", "/arch:AVX2"]
18+
if machine in x86:
19+
cflags = ["/O2", "/arch:AVX"]
20+
else:
21+
cflags = ["/O2"]
1622
else:
17-
if platform.machine().lower() in ("x86_64", "amd64"):
18-
cflags = ["-O3", "-msse4.2"]
23+
if machine in x86:
24+
cflags = ["-O2", "-mavx"]
1925
else:
20-
cflags = ["-O3", "-march=native"]
26+
cflags = ["-O2"]
2127

2228
extensions = [
2329
Extension(
@@ -54,7 +60,6 @@
5460
"Topic :: Utilities",
5561
],
5662
ext_modules=cythonize(extensions),
57-
python_requires=">=3.6",
58-
use_2to3=False,
63+
python_requires=">=3.7",
5964
zip_safe=False,
6065
)

0 commit comments

Comments
 (0)