8000 Improve source layout test discovery (#247) · scientific-python/spin@3760320 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3760320

Browse files
authored
Improve source layout test discovery (#247)
This should allow us to move forward with numpy/numpy#27371 without breaking behavior for `src/tests` layout.
2 parents eb1c607 + 5c5266c commit 3760320

File tree

21 files changed

+211
-48
lines changed

21 files changed

+211
-48
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ repos:
4141
rev: 6f546f30c2b142ad5b3edcf20e3d27cf1789b932 # frozen: v1.10.1
4242
hooks:
4343
- id: mypy
44+
exclude: |
45+
(?x)(
46+
^example_pkg_src/
47+
)
4448
4549
- repo: https://github.com/codespell-project/codespell
4650
rev: "193cd7d27cd571f79358af09a8fb8997e54f8fff" # frozen: v2.3.0

example_pkg/example_pkg/_core.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def echo(str) -> None: ...

example_pkg_src/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.* export-ignore
2+
.spin -export-ignore

example_pkg_src/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build
2+
build-install
3+
.mesonpy-native-file.ini
4+
dist/
5+
doc/_build

example_pkg_src/meson.build

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
project(
2+
'spin-example-pkg',
3+
'c',
4+
version: '0.0.dev0',
5+
license: 'BSD-3',
6+
meson_version: '>= 0.64',
7+
default_options: [
8+
'buildtype=debugoptimized',
9+
'c_std=c99',
10+
'cpp_std=c++14',
11+
],
12+
)
13+
14+
cc = meson.get_compiler('c')
15+
16+
py_mod = import('python')
17+
py = py_mod.find_installation(pure: false)
18+
py_dep = py.dependency()
19+
20+
subdir('src')

example_pkg_src/pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[project]
2+
name = "example_pkg"
3+
version = "0.0dev0"
4+
requires-python = ">=3.7"
5+
description = "spin Example Package"
6+
7+
[build-system]
8+
build-backend = "mesonpy"
9+
requires = [
10+
"meson-python>=0.13.0rc0",
11+
]
12+
13+
[tool.spin]
14+
package = 'example_pkg'
15+
16+
[tool.spin.commands]
17+
"Build" = [
18+
"spin.cmds.meson.build",
19+
"spin.cmds.meson.test"
20+
]

example_pkg_src/src/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ._core import echo
2+
3+
__all__ = ["echo"]
4+
__version__ = "0.0.0dev0"

example_pkg_src/src/_core.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def echo(str) -> None: ...

example_pkg_src/src/conftest.py

Whitespace-only changes.

example_pkg_src/src/coremodule.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
4+
static PyObject *
5+
core_echo(PyObject *self, PyObject *args)
6+
{
7+
const char *str;
8+
PyObject *ret;
9+
10+
if (!PyArg_ParseTuple(args, "s", &str))
11+
return NULL;
12+
13+
printf("%s\n", str);
14+
15+
ret = PyLong_FromLong(42);
16+
Py_INCREF(ret);
17+
return ret;
18+
}
19+
20+
static PyMethodDef CoreMethods[] = {
21+
{"echo", core_echo, METH_VARARGS, "Echo a string and return 42"},
22+
{NULL, NULL, 0, NULL} /* Sentinel */
23+
};
24+
25+
static struct PyModuleDef coremodule = {
26+
PyModuleDef_HEAD_INIT,
27+
"core", /* name of module */
28+
NULL, /* module documentation, may be NULL */
29+
-1, /* size of per-interpreter state of the module,
30+
or -1 if the module keeps state in global variables. */
31+
CoreMethods
32+
};
33+
34+
PyMODINIT_FUNC
35+
PyInit__core(void)
36+
{
37+
PyObject *m;
38+
39+
m = PyModule_Create(&coremodule);
40+
if (m == NULL)
41+
return NULL;
42+
43+
return m;
44+
}

0 commit comments

Comments
 (0)
0