Skip to content

Commit

Permalink
Refactor into src layout
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Apr 12, 2023
1 parent 0f550b4 commit 230c4bf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endef
export PRINT_HELP_PYSCRIPT

BROWSER := python -c "$$BROWSER_PYSCRIPT"
PY_PATHS = ncollpyde tests
PY_PATHS = python/ncollpyde tests

help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
Expand Down Expand Up @@ -87,7 +87,7 @@ install-opt:
maturin develop --release

coverage: install-dev
coverage run --source ncollpyde -m pytest && \
coverage run --source python/ncollpyde -m pytest && \
coverage report -m && \
coverage html && \
$(BROWSER) htmlcov/index.html
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ repository = "https://github.com/clbarnes/ncollpyde/"
requires = ["maturin==0.14", "numpy>=1.21"]
build-backend = "maturin"

[tool.maturin]
python-source = "python"
module-name = "ncollpyde._ncollpyde"

[tool.mypy]
ignore_missing_imports = true
plugins = ["numpy.typing.mypy_plugin"]
Expand Down
4 changes: 2 additions & 2 deletions ncollpyde/__init__.py → python/ncollpyde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from .main import PRECISION # noqa: F401
from .main import Volume # noqa: F401
from .main import configure_threadpool # noqa: F401
from .ncollpyde import n_threads # noqa: F401
from .ncollpyde import _version
from ._ncollpyde import n_threads # noqa: F401
from ._ncollpyde import _version

__version__ = _version()
__version_info__ = tuple(int(n) for n in __version__.split("-")[0].split("."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def _precision() -> str: ...
def _index() -> str: ...
def _version() -> str: ...
def n_threads() -> int: ...
def configure_threadpool(n_threads: Optional[int], name_prefix: Optional[str]): ...
def _configure_threadpool(n_threads: Optional[int], name_prefix: Optional[str]): ...

Points = npt.NDArray[np.float64]
Indices = npt.NDArray[np.uint32]
Expand Down
4 changes: 2 additions & 2 deletions ncollpyde/main.py → python/ncollpyde/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
except ImportError:
trimesh = None

from .ncollpyde import (
from ._ncollpyde import (
TriMeshWrapper,
_index,
_precision,
configure_threadpool as _configure_threadpool,
_configure_threadpool,
)

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl TriMeshWrapper {
}

#[pymodule]
#[pyo3(name = "_ncollpyde")]
pub fn ncollpyde(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<TriMeshWrapper>()?;

Expand Down Expand Up @@ -249,7 +250,7 @@ pub fn ncollpyde(_py: Python, m: &PyModule) -> PyResult<()> {
}

#[pyfn(m)]
#[pyo3(name = "configure_threadpool")]
#[pyo3(name = "_configure_threadpool")]
pub fn configure_threadpool(
_py: Python,
n_threads: Option<usize>,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_ncollpyde.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from itertools import product
import sys
import subprocess as sp
import logging

import numpy as np
import pytest
Expand All @@ -16,6 +17,8 @@

from ncollpyde import PRECISION, Volume, configure_threadpool

logger = logging.getLogger(__name__)

points_expected = [
([-2.3051376, -4.1556454, 1.9047838], True), # internal
([-0.35222054, -0.513299, 7.6191354], False), # external but in AABB
Expand Down Expand Up @@ -300,7 +303,10 @@ def test_configure_threadpool_subprocess():
)
args = [sys.executable, "-c", cmd]

sp.run(args, check=True, text=True, capture_output=True)
result = sp.run(args, text=True, capture_output=True)
logger.info(result.stdout)
logger.warning(result.stderr)
result.check_returncode()


def test_configure_threadpool_twice():
Expand Down

0 comments on commit 230c4bf

Please sign in to comment.