Skip to content

Commit 2fb523c

Browse files
committed
feat: rewrite
Signed-off-by: Henry Schreiner <[email protected]>
1 parent aa374d8 commit 2fb523c

File tree

12 files changed

+368
-226
lines changed

12 files changed

+368
-226
lines changed

.github/CONTRIBUTING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ Use pytest to run the unit checks:
6666
pytest
6767
```
6868

69-
# Coverage
70-
71-
Use pytest-cov to generate coverage reports:
72-
73-
```bash
74-
pytest --cov=cython-cmake
75-
```
76-
7769
# Building docs
7870

7971
You can build the docs using:

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ jobs:
5757
python-version: ${{ matrix.python-version }}
5858
allow-prereleases: true
5959

60+
- uses: yezz123/setup-uv@v4
61+
6062
- name: Install package
61-
run: python -m pip install .[test]
63+
run: uv pip install --system -e.[test]
6264

6365
- name: Test package
64-
run: >-
65-
python -m pytest -ra --cov --cov-report=xml --cov-report=term
66-
--durations=20
67-
68-
- name: Upload coverage report
69-
uses: codecov/[email protected]
66+
run: python -m pytest --durations=20

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ repos:
5555
args: []
5656
additional_dependencies:
5757
- pytest
58+
- scikit-build-core
5859

5960
- repo: https://github.com/codespell-project/codespell
6061
rev: "v2.3.0"

noxfile.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import annotations
22

33
import argparse
4-
import shutil
54
from pathlib import Path
65

76
import nox
87

98
DIR = Path(__file__).parent.resolve()
109

10+
nox.needs_version = ">=2024.3.2"
11+
nox.options.default_venv_backend = "uv|virtualenv"
1112
nox.options.sessions = ["lint", "pylint", "tests"]
1213

1314

@@ -38,7 +39,7 @@ def tests(session: nox.Session) -> None:
3839
"""
3940
Run the unit and regular tests.
4041
"""
41-
session.install(".[test]")
42+
session.install("-e.[test]")
4243
session.run("pytest", *session.posargs)
4344

4445

@@ -109,9 +110,5 @@ def build(session: nox.Session) -> None:
109110
Build an SDist and wheel.
110111
"""
111112

112-
build_path = DIR.joinpath("build")
113-
if build_path.exists():
114-
shutil.rmtree(build_path)
115-
116113
session.install("build")
117114
session.run("python", "-m", "build")

pyproject.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ any = "cython_cmake.cmake"
3838
[project.optional-dependencies]
3939
test = [
4040
"pytest >=6",
41-
"pytest-cov >=3",
42-
]
43-
dev = [
44-
"pytest >=6",
45-
"pytest-cov >=3",
41+
"scikit-build-core",
42+
"cython",
4643
]
4744
docs = [
4845
"sphinx>=7.0",
@@ -64,9 +61,11 @@ version.source = "vcs"
6461
build.hooks.vcs.version-file = "src/cython_cmake/_version.py"
6562

6663
[tool.hatch.envs.default]
67-
features = ["test"]
68-
scripts.test = "pytest {args}"
64+
installer = "uv"
6965

66+
[tool.hatch.envs.hatch-test]
67+
features = ["test"]
68+
extra-dependencies = ["cmake", "ninja"]
7069

7170
[tool.pytest.ini_options]
7271
minversion = "6.0"

src/cython_cmake/cmake/FindCython.cmake

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
# ``CYTHON_FOUND``
1414
# true if the program was found
1515
#
16+
# And the following target:
17+
#
18+
# ``Cython::Cython``
19+
# The Cython executable
20+
#
1621
# For more information on the Cython project, see https://cython.org/.
1722
#
1823
# *Cython is a language that makes writing C extensions for the Python language
@@ -34,6 +39,10 @@
3439
# limitations under the License.
3540
#=============================================================================
3641

42+
if(CMAKE_VERSION VERSION_LESS "3.20")
43+
message(SEND_ERROR "CMake 3.20 required")
44+
endif()
45+
3746
# Use the Cython executable that lives next to the Python executable
3847
# if it is a local installation.
3948
if(Python_EXECUTABLE)
@@ -56,7 +65,7 @@ else()
5665
endif()
5766

5867
if(CYTHON_EXECUTABLE)
59-
set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version)
68+
set(CYTHON_version_command "${CYTHON_EXECUTABLE}" --version)
6069

6170
execute_process(COMMAND ${CYTHON_version_command}
6271
OUTPUT_VARIABLE CYTHON_version_output
@@ -69,20 +78,31 @@ if(CYTHON_EXECUTABLE)
6978
set(_error_msg "Command \"${CYTHON_version_command}\" failed with")
7079
set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}")
7180
message(SEND_ERROR "${_error_msg}")
81+
elseif("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)")
82+
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
83+
elseif("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)")
84+
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
7285
else()
73-
if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)")
74-
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
75-
else()
76-
if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)")
77-
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
78-
endif()
79-
endif()
86+
message(SEND_ERROR "Invalid Cython version output")
8087
endif()
8188
endif()
8289

8390
include(FindPackageHandleStandardArgs)
84-
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE)
91+
find_package_handle_standard_args(Cython
92+
REQUIRED_VARS CYTHON_EXECUTABLE
93+
VERSION_VAR ${CYTHON_VERSION}
94+
HANDLE_VERSION_RANGE
95+
)
8596

86-
mark_as_advanced(CYTHON_EXECUTABLE)
97+
if(CYTHON_FOUND)
98+
if(NOT DEFINED Cython::Cython)
99+
add_executable(Cython::Cython IMPORTED)
100+
set_target_properties(Cython::Cython PROPERTIES
101+
IMPORTED_LOCATION "${CYTHON_EXECUTABLE}"
102+
)
103+
endif()
104+
105+
include(UseCython)
106+
endif()
87107

88-
include(UseCython)
108+
mark_as_advanced(CYTHON_EXECUTABLE)

0 commit comments

Comments
 (0)