From 8e081b5235bee31fd65f5401157c29391972c8fa Mon Sep 17 00:00:00 2001 From: barrust Date: Thu, 26 Dec 2024 16:19:10 -0500 Subject: [PATCH] ruff action --- .github/workflows/python-package.yml | 8 +--- .github/workflows/ruff.yml | 15 ++++++ CITATION.cff | 4 +- README.rst | 2 +- tests/bloom_test.py | 14 +++--- tests/countingbloom_test.py | 8 ++-- tests/countingcuckoo_test.py | 6 +-- tests/countminsketch_test.py | 10 ++-- tests/cuckoo_test.py | 6 +-- tests/expandingbloom_test.py | 8 ++-- tests/hashes_test.py | 6 +-- tests/quotientfilter_test.py | 70 ++++++++++++++-------------- tests/test_utilities.py | 6 +-- 13 files changed, 85 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index af26c51..5b38d19 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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 diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..3107abe --- /dev/null +++ b/.github/workflows/ruff.yml @@ -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 \ No newline at end of file diff --git a/CITATION.cff b/CITATION.cff index a8cefc2..614949e 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -32,5 +32,5 @@ keywords: - Counting Cuckoo Filter - Quotient Filter license: MIT -version: 0.6.0 -date-released: '2024-01-10' \ No newline at end of file +version: 0.6.1 +date-released: '2024-12-20' \ No newline at end of file diff --git a/README.rst b/README.rst index 1d0ff5c..f3cf7b3 100644 --- a/README.rst +++ b/README.rst @@ -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 `__ diff --git a/tests/bloom_test.py b/tests/bloom_test.py index 13e3733..3b6b0d8 100755 --- a/tests/bloom_test.py +++ b/tests/bloom_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 @@ -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" diff --git a/tests/countingbloom_test.py b/tests/countingbloom_test.py index aab6c6f..cb77d93 100755 --- a/tests/countingbloom_test.py +++ b/tests/countingbloom_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 diff --git a/tests/countingcuckoo_test.py b/tests/countingcuckoo_test.py index bb7fcf6..e600cbc 100755 --- a/tests/countingcuckoo_test.py +++ b/tests/countingcuckoo_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 diff --git a/tests/countminsketch_test.py b/tests/countminsketch_test.py index 085484d..33f81dc 100755 --- a/tests/countminsketch_test.py +++ b/tests/countminsketch_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 diff --git a/tests/cuckoo_test.py b/tests/cuckoo_test.py index edfffa5..b38fd00 100755 --- a/tests/cuckoo_test.py +++ b/tests/cuckoo_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 diff --git a/tests/expandingbloom_test.py b/tests/expandingbloom_test.py index e0ce310..357f345 100755 --- a/tests/expandingbloom_test.py +++ b/tests/expandingbloom_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import os @@ -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 diff --git a/tests/hashes_test.py b/tests/hashes_test.py index 0fa7cb7..9be3f31 100755 --- a/tests/hashes_test.py +++ b/tests/hashes_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" import hashlib import sys @@ -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, diff --git a/tests/quotientfilter_test.py b/tests/quotientfilter_test.py index 0171a54..c790ea4 100644 --- a/tests/quotientfilter_test.py +++ b/tests/quotientfilter_test.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" Unittest class """ +"""Unittest class""" -import hashlib import os import random import sys @@ -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 @@ -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("~") @@ -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(".") @@ -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("-") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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 = [] @@ -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: @@ -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 = [] @@ -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) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 11bcc3d..92ff724 100755 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -""" probables utilitites tests """ +"""probables utilitites tests""" import os import sys @@ -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