Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ __pycache__
!LICENSE
!mainpage.dox
!modules
!pyproject.toml
!README.md
!Vagrant_bootstrap.sh
!Vagrantfile
Expand Down
3 changes: 0 additions & 3 deletions .python_package/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
.nox/
LICENSE
dist/
setup.cfg
*.egg-info/
src/gridtools_cpp/data
build/
48 changes: 19 additions & 29 deletions .python_package/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
# Development

In order to be able to work on this package, it is necessary to run a preparation step.
This will generate the `setup.cfg` file from `setup.cfg.in` and install the gridtools header distribution into the package data.
It will read the version number from the top-level `version.txt` and copy the `LICENSE` file to where packaging tools can find it.
The `gridtools-cpp` distribution is built from the repository root with
[scikit-build-core](https://scikit-build-core.readthedocs.io/) (see the top-level
`pyproject.toml`). The build runs the root `CMakeLists.txt` to install the headers and
CMake config into the package data, and reads the version from `version.txt` — there is
no separate preparation step.

All of this requires `nox`, the preparation step runs in an isolated environment and installs additional requirements `cmake` and `ninja` at runtime.
## Installing

As always it is recommended to carry out the following steps in a virtual environment.
From the repository root:

```bash
pip install nox
nox -s prepare
pip install .
```

To delete all generated files run
Directly from a git ref (no subdirectory needed):

```bash
nox -s clean clean_cache
pip install "git+https://github.com/GridTools/gridtools.git@<ref>"
```

where `clean_cache` deletes chached files from Nox sessions like CMake builds and testing wheels (found in `.nox/.cache`), and `clean` deletes visible artifacts like `dist/`, `build/`, `.egg-info/`.
`setup.cfg` will not be deleted for convenience, to make sure tools keep functioning as expected.

## Installing

As always it is recommended to carry out the following steps in a virtual environment:
## Building for distribution

```bash
nox -s build -- --wheel .
pip install dist/gridtools_cpp-2.2.0-py3-none-any.whl
python -m build --wheel
```

The header-only wheel is platform independent (`gridtools_cpp-<version>-py3-none-any.whl`).

## Testing

Using nox, the tests will be carried out in isolated python environments for you:
Using nox (from this directory), the tests run in isolated environments:

```bash
nox -s test_src
```

To test the wheel distribution specifically:
To build and test the wheel distribution specifically:

```bash
nox -s build_wheel test_wheel_with_python-3.10 # replace 3.10 with the Python version you are running
```

## Advanced testing (all supported versions)

The following requires you to have Python interpreters for Python 3.8, 3.9, 3.10 and 3.11 in your system path.
To run against all supported versions (requires Python 3.8, 3.9, 3.10 and 3.11 in your path):

```bash
nox
```

## Building for distribution

Uses (`build`)[https://pypa-build.readthedocs.io/en/latest/], follow the link for available options.

```bash
nox -s build -- <build options>
```
90 changes: 9 additions & 81 deletions .python_package/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,30 @@
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause

import configparser
import pathlib
import shutil

import nox


_RELATIVE_DATA_DIR = pathlib.Path("src/gridtools_cpp/data")
_ROOT = ".."


nox.options.sessions = ["test_src", "test_wheel"]


@nox.session
def prepare(session: nox.Session):
session.install("cmake>=3.18.1")
session.install("ninja")
build_path = session.cache_dir.joinpath("build").absolute()
build_path.mkdir(exist_ok=True)
install_path = pathlib.Path(".").absolute() / _RELATIVE_DATA_DIR
source_path = pathlib.Path("..").absolute()
with session.chdir(build_path):
session.run(
"cmake",
"-DBUILD_TESTING=OFF",
"-DGT_INSTALL_EXAMPLES:BOOL=OFF",
f"-DCMAKE_INSTALL_PREFIX={install_path}",
"-GNinja",
str(source_path),
)
session.run("cmake", "--install", ".")
session.log("installed gridttols sources")
version_path = source_path / "version.txt"
config = configparser.ConfigParser()
config.read("setup.cfg.in")
config["metadata"]["version"] = version_path.read_text().strip()
with open("setup.cfg", mode="w") as setup_fp:
config.write(setup_fp)
session.log("updated version metadata")
shutil.copy(source_path / "LICENSE", ".")
session.log("copied license file")


def get_wheel(session: nox.Session) -> pathlib.Path:
return list(session.cache_dir.joinpath("dist").glob("gridtools_cpp-*.whl"))[0]
def test_src(session: nox.Session):
session.install(_ROOT)
session.install("pytest")
session.run("pytest", "tests", *session.posargs)


@nox.session
def build_wheel(session: nox.Session):
prepare(session)
dist_path = session.cache_dir.joinpath("dist").absolute()
nox_workdir = pathlib.Path(".").absolute()
session.install("build[virtualenv]", "wheel")
with session.chdir(session.cache_dir):
session.run(
"python",
"-m",
"build",
"--no-isolation",
"--wheel",
"-o",
str(dist_path),
str(nox_workdir),
)
session.install("build")
session.run("python", "-m", "build", "--wheel", "-o", str(dist_path), _ROOT)
session.log(f"built wheel in {dist_path}")
session.log("\n".join(str(path) for path in dist_path.iterdir()))


@nox.session
def test_src(session: nox.Session):
prepare(session)
session.install(".")
session.install("pytest")
session.run("pytest", "tests", *session.posargs)


@nox.session
Expand All @@ -93,34 +43,12 @@ def test_wheel(session: nox.Session):

@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
def test_wheel_with_python(session: nox.Session):
wheel_path = get_wheel(session)
wheel_path = next(session.cache_dir.joinpath("dist").glob("gridtools_cpp-*.whl"))
session.install("pytest")
session.install(str(wheel_path))
session.run("pytest", "tests", *session.posargs)


@nox.session
def clean_cache(session: nox.Session):
for subtree in session.cache_dir.iterdir():
shutil.rmtree(subtree, True)


@nox.session
def build(session: nox.Session):
prepare(session)
session.install("build[virtualenv]")
session.run("python", "-m", "build", "--no-isolation", *session.posargs)


@nox.session
def clean(session: nox.Session):
data_dir = _RELATIVE_DATA_DIR
session.log(f"rm -r {data_dir}")
shutil.rmtree(data_dir, True)
session.log("rm -r src/*.egg-info")
for egg_tree in pathlib.Path("src").glob("*.egg-info"):
shutil.rmtree(egg_tree, True)
session.log("rm -r dist")
shutil.rmtree("dist", True)
session.log("rm -r build")
shutil.rmtree("build", True)
shutil.rmtree(session.cache_dir.joinpath("dist"), True)
3 changes: 0 additions & 3 deletions .python_package/pyproject.toml

This file was deleted.

45 changes: 0 additions & 45 deletions .python_package/setup.cfg.in

This file was deleted.

42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[build-system]
requires = ["scikit-build-core>=0.11"]
build-backend = "scikit_build_core.build"

[project]
name = "gridtools-cpp"
dynamic = ["version"]
description = "Python package for GridTools headers and CMake files"
readme = ".python_package/README.md"
license = "BSD-3-Clause"
license-files = ["LICENSE"]
authors = [{ name = "ETH Zurich", email = "gridtools@cscs.ch" }]
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Atmospheric Science",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics",
]

[project.urls]
Homepage = "https://gridtools.github.io"
"Source Code" = "https://github.com/GridTools/gridtools"

[tool.scikit-build]
cmake.version = ">=3.21"
wheel.py-api = "py3"
wheel.platlib = false
wheel.packages = ["src/gridtools_cpp"]
wheel.install-dir = "gridtools_cpp/data"

[tool.scikit-build.cmake.define]
BUILD_TESTING = "OFF"
GT_INSTALL_EXAMPLES = "OFF"

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "version.txt"
regex = "(?P<value>.+)"
File renamed without changes.
Loading