Skip to content

Commit

Permalink
chore(test): add doctest namespace (#25)
Browse files Browse the repository at this point in the history
* chore(test): add doctest namespace

Import JAX and NumPy in the doctest namespace to make examples less crowded by imports.

* chore(ci): apply lint suggestions

* fix(deps): conftest is now correctly removed

* fix(test): impossible to test conftest not present

* chore(ci): do not cover conftest

* chore(lint): apply fixes

* fix(ci): typo

* fix(ci): omit conftest

* chore(docs): remove trailing imports
  • Loading branch information
jeertmans authored Jan 12, 2024
1 parent 23d2036 commit 54617d0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/source/notebooks/plotting_backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
},
"outputs": [],
"source": [
"import differt.plotting as dplt\n",
"import differt.plotting as dplt # noqa: E402\n",
"\n",
"dplt.use(\"plotly\")\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"source": [
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"import jax.numpy as jnp\n",
"import numpy as np\n",
"\n",
"import differt.plotting as dplt\n",
"from differt.geometry import TriangleMesh\n",
Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dependencies = [
]
description = "Differentiable Ray Tracing Toolbox for Radio Propagation Simulations"
dynamic = ["license", "readme", "version"]
exclude = ["docs/", "static/"]
keywords = ["ray tracing", "differentiable", "propagation", "radio", "jax"]
name = "DiffeRT"
requires-python = ">=3.9"
Expand Down Expand Up @@ -58,8 +57,19 @@ exclude_lines = [
]
precision = 2

[tool.coverage.run]
omit = ["**/*/conftest.py"]

[tool.maturin]
bindings = "pyo3"
exclude = [
".*",
".github/**/*",
"benches/**/*",
"conftest.py", # Path relative to source (python/differt/conftest.py does not work)
"docs/**/*",
"tests/**/*",
]
features = ["pyo3/extension-module"]
module-name = "differt._core"
python-source = "python"
Expand Down Expand Up @@ -138,7 +148,9 @@ target-version = "py39"
extend-ignore-names = ["T"]

[tool.ruff.lint.per-file-ignores]
"**.ipynb" = ["B018"]
"**/{tests,docs}/*" = ["D"]
"python/differt/conftest.py" = ["D"]

[tool.ruff.pydocstyle]
convention = "google"
12 changes: 12 additions & 0 deletions python/differt/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Any

import jax
import numpy
import pytest


@pytest.fixture(autouse=True)
def add_doctest_modules(doctest_namespace: dict[str, Any]) -> None:
doctest_namespace["jax"] = jax
doctest_namespace["jnp"] = jax.numpy
doctest_namespace["np"] = numpy
2 changes: 1 addition & 1 deletion python/differt/geometry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def normalize(
:Examples:
>>> from differt.geometry.utils import normalize
>>> import jax.numpy as jnp
>>>
>>> vector = jnp.array([1.0, 1.0, 1.0])
>>> normalize(vector) # [1., 1., 1.] / sqrt(3), sqrt(3)
(Array([0.57735026, 0.57735026, 0.57735026], dtype=float32),
Expand Down
3 changes: 0 additions & 3 deletions python/differt/rt/image_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def image_of_vertices_with_respect_to_mirrors(
a batch of random vertices. Here, normal vectors do not have a unit length,
but they should have if you want an interpretable result.
>>> import jax
>>> from differt.rt.image_method import (
... image_of_vertices_with_respect_to_mirrors,
... )
Expand Down Expand Up @@ -137,8 +136,6 @@ def image_method(
.. code-block:: python
import jax.numpy as jnp
paths = image_method(
from_vertices, to_vertices, mirror_vertices, mirror_normals
)
Expand Down
2 changes: 0 additions & 2 deletions python/differt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def sorted_array2(array: Shaped[Array, "m n"]) -> Shaped[Array, "m n"]:
Examples:
The following example shows how the sorting works.
>>> import jax
>>> import jax.numpy as jnp
>>> from differt.utils import sorted_array2
>>>
>>> arr = jnp.arange(10).reshape(5, 2)
Expand Down

0 comments on commit 54617d0

Please sign in to comment.