Skip to content

Commit d9534e3

Browse files
authored
fix: support multiple inclusion (#25)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 17d91fd commit d9534e3

File tree

10 files changed

+92
-14
lines changed

10 files changed

+92
-14
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ ci:
44

55
repos:
66
- repo: https://github.com/adamchainz/blacken-docs
7-
rev: "1.16.0"
7+
rev: "1.19.1"
88
hooks:
99
- id: blacken-docs
1010
additional_dependencies: [black==24.*]
1111

1212
- repo: https://github.com/pre-commit/pre-commit-hooks
13-
rev: "v4.6.0"
13+
rev: "v5.0.0"
1414
hooks:
1515
- id: check-added-large-files
1616
- id: check-case-conflict
@@ -32,22 +32,22 @@ repos:
3232
- id: rst-directive-colons
3333
- id: rst-inline-touching-normal
3434

35-
- repo: https://github.com/pre-commit/mirrors-prettier
36-
rev: "v4.0.0-alpha.8"
35+
- repo: https://github.com/rbubley/mirrors-prettier
36+
rev: "v3.4.2"
3737
hooks:
3838
- id: prettier
3939
types_or: [yaml, markdown, html, css, scss, javascript, json]
4040
args: [--prose-wrap=always]
4141

4242
- repo: https://github.com/astral-sh/ruff-pre-commit
43-
rev: "v0.5.0"
43+
rev: "v0.8.3"
4444
hooks:
4545
- id: ruff
4646
args: ["--fix", "--show-fixes"]
4747
- id: ruff-format
4848

4949
- repo: https://github.com/pre-commit/mirrors-mypy
50-
rev: "v1.10.1"
50+
rev: "v1.13.0"
5151
hooks:
5252
- id: mypy
5353
files: src|tests
@@ -76,13 +76,13 @@ repos:
7676
exclude: .pre-commit-config.yaml
7777

7878
- repo: https://github.com/abravalheri/validate-pyproject
79-
rev: "v0.18"
79+
rev: "v0.23"
8080
hooks:
8181
- id: validate-pyproject
8282
additional_dependencies: ["validate-pyproject-schema-store[all]"]
8383

8484
- repo: https://github.com/python-jsonschema/check-jsonschema
85-
rev: "0.28.6"
85+
rev: "0.30.0"
8686
hooks:
8787
- id: check-dependabot
8888
- id: check-github-workflows

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ disallow_untyped_defs = true
109109
disallow_incomplete_defs = true
110110

111111

112-
[tool.ruff]
113-
src = ["src"]
114-
115112
[tool.ruff.lint]
116113
extend-select = [
117114
"B", # flake8-bugbear
@@ -142,8 +139,6 @@ ignore = [
142139
"ISC001", # Conflicts with formatter
143140
]
144141
isort.required-imports = ["from __future__ import annotations"]
145-
# Uncomment if using a _compat.typing backport
146-
# typing-modules = ["f2py_cmake._compat.typing"]
147142

148143
[tool.ruff.lint.per-file-ignores]
149144
"tests/**" = ["T20"]

src/f2py_cmake/cmake/UseF2Py.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(CMAKE_VERSION VERSION_LESS 3.17)
88
message(FATAL_ERROR "CMake 3.17+ required")
99
endif()
1010

11-
include_guard(GLOBAL)
11+
include_guard(DIRECTORY)
1212

1313
if(TARGET Python::NumPy)
1414
set(_Python Python)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(test
4+
LANGUAGES Fortran C
5+
)
6+
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
9+
add_subdirectory(src)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
add_subdirectory(subrepo)
2+
3+
set (CMAKE_FIND_FRAMEWORK LAST)
4+
find_package(
5+
Python
6+
COMPONENTS Interpreter Development.Module NumPy
7+
REQUIRED)
8+
9+
include(UseF2Py)
10+
11+
message(STATUS "Building test f2py module")
12+
13+
f2py_object_library(test_object OBJECT)
14+
f2py_generate_module(test_ test_py.F90 OUTPUT_VARIABLE test_files)
15+
python_add_library(test_ MODULE "${test_files}" WITH_SOABI)
16+
target_link_libraries(test_ PRIVATE test_object)
17+
install(TARGETS test_ DESTINATION lib/Python)
18+
19+
message(STATUS "Done building test f2py module")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(test-subrepo
4+
LANGUAGES Fortran C
5+
)
6+
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
9+
add_subdirectory(src)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(CMAKE_FIND_FRAMEWORK LAST)
2+
3+
find_package(
4+
Python
5+
COMPONENTS Interpreter Development.Module NumPy
6+
REQUIRED)
7+
8+
include(UseF2Py)
9+
10+
message(STATUS "Building subrepo f2py module")
11+
12+
f2py_object_library(subrepo_object OBJECT)
13+
f2py_generate_module(subrepo_ subrepo_py.F90 OUTPUT_VARIABLE subrepo_files)
14+
python_add_library(subrepo_ MODULE "${subrepo_files}" WITH_SOABI)
15+
target_link_libraries(subrepo_ PRIVATE subrepo_object)
16+
install(TARGETS subrepo_ DESTINATION lib/Python)
17+
18+
message(STATUS "Done building subrepo f2py module")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subroutine bobo()
2+
print *, "bobo"
3+
end subroutine bobo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subroutine bobo()
2+
print *, "bobo"
3+
end subroutine bobo

tests/test_package.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from __future__ import annotations
22

33
import importlib.metadata
4+
import shutil
5+
import subprocess
46
import zipfile
57
from pathlib import Path
68

9+
import pytest
710
from scikit_build_core.build import build_wheel
811

912
import f2py_cmake as m
13+
import f2py_cmake.vendor
1014

1115
DIR = Path(__file__).parent.resolve()
1216

@@ -15,6 +19,7 @@ def test_version():
1519
assert importlib.metadata.version("f2py_cmake") == m.__version__
1620

1721

22+
@pytest.mark.skipif(shutil.which("cmake") is None, reason="CMake not found")
1823
def test_f77(monkeypatch, tmp_path):
1924
monkeypatch.chdir(DIR / "packages/f77")
2025
build_dir = tmp_path / "build"
@@ -30,3 +35,20 @@ def test_f77(monkeypatch, tmp_path):
3035
build_files = {x.name for x in build_dir.iterdir()}
3136
assert "fibbymodule.c" in build_files
3237
assert "fibby-f2pywrappers.f" in build_files
38+
39+
40+
def test_f90(monkeypatch, tmp_path):
41+
src_dir = tmp_path / "source"
42+
build_dir = tmp_path / "build"
43+
shutil.copytree(DIR / "packages/f90dual", src_dir)
44+
monkeypatch.chdir(src_dir)
45+
46+
cmake_dir = src_dir / "cmake"
47+
cmake_dir.mkdir()
48+
f2py_cmake.vendor.vendorize(cmake_dir)
49+
50+
inner_cmake_dir = src_dir / "src/subrepo/cmake"
51+
inner_cmake_dir.mkdir()
52+
f2py_cmake.vendor.vendorize(inner_cmake_dir)
53+
54+
subprocess.run(["cmake", "-S", ".", "-B", str(build_dir)], check=True)

0 commit comments

Comments
 (0)