Repository: Adoni5/mappy-rs (language: python)

Issue:
Pre-commit
At some point I would like to set up pre-commit and rust-fmt and cargo test on hooks


Discussion / hints:

Fix patch:
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index a372eb1..ac6621f 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -9,4 +9,3 @@ updates:
     directory: "/" # Location of package manifests
     schedule:
       interval: "weekly"
-      
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index bcab1c1..32a801e 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -8,92 +8,134 @@ on:
     - cron:  '0 0 * * SUN'
 name: check
 jobs:
-  fmt:
+
+  pre-commit:
+    name: "pre-commit"
+    runs-on: "ubuntu-latest"
+    steps:
+      - uses: "actions/checkout@v3"
+      - uses: "actions/setup-python@v4"
+      - uses: "dtolnay/rust-toolchain@stable"
+      - uses: "pre-commit/action@v3.0.0"
+  # fmt:
+  #   runs-on: ubuntu-latest
+  #   name: stable / fmt
+  #   steps:
+  #     - uses: actions/checkout@v3
+  #       with:
+  #         submodules: true
+  #     - name: Install stable
+  #       uses: actions-rs/toolchain@v1
+  #       with:
+  #         profile: minimal
+  #         toolchain: stable
+  #         components: rustfmt
+  #     - name: cargo fmt --check
+  #       uses: actions-rs/cargo@v1
+  #       with:
+  #         command: fmt
+  #         args: --check
+  # clippy:
+  #   runs-on: ubuntu-latest
+  #   name: ${{ matrix.toolchain }} / clippy
+  #   strategy:
+  #     fail-fast: false
+  #     matrix:
+  #       toolchain: [stable, beta]
+  #   steps:
+  #     - uses: actions/checkout@v3
+  #       with:
+  #         submodules: true
+  #     - name: Install ${{ matrix.toolchain }}
+  #       uses: actions-rs/toolchain@v1
+  #       with:
+  #         profile: minimal
+  #         toolchain: ${{ matrix.toolchain }}
+  #         default: true
+  #         components: clippy
+  #     - name: cargo clippy
+  #       uses: actions-rs/clippy-check@v1
+  #       with:
+  #         token: ${{ secrets.GITHUB_TOKEN }}
+  # doc:
+  #   runs-on: ubuntu-latest
+  #   name: nightly / doc
+  #   steps:
+  #     - uses: actions/checkout@v3
+  #       with:
+  #         submodules: true
+  #     - name: Install nightly
+  #       uses: actions-rs/toolchain@v1
+  #       with:
+  #         profile: minimal
+  #         toolchain: nightly
+  #         default: true
+  #     - name: cargo doc
+  #       uses: actions-rs/cargo@v1
+  #       with:
+  #         command: doc
+  #         args: --no-deps --all-features
+  #       env:
+  #         RUSTDOCFLAGS: --cfg docsrs
+  # hack:
+  #   runs-on: ubuntu-latest
+  #   name: ubuntu / stable / features
+  #   steps:
+  #     - uses: actions/checkout@v3
+  #       with:
+  #         submodules: true
+  #     - name: Install stable
+  #       uses: actions-rs/toolchain@v1
+  #       with:
+  #         profile: minimal
+  #         toolchain: stable
+  #     - name: cargo install cargo-hack
+  #       uses: taiki-e/install-action@cargo-hack
+  #     - name: cargo hack
+  #       uses: actions-rs/cargo@v1
+  #       with:
+  #         command: hack
+  #         args: check --lib --tests --no-default-features
+  #     - name: cargo test
+  #       uses: actions-rs/cargo@v1
+  #       with:
+  #         command: hack
+  cargo-test:
+    name: cargo test
     runs-on: ubuntu-latest
-    name: stable / fmt
+    needs: pre-commit
     steps:
       - uses: actions/checkout@v3
-        with:
-          submodules: true
-      - name: Install stable
-        uses: actions-rs/toolchain@v1
-        with:
-          profile: minimal
-          toolchain: stable
-          components: rustfmt
-      - name: cargo fmt --check
-        uses: actions-rs/cargo@v1
-        with:
-          command: fmt
-          args: --check
-  clippy:
-    runs-on: ubuntu-latest
-    name: ${{ matrix.toolchain }} / clippy
+      - uses: dtolnay/rust-toolchain@stable
+      - run: cargo test --no-default-features
+
+  python-test:
+    name: "Test Python ${{ matrix.python-version }}"
+    runs-on: "ubuntu-latest"
+    needs: pre-commit
     strategy:
-      fail-fast: false
       matrix:
-        toolchain: [stable, beta]
-    steps:
-      - uses: actions/checkout@v3
-        with:
-          submodules: true
-      - name: Install ${{ matrix.toolchain }}
-        uses: actions-rs/toolchain@v1
-        with:
-          profile: minimal
-          toolchain: ${{ matrix.toolchain }}
-          default: true
-          components: clippy
-      - name: cargo clippy
-        uses: actions-rs/clippy-check@v1
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-  doc:
-    runs-on: ubuntu-latest
-    name: nightly / doc
-    steps:
-      - uses: actions/checkout@v3
-        with:
-          submodules: true
-      - name: Install nightly
-        uses: actions-rs/toolchain@v1
-        with:
-          profile: minimal
-          toolchain: nightly
-          default: true
-      - name: cargo doc
-        uses: actions-rs/cargo@v1
-        with:
-          command: doc
-          args: --no-deps --all-features
-        env:
-          RUSTDOCFLAGS: --cfg docsrs
-  hack:
-    runs-on: ubuntu-latest
-    name: ubuntu / stable / features
+        python-version: ["3.8", "3.9", "3.10", "3.11"]
+
     steps:
-      - uses: actions/checkout@v3
-        with:
-          submodules: true
-      - name: Install stable
-        uses: actions-rs/toolchain@v1
-        with:
-          profile: minimal
-          toolchain: stable
-      - name: cargo install cargo-hack
-        uses: taiki-e/install-action@cargo-hack
-      - name: cargo hack
-        uses: actions-rs/cargo@v1
-        with:
-          command: hack
-          args: check --lib --tests --no-default-features
-      - name: cargo test
-        uses: actions-rs/cargo@v1
+      - uses: "actions/checkout@v3"
+      - uses: "actions/setup-python@v4"
         with:
-          command: hack
-          args: test --no-default-features
+          python-version: "${{ matrix.python-version }}"
+      - uses: "dtolnay/rust-toolchain@stable"
+      - name: "Install dependencies"
+        run: |
+          set -xe
+          python -VV
+          python -m site
+          python -m pip install --upgrade pip
+          python -m pip install ".[tests]"
+      - name: "Run pytest for ${{ matrix.python-version }}"
+        run: "pytest"
+
   msrv:
     runs-on: ubuntu-latest
+    needs: [cargo-test, python-test]
     # we use a matrix here just because env can't be used in job names
     # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
     strategy:
@@ -114,25 +156,3 @@ jobs:
         uses: actions-rs/cargo@v1
         with:
           command: check
-
-  pytests:
-    name: "Test Python ${{ matrix.python-version }}"
-    runs-on: "ubuntu-latest"
-    strategy:
-      matrix:
-        python-version: ["3.8", "3.9", "3.10", "3.11"]
-
-    steps:
-      - uses: "actions/checkout@v3"
-      - uses: "actions/setup-python@v4"
-        with:
-          python-version: "${{ matrix.python-version }}"
-      - name: "Install dependencies"
-        run: |
-          set -xe
-          python -VV
-          python -m site
-          python -m pip install --upgrade pip
-          python -m pip install ".[tests]"
-      - name: "Run pytest for ${{ matrix.python-version }}"
-        run: "pytest"
diff --git a/.gitignore b/.gitignore
index d74feef..6d8d89b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -266,4 +266,4 @@ cython_debug/
 #  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 #  and can be added to the global gitignore or merged into this file.  For a more nuclear
 #  option (not recommended) you can uncomment the following to ignore the entire idea folder.
-#.idea/
\ No newline at end of file
+#.idea/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d2d6d0d..7bd08eb 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -24,5 +24,3 @@ repos:
         exclude: '(\.patch|\.diff|\.fasta$|\.fastq$|\.sam$|\.rbt$|\.bit$|target/)'
       - id: trailing-whitespace
         exclude: '(target/|\.patch|\.diff|\.fasta$|\.fastq$|\.sam$|\.rbt$|\.bit$)'
-
-
diff --git a/LICENSE.MD b/LICENSE.MD
index 57aee36..37fe8b0 100644
--- a/LICENSE.MD
+++ b/LICENSE.MD
@@ -21,4 +21,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
\ No newline at end of file
+SOFTWARE.
diff --git a/README.md b/README.md
index 748f193..90413c7 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ aligner = mappy_rs.Aligner("resources/test/test.mmi")
 aligner.enable_threading(10)
 ```
 
-Enabling threading makes the `map_batch` method available.  
+Enabling threading makes the `map_batch` method available.
 This method requires a list or iterable of dictionaries, which can have any number of keys and depth, but **must** contain the key `seq` with a string value in the top-level dictionary.
 
 For example:
@@ -62,7 +62,7 @@ import mappy_rs
 aligner = mappy_rs.Aligner("resources/test/test.mmi")
 aligner.enable_threading(10)
 seqs = [
-    {"seq": "ACGTAGCATCGAGACTACGA", "Other_random_key": "banter"}, 
+    {"seq": "ACGTAGCATCGAGACTACGA", "Other_random_key": "banter"},
     {"seq": "ACGTAGCATCGAGACTACGA", "Other_random_key": "banter"},
 ]
 for (mapping, data) in aligner.map_batch(seqs):
diff --git a/pyproject.toml b/pyproject.toml
index b350be8..02406df 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -35,3 +35,7 @@ features = ["pyo3/extension-module"]
 minversion = "6.0"
 addopts = "-ra"
 testpaths = ["tests"]
+
+[tool.black]
+line-length = 88
+target-version = ["py37"]


Test patch:
diff --git a/tests/python_test.py b/tests/python_test.py
index fada20c..e09eec6 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -1,7 +1,7 @@
 """python_test.py
 
-This set of tests roughly recreate those that are in lib.rs but use the compiled 
-package.
+This set of tests roughly recreate those that are in lib.rs but use the
+compiled package.
 """
 from pathlib import Path
 import copy
@@ -109,11 +109,12 @@ def test_property_seq_names(al):
 def test_get_seq(al):
     contig = "Bacillus_subtilis"
     expected = (
-        "AGAGTGAAGCCAATATTCCGATAACGATTGCTTTCATGATATCCCTCATTCTGGCATTATTTTTTTATACTATACTATTC"
-        "GATATCGCACAGATCAATGGAGTCGTGAGAAAATAAACATGTTTTGCGAACCGCTATGTGTGGAAGACAAAAAATGGAGG"
-        "TGAAATTGATGGAAGCAAAGACACAGGCGTACTTTTTTCAGGATGATGGCAGGATTCCGAATCACCCTGATTTTCCGCTC"
-        "GTTGTGTATCAAAACGCACTCAAGGACACCGGTCAGGCAGAGCGGATCGTCAACCGGCATGGCTGGTCAAACAGCTGGTC"
-        "GGGGAGTGTTTTTCCATACCATCATTATCACAGCAATACGCATGAAGTCCTGATTGCAGTTCGGGGAGAGGCTGTGATTC"
+        "AGAGTGAAGCCAATATTCCGATAACGATTGCTTTCATGATATCCCTCATTCTGGCATTATTTTTTTATA"
+        "CTATACTATTCGATATCGCACAGATCAATGGAGTCGTGAGAAAATAAACATGTTTTGCGAACCGCTATG"
+        "TGTGGAAGACAAAAAATGGAGGTGAAATTGATGGAAGCAAAGACACAGGCGTACTTTTTTCAGGATGAT"
+        "GGCAGGATTCCGAATCACCCTGATTTTCCGCTCGTTGTGTATCAAAACGCACTCAAGGACACCGGTCAG"
+        "GCAGAGCGGATCGTCAACCGGCATGGCTGGTCAAACAGCTGGTCGGGGAGTGTTTTTCCATACCATCAT"
+        "TATCACAGCAATACGCATGAAGTCCTGATTGCAGTTCGGGGAGAGGCTGTGATTC"
     )
     seq = al.seq(contig)
     assert seq == expected
@@ -121,11 +122,12 @@ def test_get_seq(al):
 
 def test_map_one(al):
     mappings = al.map(
-        "AGAGCAGGTAGGATCGTTGAAAAAAGAGTACTCAGGATTCCATTCAACTTTTACTGATTTGAAGCGTACTGTTTATGGCC"
-        "AAGAATATTTACGTCTTTACAACCAATACGCAAAAAAAGGTTCATTGAGTTTGGTTGTGATTTGATGAAAATTACTGAGA"
-        "ATAACAGGATTATTAAGCTGATTGATGAACTAAATCAGCTTAATAAATATTCTTTGCAGATAGGAATATTTGGGGAAAAT"
-        "GATTCTTTTATGGCGATGTTGGCCCAAGTTCATGAATTTGGGGTGACTATTCGTCCCAAAGGTCGTTTTCTTGTTATACC"
-        "ACTTATGAAAAAGTATAGAGGTAAAAGTCCACGTCAATTTGATTTGTTTTTTATGCAAACTAAAGAAAATCACAAGTTTT",
+        "AGAGCAGGTAGGATCGTTGAAAAAAGAGTACTCAGGATTCCATTCAACTTTTACTGATTTGAAGCGTAC"
+        "TGTTTATGGCCAAGAATATTTACGTCTTTACAACCAATACGCAAAAAAAGGTTCATTGAGTTTGGTTGT"
+        "GATTTGATGAAAATTACTGAGAATAACAGGATTATTAAGCTGATTGATGAACTAAATCAGCTTAATAAA"
+        "TATTCTTTGCAGATAGGAATATTTGGGGAAAATGATTCTTTTATGGCGATGTTGGCCCAAGTTCATGAA"
+        "TTTGGGGTGACTATTCGTCCCAAAGGTCGTTTTCTTGTTATACCACTTATGAAAAAGTATAGAGGTAAA"
+        "AGTCCACGTCAATTTGATTTGTTTTTTATGCAAACTAAAGAAAATCACAAGTTTT",
         cs=True,
     )
     assert len(mappings) == 1
@@ -152,25 +154,25 @@ def test_map_batch_fail_dict_single(al, fasta_iter):
     fasta = next(fasta_iter)
     al.enable_threading(2)
     with pytest.raises(TypeError) as excinfo:
-        mappings = al.map_batch(fasta)
-    err = str(excinfo)
-    assert "Unsupported batch type, pass a list, iter, generator or tuple" in err
+        _ = al.map_batch(fasta)
+    e = str(excinfo)
+    assert "Unsupported batch type, pass a list, iter, generator or tuple" in e
 
 
 def test_map_batch_fail_dict_many(al, fasta_iter):
     fasta = {i: dct for i, dct in enumerate(fasta_iter)}
     al.enable_threading(2)
     with pytest.raises(TypeError) as excinfo:
-        mappings = al.map_batch(fasta)
-    err = str(excinfo)
-    assert "Unsupported batch type, pass a list, iter, generator or tuple" in err
+        _ = al.map_batch(fasta)
+    e = str(excinfo)
+    assert "Unsupported batch type, pass a list, iter, generator or tuple" in e
 
 
 def test_map_batch_fail_list_str(al, fasta_iter):
     fasta = [dct["seq"] for dct in fasta_iter]
     al.enable_threading(2)
     with pytest.raises(TypeError) as excinfo:
-        mappings = al.map_batch(fasta)
+        _ = al.map_batch(fasta)
     assert "Element in iterable is not a dictionary" in str(excinfo.value)
 
 
@@ -178,7 +180,7 @@ def test_map_batch_fail_no_seq_key(al, fasta_iter):
     fasta = [{"SEQ": dct["seq"]} for dct in fasta_iter]
     al.enable_threading(2)
     with pytest.raises(KeyError) as excinfo:
-        mappings = al.map_batch(fasta)
+        _ = al.map_batch(fasta)
     assert "AHHH Key 🗝️  not found in iterated dictionary" in str(excinfo)
 
 
@@ -186,7 +188,7 @@ def test_map_batch_fail_seq_not_str(al, fasta_iter):
     fasta = [{"seq": dct["seq"].encode()} for dct in fasta_iter]
     al.enable_threading(2)
     with pytest.raises(ValueError) as excinfo:
-        mappings = al.map_batch(fasta)
+        _ = al.map_batch(fasta)
     assert "`seq` must be a string" in str(excinfo)