Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt CI for multiple OS #23

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,49 @@ on:


jobs:
build:
check_install:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: True
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install nox_poetry
- name: Test install all
run: pip install -e .[all]

tests:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: True
matrix:
python-version: [3.8, "3.10"]
python-version: ["3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
python -m pip install nox_poetry
- name: Test with nox
run: nox -s tests
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up Python
- name: Install poetry
run: pipx install poetry
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.8"
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
python -m pip install nox_poetry
- name: Lint
run: nox -s lint
- name: Type checking
run: nox -s type_checking
- name: Run all style checks
run: nox -t style
- name: Build docs
run: nox -s build_docs
7 changes: 2 additions & 5 deletions kiez/hubness_reduction/mutual_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

import numpy as np
from scipy import stats
from sklearn.utils.validation import (
check_array,
check_consistent_length,
check_is_fitted,
)
from sklearn.utils.validation import (check_array, check_consistent_length,
check_is_fitted)
from tqdm.auto import tqdm

from .base import HubnessReduction
Expand Down
4 changes: 3 additions & 1 deletion kiez/neighbors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from class_resolver import ClassResolver

from kiez.neighbors.approximate.faiss import Faiss
from kiez.neighbors.approximate.nmslib import NMSLIB
from kiez.neighbors.approximate.nng import NNG
from kiez.neighbors.approximate.random_projection_trees import Annoy
from kiez.neighbors.exact.sklearn_nearest_neighbors import SklearnNN
from kiez.neighbors.neighbor_algorithm_base import NNAlgorithm, NNAlgorithmWithJoblib
from kiez.neighbors.neighbor_algorithm_base import (NNAlgorithm,
NNAlgorithmWithJoblib)

__all__ = [
"nn_algorithm_resolver",
Expand Down
1 change: 1 addition & 0 deletions kiez/neighbors/approximate/nmslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import numpy as np

from kiez.neighbors.neighbor_algorithm_base import NNAlgorithm

try:
Expand Down
3 changes: 2 additions & 1 deletion kiez/neighbors/approximate/nng.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import logging

import numpy as np
from tqdm.auto import tqdm

from kiez.io.temp_file_handling import create_tempfile_preferably_in_dir
from kiez.neighbors.neighbor_algorithm_base import NNAlgorithmWithJoblib
from tqdm.auto import tqdm

try:
import ngtpy # noqa: autoimport
Expand Down
3 changes: 2 additions & 1 deletion kiez/neighbors/approximate/random_projection_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from typing import Tuple

import numpy as np
from tqdm.auto import tqdm

from kiez.io.temp_file_handling import create_tempfile_preferably_in_dir
from kiez.neighbors.neighbor_algorithm_base import NNAlgorithmWithJoblib
from tqdm.auto import tqdm

try:
import annoy # noqa: autoimport
Expand Down
3 changes: 2 additions & 1 deletion kiez/neighbors/exact/sklearn_nearest_neighbors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# documentation copied in parts from scikit-learn
from kiez.neighbors.neighbor_algorithm_base import NNAlgorithm
from sklearn.neighbors import VALID_METRICS, NearestNeighbors

from kiez.neighbors.neighbor_algorithm_base import NNAlgorithm


class SklearnNN(NNAlgorithm):
"""Wrapper for scikit learn's NearestNeighbors class
Expand Down
20 changes: 14 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nox_poetry import Session, session


@session()
@session(tags=["test"])
def tests(session: Session) -> None:
args = session.posargs or ["--cov=kiez/", "--cov-report=xml", "tests/"]
session.install(".[all]")
Expand All @@ -13,8 +13,16 @@ def tests(session: Session) -> None:
locations = ["kiez", "tests", "noxfile.py"]


@session()
@session(tags=["fix"])
def lint(session: Session) -> None:
args = session.posargs or locations
session.install("black", "isort")
session.run("black", *args)
session.run("isort", *args)


@session(tags=["style"])
def style_checking(session: Session) -> None:
args = session.posargs or locations
session.install(
"pyproject-flake8",
Expand All @@ -27,28 +35,28 @@ def lint(session: Session) -> None:
session.run("pflake8", *args)


@session()
@session(tags=["style"])
def pyroma(session: Session) -> None:
session.install("poetry", "pyroma")
session.run("pyroma", "--min", "10", ".")


@session()
@session(tags=["style", "docs"])
def doctests(session: Session) -> None:
session.install(".[all]")
session.install("xdoctest")
session.install("pygments")
session.run("xdoctest", "-m", "kiez")


@session()
@session(tags=["style"])
def type_checking(session: Session) -> None:
args = session.posargs or locations
session.install("mypy")
session.run("mypy", "--ignore-missing-imports", *args)


@session()
@session(tags=["docs"])
def build_docs(session: Session) -> None:
session.install(".")
session.install("sphinx")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mypy = "^0.960"

[tool.poetry.extras]
docs = ["sphinx", "insegel"]
all = ["ngt","annoy","nmslib","faiss-cpu","faiss-gpu","autofaiss"]
all = ["annoy","nmslib","faiss-cpu","faiss-gpu","autofaiss"]
ngt = ["ngt"]
nmslib = ["nmslib"]
annoy = ["annoy"]
Expand Down
9 changes: 5 additions & 4 deletions tests/analysis/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import numpy as np
import pytest
from numpy.testing import assert_array_equal

from kiez.analysis import hubness_score
from kiez.analysis.estimation import _calc_atkinson_index, _calc_gini_index
from numpy.testing import assert_array_equal

PRE_CALC_NEIGHBORS = np.load("tests/nn_ind.npy")

Expand Down Expand Up @@ -108,9 +109,9 @@ def test_hubness_return_values_are_self_consistent(k):
np.testing.assert_array_equal(occ, occ_true)
# Calculate skewness (different method than in module)
x0 = occ - occ.mean()
s2 = (x0 ** 2).mean()
m3 = (x0 ** 3).mean()
skew_true = m3 / (s2 ** 1.5)
s2 = (x0**2).mean()
m3 = (x0**3).mean()
skew_true = m3 / (s2**1.5)
np.testing.assert_equal(skew, skew_true)


Expand Down
1 change: 1 addition & 0 deletions tests/evaluate/test_eval_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from kiez.evaluate import hits


Expand Down
3 changes: 2 additions & 1 deletion tests/hubness_reduction/test_mutual_proximity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from numpy.testing import assert_array_equal

from kiez import Kiez
from kiez.hubness_reduction import MutualProximity
from numpy.testing import assert_array_equal

rng = np.random.RandomState(2)

Expand Down
3 changes: 2 additions & 1 deletion tests/io/test_data_loading.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from kiez.io.data_loading import _seperate_common_embedding
from numpy.testing import assert_array_equal

from kiez.io.data_loading import _seperate_common_embedding


@pytest.mark.parametrize(
"input,expected",
Expand Down
1 change: 1 addition & 0 deletions tests/io/test_temp_file_handling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest

from kiez.io.temp_file_handling import create_tempfile_preferably_in_dir


Expand Down
6 changes: 4 additions & 2 deletions tests/neighbors/test_alignment.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import numpy as np
import pytest
from numpy.testing import assert_array_almost_equal, assert_array_equal

from kiez import Kiez
from kiez.hubness_reduction import CSLS, DisSimLocal, LocalScaling, MutualProximity
from kiez.hubness_reduction import (CSLS, DisSimLocal, LocalScaling,
MutualProximity)
from kiez.neighbors import NMSLIB, NNG, Annoy, Faiss, SklearnNN
from kiez.utils.platform import available_ann_algorithms_on_current_platform
from numpy.testing import assert_array_almost_equal, assert_array_equal

P = (1, 3, 4, np.inf, 2) # Euclidean last, for tests against approx NN
rng = np.random.RandomState(2)
Expand Down
3 changes: 2 additions & 1 deletion tests/neighbors/test_annoy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from kiez.neighbors import Annoy
from numpy.testing import assert_array_equal

from kiez.neighbors import Annoy

rng = np.random.RandomState(2)


Expand Down
1 change: 1 addition & 0 deletions tests/neighbors/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from kiez.neighbors import NMSLIB, NNG, Annoy, Faiss, SklearnNN

rng = np.random.RandomState(2)
Expand Down
3 changes: 2 additions & 1 deletion tests/neighbors/test_faiss.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from kiez.neighbors import Faiss
from numpy.testing import assert_array_equal

from kiez.neighbors import Faiss


@pytest.mark.parametrize("single_source", [True, False])
def test_different_instantiations(single_source):
Expand Down
3 changes: 2 additions & 1 deletion tests/neighbors/test_hnsw.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from kiez.neighbors import NMSLIB
from numpy.testing import assert_array_equal

from kiez.neighbors import NMSLIB

rng = np.random.RandomState(2)


Expand Down
3 changes: 2 additions & 1 deletion tests/neighbors/test_nng.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pytest
from kiez.neighbors import NNG
from numpy.testing import assert_array_equal

from kiez.neighbors import NNG

rng = np.random.RandomState(2)


Expand Down
3 changes: 2 additions & 1 deletion tests/neighbors/test_sklearn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from kiez.neighbors import SklearnNN
from numpy.testing import assert_array_equal

from kiez.neighbors import SklearnNN

rng = np.random.RandomState(2)


Expand Down
13 changes: 5 additions & 8 deletions tests/test_kiez.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

import numpy as np
import pytest
from kiez import Kiez
from kiez.hubness_reduction import (
DisSimLocal,
HubnessReduction,
LocalScaling,
NoHubnessReduction,
)
from kiez.neighbors import NMSLIB, NNAlgorithm, SklearnNN
from numpy.testing import assert_array_equal
from sklearn.neighbors import NearestNeighbors

from kiez import Kiez
from kiez.hubness_reduction import (DisSimLocal, HubnessReduction,
LocalScaling, NoHubnessReduction)
from kiez.neighbors import NMSLIB, NNAlgorithm, SklearnNN

HERE = pathlib.Path(__file__).parent.resolve()
rng = np.random.RandomState(2)

Expand Down