Skip to content

Commit

Permalink
Add CI script + lint code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgautier committed Dec 30, 2023
1 parent fb87b39 commit 3591617
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 50 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Python package

on: [push, pull_request]

jobs:
code-qc:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Lint with flake8
run: |
python -m pip install flake8
flake8 src/
build-sdist:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Set up R ${{ matrix.r-version }}
uses: r-lib/actions/setup-r@v2
with:
r-version: release
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools build
- name: Build sdist
run: |
python -m build -o dist/ --sdist .
- name: Upload source package.
uses: actions/upload-artifact@v3
with:
name: mashing-pumkins-sdist
path: dist/mashing-pumpkins-*.tar.gz
build-wheel-posix:
runs-on: ${{ matrix.os }}
permissions:
packages: read
continue-on-error: true
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python: 39
platform_id: manylinux2014
- os: macos-11
python: 310
platform_id: macosx_x86_64
- os: macos-11
python: 310
platform_id: macosx_arm64
- os: macos-12
python: 310
platform_id: macosx_arm64
- os: macos-13
python: 310
platform_id: macosx_arm64
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools build cibuildwheel
- name: Build wheel
uses: pypa/[email protected]
env:
CIBW_SKIP: cp36-* cp37-*
CIBW_ARCHS_LINUX: "auto aarch64"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_BUILD_VERBOSITY: 1
with:
output-dir: wheelhouse
config-file: pyproject.toml
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: binary-wheels-${{ matrix.platform_id }}
path: wheelhouse/*.whl
test:
needs: [build-sdist]
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
r-version: ['release']
os: [ubuntu-latest, ubuntu-20.04, macOS-latest]
venv_activate: ["source pyenv_base/bin/activate"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Create base virtualenv (non-windows)
run: |
python -m venv pyenv_base
${{ matrix.venv_activate }}
python -m pip install -U pip wheel
- uses: actions/download-artifact@v3
with:
name: mashing-pumpkins-sdist
path: dist/
- name: Source package path.
shell: bash
run: echo "SRC_DIST=$(ls -1 dist/*.tar.gz | tail -n 1)" >> $GITHUB_ENV
- name: Install package (non-Windows)
run: |
${{ matrix.venv_activate }}
pip install $SRC_DIST
- name: Test
run: |
${{ matrix.venv_activate }}
python -m pip install $SRC_DIST'[test_minimal]'
pytest src/tests/
8 changes: 4 additions & 4 deletions src/minhashsketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _minmaxhash_add_ngrams(
# Replace the maximum value in the heap.
heapmap[h] = elt
out = heapreplace(heap, elt)
del(heapmap[sign * out[0]])
del (heapmap[sign * out[0]])
# The negative of the hash is needed for MinHash.
heaptop = sign * heap[0][0]
if anynew is not None:
Expand Down Expand Up @@ -172,7 +172,7 @@ def _replace(self, h, elt):
heapmap = self._heapmap
heapmap[h] = elt
out = heapreplace(self._heap, elt)
del(heapmap[self._extracthash(out)])
del (heapmap[self._extracthash(out)])
return out

def __add__(self, obj):
Expand Down Expand Up @@ -405,7 +405,7 @@ def _replace(self, h, elt):
heapmap = self._heapmap
heapmap[h] = elt
out = heapreplace(self._heap, elt)
del(heapmap[self._extracthash(out)])
del (heapmap[self._extracthash(out)])
return out

def _add(self, subs, nsubs, hashbuffer, heaptop,
Expand Down Expand Up @@ -541,7 +541,7 @@ class CountTrait(object):

def _replace(self, h, elt):
out = super()._replace(h, elt)
del(self._count[self._extracthash(out)])
del (self._count[self._extracthash(out)])
return out

def _anynew(self, h):
Expand Down
28 changes: 16 additions & 12 deletions src/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
Parallelization utilities
"""

from functools import reduce
import multiprocessing


class Sketch(object):

@staticmethod
def initializer(cls, *args):
"""
FIXME: use of global not really nice (possible root of mysterious issue for user)
FIXME: use of global not really nice (possible root of mysterious
issue for user)
"""
global sketch_constructor

def sketch_constructor():
return cls(*args)

@staticmethod
def map_sequence(sequence):
"""
Expand Down Expand Up @@ -59,7 +58,8 @@ class SketchList(object):
@staticmethod
def initializer(clslist, argslist):
"""
FIXME: use of global not really nice (possible root of mysterious issue for user)
FIXME: use of global not really nice (possible root of mysterious
issue for user)
"""

# Allow automagic expansion of the list of classes
Expand All @@ -69,12 +69,15 @@ def initializer(clslist, argslist):
# Allow automagic expansion of the list of args
if len(argslist) == 1:
argslist = tuple(argslist[0] for x in range(len(clslist)))

if len(clslist) != len(argslist):
raise ValueError("The arguments argslist and clslist must be sequences of either the "
"same length, or of length 1.")

raise ValueError(
"The arguments argslist and clslist must be sequences of "
"either the same length, or of length 1."
)

global sketchlist_constructor

def sketchlist_constructor():
return (cls(*args) for cls, args in zip(clslist, argslist))

Expand Down Expand Up @@ -111,8 +114,9 @@ def reduce(alist, blist):
- alist: a sequence of sketches
- blist: a sequence of sketches
return alist after each of its elements has been updated to the corresponding element in blist
return alist after each of its elements has been updated to the
corresponding element in blist
"""
for a,b in zip(alist, blist):
for a, b in zip(alist, blist):
a.update(b)
return alist
5 changes: 1 addition & 4 deletions src/tests/test__murmurhash3.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pytest

import array
from mashingpumpkins import _murmurhash3


def test_hasharray():
nsize=3
nsize = 3
buffer = array.array('Q', [0, ])
seed = 42
_murmurhash3.hasharray(b"ACG", nsize, buffer, seed)
Expand All @@ -14,4 +12,3 @@ def test_hasharray():
seed = 43
_murmurhash3.hasharray(b"ACG", nsize, buffer, seed)
assert buffer[0] != 1731421407650554201

Loading

0 comments on commit 3591617

Please sign in to comment.