Skip to content

Commit

Permalink
ruff action
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Dec 26, 2024
1 parent 7f06b1c commit 8e081b5
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 78 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-cov
python -m pip install pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 probables/ --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 probables/ --count --exit-zero --max-complexity=11 --max-line-length=127 --statistics
- name: Test with pytest
run: |
# Run tests while also generating coverage statistics
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Ruff
on: [workflow_dispatch, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.13"
- uses: astral-sh/ruff-action@v3
with:
args: "check --fix"
continue-on-error: false
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ keywords:
- Counting Cuckoo Filter
- Quotient Filter
license: MIT
version: 0.6.0
date-released: '2024-01-10'
version: 0.6.1
date-released: '2024-12-20'
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To install `pyprobables`, simply clone the `repository on GitHub

$ python setup.py install

`pyprobables` supports python 3.6 - 3.11+
`pyprobables` supports python 3.8 - 3.13+

For *python 2.7* support, install `release 0.3.2 <https://github.com/barrust/pyprobables/releases/tag/v0.3.2>`__

Expand Down
14 changes: 7 additions & 7 deletions tests/bloom_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,11 +13,11 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import BloomFilter, BloomFilterOnDisk
from probables.constants import UINT64_T_MAX
from probables.exceptions import InitializationError, NotSupportedError
from probables.hashes import hash_with_depth_int
from tests.utilities import calc_file_md5, different_hash
from probables import BloomFilter, BloomFilterOnDisk # noqa: E402
from probables.constants import UINT64_T_MAX # noqa: E402
from probables.exceptions import InitializationError, NotSupportedError # noqa: E402
from probables.hashes import hash_with_depth_int # noqa: E402
from tests.utilities import calc_file_md5, different_hash # noqa: E402

DELETE_TEMP_FILES = True

Expand Down Expand Up @@ -714,7 +714,7 @@ def test_bfod_close_del(self):
blm.add("this is a test")
del blm
try:
self.assertEqual(True, blm)
self.assertEqual(True, blm) # noqa: F821
except UnboundLocalError as ex:
msg1 = "local variable 'blm' referenced before assignment"
msg2 = "cannot access local variable 'blm' where it is not associated with a value"
Expand Down
8 changes: 4 additions & 4 deletions tests/countingbloom_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,9 +13,9 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import CountingBloomFilter
from probables.exceptions import InitializationError
from tests.utilities import calc_file_md5, different_hash
from probables import CountingBloomFilter # noqa: E402
from probables.exceptions import InitializationError # noqa: E402
from tests.utilities import calc_file_md5, different_hash # noqa: E402

DELETE_TEMP_FILES = True

Expand Down
6 changes: 3 additions & 3 deletions tests/countingcuckoo_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,8 +13,8 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import CountingCuckooFilter, CuckooFilterFullError
from tests.utilities import calc_file_md5
from probables import CountingCuckooFilter, CuckooFilterFullError # noqa: E402
from tests.utilities import calc_file_md5 # noqa: E402

DELETE_TEMP_FILES = True

Expand Down
10 changes: 5 additions & 5 deletions tests/countminsketch_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,10 +13,10 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import CountMeanMinSketch, CountMeanSketch, CountMinSketch, HeavyHitters, StreamThreshold
from probables.constants import INT32_T_MAX, INT32_T_MIN, INT64_T_MAX, INT64_T_MIN
from probables.exceptions import CountMinSketchError, InitializationError, NotSupportedError
from tests.utilities import calc_file_md5, different_hash
from probables import CountMeanMinSketch, CountMeanSketch, CountMinSketch, HeavyHitters, StreamThreshold # noqa: E402
from probables.constants import INT32_T_MAX, INT32_T_MIN, INT64_T_MAX, INT64_T_MIN # noqa: E402
from probables.exceptions import CountMinSketchError, InitializationError, NotSupportedError # noqa: E402
from tests.utilities import calc_file_md5, different_hash # noqa: E402

DELETE_TEMP_FILES = True

Expand Down
6 changes: 3 additions & 3 deletions tests/cuckoo_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,8 +13,8 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import CuckooFilter, CuckooFilterFullError, InitializationError
from tests.utilities import calc_file_md5
from probables import CuckooFilter, CuckooFilterFullError, InitializationError # noqa: E402
from tests.utilities import calc_file_md5 # noqa: E402

DELETE_TEMP_FILES = True

Expand Down
8 changes: 4 additions & 4 deletions tests/expandingbloom_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
Expand All @@ -13,9 +13,9 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables import ExpandingBloomFilter, RotatingBloomFilter
from probables.exceptions import RotatingBloomFilterError
from tests.utilities import calc_file_md5, different_hash
from probables import ExpandingBloomFilter, RotatingBloomFilter # noqa: E402
from probables.exceptions import RotatingBloomFilterError # noqa: E402
from tests.utilities import calc_file_md5, different_hash # noqa: E402

DELETE_TEMP_FILES = True

Expand Down
6 changes: 3 additions & 3 deletions tests/hashes_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import sys
Expand All @@ -11,8 +11,8 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables.constants import UINT64_T_MAX
from probables.hashes import (
from probables.constants import UINT64_T_MAX # noqa: E402
from probables.hashes import ( # noqa: E402
default_fnv_1a,
default_md5,
default_sha256,
Expand Down
70 changes: 34 additions & 36 deletions tests/quotientfilter_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Unittest class """
"""Unittest class"""

import hashlib
import os
import random
import sys
Expand All @@ -15,8 +14,7 @@
this_dir = Path(__file__).parent
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))
from probables import QuotientFilter
from tests.utilities import calc_file_md5, different_hash
from probables import QuotientFilter # noqa: E402

DELETE_TEMP_FILES = True

Expand Down Expand Up @@ -242,8 +240,8 @@ def test_qf_remove_missing_elm(self):
"""test removing a missing element"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("~")

Expand All @@ -258,8 +256,8 @@ def test_qf_remove_cluster_start(self):
"""test removing a cluster start followed by empty"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove(".")

Expand All @@ -274,8 +272,8 @@ def test_qf_remove_cluster_start_cluster(self):
"""test removing a cluster start followed by cluster start"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("-")

Expand All @@ -290,8 +288,8 @@ def test_qf_remove_shifted_run_start_followed_by_empty(self):
"""test removing a shifted run start followed by empty"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("z")

Expand All @@ -306,8 +304,8 @@ def test_qf_remove_shifted_run_start_followed_continuation(self):
"""test removing a shifted run start followed by continuation"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("y")

Expand All @@ -322,8 +320,8 @@ def test_qf_remove_shifted_continuation_followed_run_start(self):
"""test removing a shifted continuation followed by run start"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("x")

Expand All @@ -338,8 +336,8 @@ def test_qf_remove_shifted_run_start_followed_run_start(self):
"""test removing a shifted run start followed by run start"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("a")

Expand All @@ -354,8 +352,8 @@ def test_qf_remove_cluster_start_followed_continuation_follow_run_start(self):
"""test removing a cluster start followed by continuation putting a run start into a cluster start position"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

qf.remove("d")

Expand All @@ -370,13 +368,13 @@ def test_qf_remove_full(self):
"""Test removing all elements, but find each one after each removal"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
_hash = qf._hash_func(l, 0)
print(l, _hash >> qf._r, _hash & ((1 << qf._r) - 1))
qf.add(l)
for a in alpha:
# _hash = qf._hash_func(a, 0)
# print(a, _hash >> qf._r, _hash & ((1 << qf._r) - 1))
qf.add(a)

for l in alpha:
self.assertTrue(qf.check(l), "failed to insert")
for a in alpha:
self.assertTrue(qf.check(a), "failed to insert")

while alpha:
missing_vals = []
Expand All @@ -393,11 +391,11 @@ def test_qf_remove_full_random(self):
"""Test removing all elements, but in a random order"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

for l in alpha:
self.assertTrue(qf.check(l), "failed to insert")
for a in alpha:
self.assertTrue(qf.check(a), "failed to insert")
self.assertTrue(qf.validate_metadata())

while alpha:
Expand All @@ -416,11 +414,11 @@ def test_qf_remove_full_random_take_2(self):
"""Test removing all elements, but in a random order - take 2"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

for l in alpha:
self.assertTrue(qf.check(l), "failed to insert")
for a in alpha:
self.assertTrue(qf.check(a), "failed to insert")

while alpha:
missing_vals = []
Expand Down Expand Up @@ -452,8 +450,8 @@ def test_quotient_filter_print(self):
"""Test printing the data of a quotient filter in a manner to be read through not empty"""
alpha = [a for a in "abcd.efghij;klm-nopqrs=tuvwxyz"]
qf = QuotientFilter(quotient=7)
for l in alpha:
qf.add(l)
for a in alpha:
qf.add(a)

with NamedTemporaryFile(dir=os.getcwd(), suffix=".txt", delete=DELETE_TEMP_FILES, mode="wt") as fobj:
qf.print(file=fobj.file)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
""" probables utilitites tests """
"""probables utilitites tests"""

import os
import sys
Expand All @@ -11,8 +11,8 @@
sys.path.insert(0, str(this_dir))
sys.path.insert(0, str(this_dir.parent))

from probables.utilities import Bitarray, MMap, get_x_bits, is_hex_string, is_valid_file, resolve_path
from tests.utilities import different_hash
from probables.utilities import Bitarray, MMap, get_x_bits, is_hex_string, is_valid_file, resolve_path # noqa: E402
from tests.utilities import different_hash # noqa: E402

DELETE_TEMP_FILES = True

Expand Down

0 comments on commit 8e081b5

Please sign in to comment.