Skip to content

Commit

Permalink
feat: first version
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 27, 2024
1 parent d811787 commit 7aeceb9
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 47 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
environment: pypi
permissions:
id-token: write
attestations: write
contents: read
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'

Expand All @@ -46,8 +48,9 @@ jobs:
name: Packages
path: dist

- uses: pypa/gh-action-pypi-publish@release/v1
- name: Generate artifact attestation for sdist and wheel
uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2
with:
# Remember to tell (test-)pypi about this repo before publishing
# Remove this line to publish to PyPI
repository-url: https://test.pypi.org/legacy/
subject-path: "dist/f2py*"

- uses: pypa/gh-action-pypi-publish@release/v1
23 changes: 15 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.12"]
runs-on: [ubuntu-latest, windows-latest, macos-14]
runs-on: [ubuntu-latest, macos-14]

include:
- python-version: "pypy-3.10"
Expand All @@ -57,15 +57,22 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install gfortran
uses: fortran-lang/setup-fortran@v1
if: runner.os != 'Linux'
with:
compiler: gcc
version: 13

- name: Use GFortran
if: runner.os == 'macOS'
run: |
echo "CC=clang" >> $GITHUB_ENV
echo "FC=gfortran" >> $GITHUB_ENV
- name: Install package
run: python -m pip install .[test]

- name: Test package
run: >-
python -m pytest -ra --cov --cov-report=xml --cov-report=term
--durations=20
- name: Upload coverage report
uses: codecov/codecov-action@v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
python -m pytest --durations=20
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,28 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
rev: "v4.0.0-alpha.8"
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.4.8"
rev: "v0.5.0"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.10.0"
rev: "v1.10.1"
hooks:
- id: mypy
files: src|tests
args: []
additional_dependencies:
- pytest
- scikit-build-core

- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
Expand All @@ -80,7 +81,7 @@ repos:
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.28.4"
rev: "0.28.6"
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
60 changes: 57 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,75 @@
# f2py-cmake

[![Actions Status][actions-badge]][actions-link]

<!--
[![Documentation Status][rtd-badge]][rtd-link]
-->

[![PyPI version][pypi-version]][pypi-link]
[![Conda-Forge][conda-badge]][conda-link]
[![PyPI platforms][pypi-platforms]][pypi-link]

<!--
[![GitHub Discussion][github-discussions-badge]][github-discussions-link]
-->

<!-- SPHINX-START -->

This provides helpers for using F2Py. Use:

```cmake
include(UseF2Py)
```

You must have found a Python interpreter beforehand. This will define a
`F2Py::F2Py` target (along with a matching `F2PY_EXECUTABLE` variable). It will
also provide the following helper functions:

```cmake
f2py_object_library(<name> <type>)
f2py_generate_module(<module> <files>...
[F2PY_ARGS <args> ...]
[F77 | F90]
[NOLOWER]
[OUTPUT_DIR <OutputDir>]
[OUTPUT_VARIABLE <OutputVariable>]
)
```

## Example

```cmake
find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)
include(UseF2Py)
# Create the F2Py `numpyobject` library.
f2py_object_library(f2py_object OBJECT)
f2py_generate_module(fibby fib1.f OUTPUT_VARIABLE fibby_files)
python_add_library(fibby MODULE "${fibby_files}" WITH_SOABI)
target_link_library(fibby PRIVATE f2py_object)
```

## scikit-build-core

To use this package with scikit-build-core, you need to include it in your build
requirements:

```toml
[build-system]
requires = ["scikit-build-core", "numpy", "f2py-cmake"]
build-backend = "scikit_build_core.build"
```

<!-- prettier-ignore-start -->
[actions-badge]: https://github.com/scikit-build/f2py-cmake/workflows/CI/badge.svg
[actions-link]: https://github.com/scikit-build/f2py-cmake/actions
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/f2py-cmake
[conda-link]: https://github.com/conda-forge/f2py-cmake-feedstock
[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
[github-discussions-link]: https://github.com/scikit-build/f2py-cmake/discussions
[pypi-link]: https://pypi.org/project/f2py-cmake/
Expand Down
43 changes: 25 additions & 18 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from __future__ import annotations

import argparse
import shutil
from pathlib import Path

import nox

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

nox.needs_version = ">=2024.3.2"
nox.options.sessions = ["lint", "pylint", "tests"]
nox.options.default_venv_backend = "uv|virtualenv"
nox.options.sessions = ["lint", "pylint", "tests"]


@nox.session
Expand All @@ -31,7 +30,7 @@ def pylint(session: nox.Session) -> None:
"""
# This needs to be installed into the package environment, and is slower
# than a pre-commit check
session.install(".", "pylint>=3.2")
session.install(".", "pylint")
session.run("pylint", "f2py_cmake", *session.posargs)


Expand All @@ -40,37 +39,48 @@ def tests(session: nox.Session) -> None:
"""
Run the unit and regular tests.
"""
session.install(".[test]")
session.install("-e.[test]")
session.run("pytest", *session.posargs)


@nox.session(reuse_venv=True)
def docs(session: nox.Session) -> None:
"""
Build the docs. Pass --non-interactive to avoid serving. First positional argument is the target directory.
Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links.
"""

parser = argparse.ArgumentParser()
parser.add_argument("--serve", action="store_true", help="Serve after building")
parser.add_argument(
"-b", dest="builder", default="html", help="Build target (default: html)"
)
parser.add_argument("output", nargs="?", help="Output directory")
args, posargs = parser.parse_known_args(session.posargs)
serve = args.builder == "html" and session.interactive

session.install("-e.[docs]", "sphinx-autobuild")
if args.builder != "html" and args.serve:
session.error("Must not specify non-HTML builder with --serve")

extra_installs = ["sphinx-autobuild"] if args.serve else []

session.install("-e.[docs]", *extra_installs)
session.chdir("docs")

if args.builder == "linkcheck":
session.run(
"sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs
)
return

shared_args = (
"-n", # nitpicky mode
"-T", # full tracebacks
f"-b={args.builder}",
"docs",
args.output or f"docs/_build/{args.builder}",
".",
f"_build/{args.builder}",
*posargs,
)

if serve:
session.run("sphinx-autobuild", "--open-browser", *shared_args)
if args.serve:
session.run("sphinx-autobuild", *shared_args)
else:
session.run("sphinx-build", "--keep-going", *shared_args)

Expand All @@ -82,14 +92,15 @@ def build_api_docs(session: nox.Session) -> None:
"""

session.install("sphinx")
session.chdir("docs")
session.run(
"sphinx-apidoc",
"-o",
"docs/api/",
"api/",
"--module-first",
"--no-toc",
"--force",
"src/f2py_cmake",
"../src/f2py_cmake",
)


Expand All @@ -99,9 +110,5 @@ def build(session: nox.Session) -> None:
Build an SDist and wheel.
"""

build_path = DIR.joinpath("build")
if build_path.exists():
shutil.rmtree(build_path)

session.install("build")
session.run("python", "-m", "build")
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "f2py-cmake"
authors = [
{ name = "Henry Schreiner", email = "henryfs@princeton.edu" },
]
description = "Helper for F2Py and CMake"
description = "CMake helpers for building F2Py modules"
readme = "README.md"
license.file = "LICENSE"
requires-python = ">=3.8"
Expand All @@ -32,14 +32,14 @@ classifiers = [
dynamic = ["version"]
dependencies = []

[project.entry-points."cmake.module"]
any = "f2py_cmake.cmake"

[project.optional-dependencies]
test = [
"pytest >=6",
"pytest-cov >=3",
]
dev = [
"pytest >=6",
"pytest-cov >=3",
"scikit-build-core",
"numpy",
]
docs = [
"sphinx>=7.0",
Expand All @@ -61,9 +61,11 @@ version.source = "vcs"
build.hooks.vcs.version-file = "src/f2py_cmake/_version.py"

[tool.hatch.envs.default]
features = ["test"]
scripts.test = "pytest {args}"
installer = "uv"

[tool.hatch.envs.hatch-test]
features = ["test"]
extra-dependencies = ["cmake", "ninja"]

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down Expand Up @@ -152,6 +154,5 @@ messages_control.disable = [
"fixme",
"line-too-long",
"missing-module-docstring",
"missing-function-docstring",
"wrong-import-position",
]
2 changes: 1 addition & 1 deletion src/f2py_cmake/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Copyright (c) 2024 Henry Schreiner. All rights reserved.
f2py-cmake: Helper for F2Py and CMake
f2py-cmake: CMake helpers for building F2Py modules
"""

from __future__ import annotations
Expand Down
Loading

0 comments on commit 7aeceb9

Please sign in to comment.