From 57e2440afe165a47ba4eb31c2fc4bacf9c3522fa Mon Sep 17 00:00:00 2001 From: Phil Schaf Date: Tue, 18 Jun 2024 15:45:13 +0200 Subject: [PATCH] Make test fail more clear --- README.rst | 10 ++++++---- docs/conf.py | 3 ++- pyproject.toml | 22 ++++++++++------------ tests/test_faiss.py | 9 ++++----- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 8db98d6..89bd881 100644 --- a/README.rst +++ b/README.rst @@ -53,10 +53,12 @@ perform competitively in high dimensional spaces. Development =========== -This project is managed using Hatch_ and pre-commit_. To get started, run ``pre-commit -install`` and ``hatch env create``. Run all commands using ``hatch run python -`` which will ensure the environment is kept up to date. pre-commit_ comes into -play on every `git commit` after installation. +This project is managed using Hatch_ and pre-commit_. +To get started, run ``pre-commit install``. +pre-commit_ comes into play on every `git commit` after installation. + +Use the commands `hatch test` and `hatch run docs:build` to +run the tests and build the documentation, respectively. Consult ``pyproject.toml`` for which dependency groups and extras exist, and the Hatch help or user guide for more info on what they are. diff --git a/docs/conf.py b/docs/conf.py index 66b5a00..fcb8e84 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,6 +5,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html import os +from pathlib import PurePosixPath # -- Path setup -------------------------------------------------------------- @@ -61,6 +62,6 @@ repository_url="https://github.com/frankier/sklearn-ann", repository_branch=os.environ.get("READTHEDOCS_GIT_IDENTIFIER", "main"), ) -rtd_links_prefix = "src" +rtd_links_prefix = PurePosixPath("src") autodoc_mock_imports = ["annoy", "faiss", "pynndescent", "nmslib"] diff --git a/pyproject.toml b/pyproject.toml index 691d172..0f9896d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,9 @@ content-type = "text/x-rst" path = "README.rst" start-after = ".. inclusion-marker-do-not-remove\n\n" +[tool.hatch.build.targets.wheel] +packages = ["src/sklearn_ann"] + [tool.pytest.ini_options] addopts = [ "--import-mode=importlib", @@ -84,19 +87,14 @@ ignore = [ [tool.ruff.lint.isort] known-first-party = ["sklearn_ann"] -[tool.hatch.envs.default] -features = [ - "tests", - "docs", - "annlibs", -] +[tool.hatch.envs.hatch-test] +features = ["tests", "annlibs"] +default-args = [] -[tool.hatch.envs.default.scripts] -test = "pytest {args:tests}" -build-docs = "sphinx-build -M html docs docs/_build" - -[tool.hatch.build.targets.wheel] -packages = ["src/sklearn_ann"] +[tool.hatch.envs.docs] +features = ["docs"] +[tool.hatch.envs.docs.scripts] +build = "sphinx-build -M html docs docs/_build" [build-system] requires = ["hatchling", "hatch-vcs", "hatch-fancy-pypi-readme"] diff --git a/tests/test_faiss.py b/tests/test_faiss.py index 7f76a96..6e4e273 100644 --- a/tests/test_faiss.py +++ b/tests/test_faiss.py @@ -1,13 +1,10 @@ from sklearn_ann.test_utils import assert_row_close, needs -try: - from sklearn_ann.kneighbors.faiss import FAISSTransformer -except ImportError: - pass - @needs.faiss def test_euclidean(random_small, random_small_pdists): + from sklearn_ann.kneighbors.faiss import FAISSTransformer + trans = FAISSTransformer(metric="euclidean") mat = trans.fit_transform(random_small) euclidean_dist = random_small_pdists["euclidean"] @@ -16,6 +13,8 @@ def test_euclidean(random_small, random_small_pdists): @needs.faiss def test_cosine(random_small, random_small_pdists): + from sklearn_ann.kneighbors.faiss import FAISSTransformer + trans = FAISSTransformer(metric="cosine") mat = trans.fit_transform(random_small) cosine_dist = random_small_pdists["cosine"]