Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support multiple inclusion #25

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ ci:

repos:
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
rev: "1.19.1"
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
rev: "v5.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -32,22 +32,22 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

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

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.0"
rev: "v0.8.3"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.10.1"
rev: "v1.13.0"
hooks:
- id: mypy
files: src|tests
Expand Down Expand Up @@ -76,13 +76,13 @@ repos:
exclude: .pre-commit-config.yaml

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.18"
rev: "v0.23"
hooks:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.28.6"
rev: "0.30.0"
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ disallow_untyped_defs = true
disallow_incomplete_defs = true


[tool.ruff]
src = ["src"]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
Expand Down Expand Up @@ -142,8 +139,6 @@ ignore = [
"ISC001", # Conflicts with formatter
]
isort.required-imports = ["from __future__ import annotations"]
# Uncomment if using a _compat.typing backport
# typing-modules = ["f2py_cmake._compat.typing"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
Expand Down
2 changes: 1 addition & 1 deletion src/f2py_cmake/cmake/UseF2Py.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if(CMAKE_VERSION VERSION_LESS 3.17)
message(FATAL_ERROR "CMake 3.17+ required")
endif()

include_guard(GLOBAL)
include_guard(DIRECTORY)

if(TARGET Python::NumPy)
set(_Python Python)
Expand Down
9 changes: 9 additions & 0 deletions tests/packages/f90dual/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.24)

project(test
LANGUAGES Fortran C
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_subdirectory(src)
19 changes: 19 additions & 0 deletions tests/packages/f90dual/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_subdirectory(subrepo)

set (CMAKE_FIND_FRAMEWORK LAST)
find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)

include(UseF2Py)

message(STATUS "Building test f2py module")

f2py_object_library(test_object OBJECT)
f2py_generate_module(test_ test_py.F90 OUTPUT_VARIABLE test_files)
python_add_library(test_ MODULE "${test_files}" WITH_SOABI)
target_link_libraries(test_ PRIVATE test_object)
install(TARGETS test_ DESTINATION lib/Python)

message(STATUS "Done building test f2py module")
9 changes: 9 additions & 0 deletions tests/packages/f90dual/src/subrepo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.24)

project(test-subrepo
LANGUAGES Fortran C
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_subdirectory(src)
18 changes: 18 additions & 0 deletions tests/packages/f90dual/src/subrepo/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(CMAKE_FIND_FRAMEWORK LAST)

find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)

include(UseF2Py)

message(STATUS "Building subrepo f2py module")

f2py_object_library(subrepo_object OBJECT)
f2py_generate_module(subrepo_ subrepo_py.F90 OUTPUT_VARIABLE subrepo_files)
python_add_library(subrepo_ MODULE "${subrepo_files}" WITH_SOABI)
target_link_libraries(subrepo_ PRIVATE subrepo_object)
install(TARGETS subrepo_ DESTINATION lib/Python)

message(STATUS "Done building subrepo f2py module")
3 changes: 3 additions & 0 deletions tests/packages/f90dual/src/subrepo/src/subrepo_piy.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subroutine bobo()
print *, "bobo"
end subroutine bobo
3 changes: 3 additions & 0 deletions tests/packages/f90dual/src/test_py.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subroutine bobo()
print *, "bobo"
end subroutine bobo
22 changes: 22 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

import importlib.metadata
import shutil
import subprocess
import zipfile
from pathlib import Path

import pytest
from scikit_build_core.build import build_wheel

import f2py_cmake as m
import f2py_cmake.vendor

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

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


@pytest.mark.skipif(shutil.which("cmake") is None, reason="CMake not found")
def test_f77(monkeypatch, tmp_path):
monkeypatch.chdir(DIR / "packages/f77")
build_dir = tmp_path / "build"
Expand All @@ -30,3 +35,20 @@ def test_f77(monkeypatch, tmp_path):
build_files = {x.name for x in build_dir.iterdir()}
assert "fibbymodule.c" in build_files
assert "fibby-f2pywrappers.f" in build_files


def test_f90(monkeypatch, tmp_path):
src_dir = tmp_path / "source"
build_dir = tmp_path / "build"
shutil.copytree(DIR / "packages/f90dual", src_dir)
monkeypatch.chdir(src_dir)

cmake_dir = src_dir / "cmake"
cmake_dir.mkdir()
f2py_cmake.vendor.vendorize(cmake_dir)

inner_cmake_dir = src_dir / "src/subrepo/cmake"
inner_cmake_dir.mkdir()
f2py_cmake.vendor.vendorize(inner_cmake_dir)

subprocess.run(["cmake", "-S", ".", "-B", str(build_dir)], check=True)
Loading