From 03b7de3f8cefc0d9f57ac3c20e2d89abdfa9dad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 14 Jul 2022 13:19:11 +0200 Subject: [PATCH 01/44] pip package for gt4py to depend on --- py_src/gridtools/__init__.py | 22 ++++++++++++++++++++++ pyproject.toml | 3 +++ setup.cfg | 28 ++++++++++++++++++++++++++++ setup.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 py_src/gridtools/__init__.py create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/py_src/gridtools/__init__.py b/py_src/gridtools/__init__.py new file mode 100644 index 000000000..6e0536f50 --- /dev/null +++ b/py_src/gridtools/__init__.py @@ -0,0 +1,22 @@ +# GT4Py Project - GridTools Framework +# +# Copyright (c) 2014-2021, ETH Zurich +# All rights reserved. +# +# This file is part of the GT4Py project and the GridTools framework. +# GT4Py is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or any later +# version. See the LICENSE.txt file at the top-level directory of this +# distribution for a copy of the license or check . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import pathlib + + +_file = pathlib.Path(__file__) + + +def get_cmake_path() -> pathlib.Path: + return _file.parent / "data" / "lib" / "cmake" / "GridTools" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..c1a49b58b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42", "wheel", "cmake>=2.18.1", "scikit-build"] +build_backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..25496fa0a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,28 @@ +[metadata] +name = gridtools +author = ETH Zurich +author_email = gridtools@cscs.ch +license = bsd3 +license_files = LICENSE +url = https://gridtools.github.io +project_urls = + Source Code = https://github.com/GridTools/gridtools + +[options] +zip_safe = False +packages = find: +package_dir = + =py_src +include_package_data = True +python_requires = >= 3.10 +install_requires = + cmake>=3.18.1 + +[options.packages.find] +where = py_src + +[tools:isort] +line_length = 100 + +[flake8] +max-line-length = 100 diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..1bf2734ad --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +# GT4Py Project - GridTools Framework +# +# Copyright (c) 2014-2021, ETH Zurich +# All rights reserved. +# +# This file is part of the GT4Py project and the GridTools framework. +# GT4Py is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or any later +# version. See the LICENSE.txt file at the top-level directory of this +# distribution for a copy of the license or check . +# +# SPDX-License-Identifier: GPL-3.0-or-later + + +import pathlib + +from pkg_resources import parse_version +from setuptools import find_packages +from skbuild import setup + +if __name__ == "__main__": + version_file = pathlib.Path("__file__").parent / "version.txt" + setup( + package_dir={"": "py_src"}, + packages=find_packages(where="py_src"), + version=parse_version(version_file.read_text()), + cmake_install_dir="py_src/gridtools/data", + cmake_args=["-DGT_INSTALL_EXAMPLES:BOOL=OFF"], + ) From 2e13579278d1fae9f4b014462b501decbcb169ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 14 Jul 2022 15:18:10 +0200 Subject: [PATCH 02/44] move pip package into subdir --- {py_src => pylibgt/py_src}/gridtools/__init__.py | 0 pyproject.toml => pylibgt/pyproject.toml | 0 setup.cfg => pylibgt/setup.cfg | 0 setup.py => pylibgt/setup.py | 7 ++++++- 4 files changed, 6 insertions(+), 1 deletion(-) rename {py_src => pylibgt/py_src}/gridtools/__init__.py (100%) rename pyproject.toml => pylibgt/pyproject.toml (100%) rename setup.cfg => pylibgt/setup.cfg (100%) rename setup.py => pylibgt/setup.py (79%) diff --git a/py_src/gridtools/__init__.py b/pylibgt/py_src/gridtools/__init__.py similarity index 100% rename from py_src/gridtools/__init__.py rename to pylibgt/py_src/gridtools/__init__.py diff --git a/pyproject.toml b/pylibgt/pyproject.toml similarity index 100% rename from pyproject.toml rename to pylibgt/pyproject.toml diff --git a/setup.cfg b/pylibgt/setup.cfg similarity index 100% rename from setup.cfg rename to pylibgt/setup.cfg diff --git a/setup.py b/pylibgt/setup.py similarity index 79% rename from setup.py rename to pylibgt/setup.py index 1bf2734ad..baf09b4f4 100644 --- a/setup.py +++ b/pylibgt/setup.py @@ -20,11 +20,16 @@ from skbuild import setup if __name__ == "__main__": - version_file = pathlib.Path("__file__").parent / "version.txt" + version_file = pathlib.Path(__file__).absolute().parent.parent / "version.txt" + print(pathlib.Path(__file__).absolute()) + print(version_file.absolute()) + print(version_file) + print(version_file.exists()) setup( package_dir={"": "py_src"}, packages=find_packages(where="py_src"), version=parse_version(version_file.read_text()), cmake_install_dir="py_src/gridtools/data", cmake_args=["-DGT_INSTALL_EXAMPLES:BOOL=OFF"], + cmake_source_dir="../", ) From 43a1b10249aefb7803d62d0c018aac73e8af6aa9 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Fri, 22 Jul 2022 12:56:49 +0200 Subject: [PATCH 03/44] Update pylibgt/setup.py --- pylibgt/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylibgt/setup.py b/pylibgt/setup.py index baf09b4f4..04d1d2e36 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -30,6 +30,6 @@ packages=find_packages(where="py_src"), version=parse_version(version_file.read_text()), cmake_install_dir="py_src/gridtools/data", - cmake_args=["-DGT_INSTALL_EXAMPLES:BOOL=OFF"], + cmake_args=["-DBUILD_TESTING=OFF", -DGT_INSTALL_EXAMPLES:BOOL=OFF"], cmake_source_dir="../", ) From 51b7fd42ea796e13d1b8684662b6acc765b7d31b Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Fri, 22 Jul 2022 12:57:35 +0200 Subject: [PATCH 04/44] Update pylibgt/setup.py --- pylibgt/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylibgt/setup.py b/pylibgt/setup.py index 04d1d2e36..a3d799170 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -30,6 +30,6 @@ packages=find_packages(where="py_src"), version=parse_version(version_file.read_text()), cmake_install_dir="py_src/gridtools/data", - cmake_args=["-DBUILD_TESTING=OFF", -DGT_INSTALL_EXAMPLES:BOOL=OFF"], + cmake_args=["-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF"], cmake_source_dir="../", ) From f81f6bbd300493048c5b773e6557728ce01abe81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Tue, 2 Aug 2022 14:17:36 +0200 Subject: [PATCH 05/44] remove print statements --- pylibgt/setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pylibgt/setup.py b/pylibgt/setup.py index a3d799170..388a0f967 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -21,10 +21,6 @@ if __name__ == "__main__": version_file = pathlib.Path(__file__).absolute().parent.parent / "version.txt" - print(pathlib.Path(__file__).absolute()) - print(version_file.absolute()) - print(version_file) - print(version_file.exists()) setup( package_dir={"": "py_src"}, packages=find_packages(where="py_src"), From 6c3f99b7db165ae19c17eb44157b40ce24f55e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 15:14:54 +0200 Subject: [PATCH 06/44] add test and CI --- .github/workflows/pylib-tests.yml | 24 ++++++++++++++++++++++++ pylibgt/MANIFEST.in | 2 ++ pylibgt/noxfile.py | 10 ++++++++++ pylibgt/py_src/gridtools/__init__.py | 2 +- pylibgt/pyproject.toml | 4 ++-- pylibgt/setup.py | 7 +++++++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pylib-tests.yml create mode 100644 pylibgt/MANIFEST.in create mode 100644 pylibgt/noxfile.py diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml new file mode 100644 index 000000000..7565d0121 --- /dev/null +++ b/.github/workflows/pylib-tests.yml @@ -0,0 +1,24 @@ +name: Pip install test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + piptest: + runs-on: ubuntu-latest + container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} + strategy: + matrix: + compiler: [gcc-10] + build_type: [release] + steps: + - uses: actions/checkout@v2 + - name: install nox + run: | + python3 -m pip install --upgrade pip setuptools + python3 -m pip install nox + - name: run tests + run: nox diff --git a/pylibgt/MANIFEST.in b/pylibgt/MANIFEST.in new file mode 100644 index 000000000..c0eff43a6 --- /dev/null +++ b/pylibgt/MANIFEST.in @@ -0,0 +1,2 @@ +include py_src/gridtools/__init__.py +recursive-include py_src/gridtools/data * diff --git a/pylibgt/noxfile.py b/pylibgt/noxfile.py new file mode 100644 index 000000000..09eeed02f --- /dev/null +++ b/pylibgt/noxfile.py @@ -0,0 +1,10 @@ +import nox + +nox.options.sessions = ["tests"] + + +@nox.session +def tests(session): + session.install(".") + session.install("pytest") + session.run("pytest", "tests", *session.posargs) diff --git a/pylibgt/py_src/gridtools/__init__.py b/pylibgt/py_src/gridtools/__init__.py index 6e0536f50..2a6cda5ba 100644 --- a/pylibgt/py_src/gridtools/__init__.py +++ b/pylibgt/py_src/gridtools/__init__.py @@ -18,5 +18,5 @@ _file = pathlib.Path(__file__) -def get_cmake_path() -> pathlib.Path: +def get_cmake_dir() -> pathlib.Path: return _file.parent / "data" / "lib" / "cmake" / "GridTools" diff --git a/pylibgt/pyproject.toml b/pylibgt/pyproject.toml index c1a49b58b..f75df675f 100644 --- a/pylibgt/pyproject.toml +++ b/pylibgt/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=42", "wheel", "cmake>=2.18.1", "scikit-build"] -build_backend = "setuptools.build_meta" +requires = ["setuptools>=42", "wheel", "cmake>=2.18.1", "scikit-build", "ninja"] +build-backend = "setuptools.build_meta" diff --git a/pylibgt/setup.py b/pylibgt/setup.py index 388a0f967..27b0c2edf 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -21,11 +21,18 @@ if __name__ == "__main__": version_file = pathlib.Path(__file__).absolute().parent.parent / "version.txt" + print(pathlib.Path(__file__).absolute()) + print(version_file.absolute()) + print(version_file) + print(version_file.exists()) setup( package_dir={"": "py_src"}, packages=find_packages(where="py_src"), version=parse_version(version_file.read_text()), + include_package_data=True, + package_data={"gridtools": ["*.hpp", "*.h", "*.cmake"]}, cmake_install_dir="py_src/gridtools/data", cmake_args=["-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF"], cmake_source_dir="../", + cmake_with_sdist=True, ) From be6f794dec944ffaab83ef52a3d3d9bd6cc0afc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 15:23:20 +0200 Subject: [PATCH 07/44] fix piptest CI --- .github/workflows/pylib-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 7565d0121..30dcf6144 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -21,4 +21,4 @@ jobs: python3 -m pip install --upgrade pip setuptools python3 -m pip install nox - name: run tests - run: nox + run: nox --noxfile pylibgt/noxfile.py From 37f68ff01866b030ccae191d3065f31955fe1b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 15:26:17 +0200 Subject: [PATCH 08/44] set python version for pylib CI to 3.10 --- .github/workflows/pylib-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 30dcf6144..25ba22c5f 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -7,11 +7,12 @@ on: branches: [ master ] jobs: - piptest: + nox-tests: runs-on: ubuntu-latest container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} strategy: matrix: + python-version: ["3.10"] compiler: [gcc-10] build_type: [release] steps: From 6d00ba2a0f35c92356a50236201bd64f9175b224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 16:02:23 +0200 Subject: [PATCH 09/44] use python instead of python3 in nox-ci --- .github/workflows/pylib-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 25ba22c5f..3229746b8 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - name: install nox run: | - python3 -m pip install --upgrade pip setuptools - python3 -m pip install nox + python -m pip install --upgrade pip setuptools + python -m pip install nox - name: run tests run: nox --noxfile pylibgt/noxfile.py From 06333b8fd92b7b4017909b90d56ee4ef118543b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 16:04:02 +0200 Subject: [PATCH 10/44] add python setup step to nox-ci --- .github/workflows/pylib-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 3229746b8..5c324b973 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -17,6 +17,10 @@ jobs: build_type: [release] steps: - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} - name: install nox run: | python -m pip install --upgrade pip setuptools From 2cea7bf67fa9478a37b90dc2ca12c90ed27bbffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 16:16:25 +0200 Subject: [PATCH 11/44] add workdir to nox-ci --- .github/workflows/pylib-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 5c324b973..1c699677b 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -26,4 +26,5 @@ jobs: python -m pip install --upgrade pip setuptools python -m pip install nox - name: run tests - run: nox --noxfile pylibgt/noxfile.py + working-directory: ./pylibgt + run: nox From e37f9773a8bc4527823f17c95827f71ac098cf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 3 Aug 2022 16:24:29 +0200 Subject: [PATCH 12/44] add tests --- pylibgt/tests/test_get_cmake_dir.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pylibgt/tests/test_get_cmake_dir.py diff --git a/pylibgt/tests/test_get_cmake_dir.py b/pylibgt/tests/test_get_cmake_dir.py new file mode 100644 index 000000000..1284613a5 --- /dev/null +++ b/pylibgt/tests/test_get_cmake_dir.py @@ -0,0 +1,20 @@ +# GT4Py Project - GridTools Framework +# +# Copyright (c) 2014-2021, ETH Zurich +# All rights reserved. +# +# This file is part of the GT4Py project and the GridTools framework. +# GT4Py is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or any later +# version. See the LICENSE.txt file at the top-level directory of this +# distribution for a copy of the license or check . +# +# SPDX-License-Identifier: GPL-3.0-or-later +from gridtools import get_cmake_dir + + +def test_cmake_dir_contains_gridtools_cmake(): + main_config_file = get_cmake_dir() / "GridToolsConfig.cmake" + assert main_config_file.exists() + assert main_config_file.read_text() From 7662b2902e2fd79482bd7b8b803bb7a76e4a34d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:02:42 +0100 Subject: [PATCH 13/44] add test for wheel build --- pylibgt/noxfile.py | 12 +++++++++++- pylibgt/setup.py | 6 +----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pylibgt/noxfile.py b/pylibgt/noxfile.py index 09eeed02f..8cef8c40f 100644 --- a/pylibgt/noxfile.py +++ b/pylibgt/noxfile.py @@ -1,6 +1,7 @@ +import pathlib import nox -nox.options.sessions = ["tests"] +nox.options.sessions = ["tests", "test_wheel"] @nox.session @@ -8,3 +9,12 @@ def tests(session): session.install(".") session.install("pytest") session.run("pytest", "tests", *session.posargs) + + +@nox.session +def test_wheel(session): + session.install("pip") + session.run("pip", "wheel", "-w", "dist", ".") + wheel_path = list(pathlib.Path("./dist").glob("gridtools-*.whl"))[0] + session.install(str(wheel_path)) + session.run("pytest", "tests", *session.posargs) diff --git a/pylibgt/setup.py b/pylibgt/setup.py index 27b0c2edf..99a26b9bb 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -21,14 +21,10 @@ if __name__ == "__main__": version_file = pathlib.Path(__file__).absolute().parent.parent / "version.txt" - print(pathlib.Path(__file__).absolute()) - print(version_file.absolute()) - print(version_file) - print(version_file.exists()) setup( package_dir={"": "py_src"}, packages=find_packages(where="py_src"), - version=parse_version(version_file.read_text()), + version=str(parse_version(version_file.read_text())), include_package_data=True, package_data={"gridtools": ["*.hpp", "*.h", "*.cmake"]}, cmake_install_dir="py_src/gridtools/data", From 41fa89a2c0a5a3f20670167961fac139a926d26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:07:54 +0100 Subject: [PATCH 14/44] fix headers for all py files --- pylibgt/noxfile.py | 8 ++++++++ pylibgt/py_src/gridtools/__init__.py | 12 +++--------- pylibgt/setup.py | 13 +++---------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/pylibgt/noxfile.py b/pylibgt/noxfile.py index 8cef8c40f..839edb1e9 100644 --- a/pylibgt/noxfile.py +++ b/pylibgt/noxfile.py @@ -1,3 +1,11 @@ +# GridTools +# +# Copyright (c) 2014-2021, ETH Zurich +# All rights reserved. +# +# Please, refer to the LICENSE file in the root directory. +# SPDX-License-Identifier: BSD-3-Clause + import pathlib import nox diff --git a/pylibgt/py_src/gridtools/__init__.py b/pylibgt/py_src/gridtools/__init__.py index 2a6cda5ba..0702b86df 100644 --- a/pylibgt/py_src/gridtools/__init__.py +++ b/pylibgt/py_src/gridtools/__init__.py @@ -1,16 +1,10 @@ -# GT4Py Project - GridTools Framework +# GridTools # # Copyright (c) 2014-2021, ETH Zurich # All rights reserved. # -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later +# Please, refer to the LICENSE file in the root directory. +# SPDX-License-Identifier: BSD-3-Clause import pathlib diff --git a/pylibgt/setup.py b/pylibgt/setup.py index 99a26b9bb..6accc118a 100644 --- a/pylibgt/setup.py +++ b/pylibgt/setup.py @@ -1,17 +1,10 @@ -# GT4Py Project - GridTools Framework +# GridTools # # Copyright (c) 2014-2021, ETH Zurich # All rights reserved. # -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - +# Please, refer to the LICENSE file in the root directory. +# SPDX-License-Identifier: BSD-3-Clause import pathlib From 5fe6a994562dd7b063d1dd2bc85cba30e25a4db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:11:18 +0100 Subject: [PATCH 15/44] fix licence header also for tests --- pylibgt/tests/test_get_cmake_dir.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pylibgt/tests/test_get_cmake_dir.py b/pylibgt/tests/test_get_cmake_dir.py index 1284613a5..375356d9b 100644 --- a/pylibgt/tests/test_get_cmake_dir.py +++ b/pylibgt/tests/test_get_cmake_dir.py @@ -1,16 +1,11 @@ -# GT4Py Project - GridTools Framework +# GridTools # # Copyright (c) 2014-2021, ETH Zurich # All rights reserved. # -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later +# Please, refer to the LICENSE file in the root directory. +# SPDX-License-Identifier: BSD-3-Clause + from gridtools import get_cmake_dir From 35ef68f2ba45c435d4cd11d4d600bf50821d47a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:21:22 +0100 Subject: [PATCH 16/44] add get_include_dir method and test --- pylibgt/noxfile.py | 1 + pylibgt/py_src/gridtools/__init__.py | 4 ++++ pylibgt/tests/test_get_cmake_dir.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pylibgt/noxfile.py b/pylibgt/noxfile.py index 839edb1e9..afb65b41e 100644 --- a/pylibgt/noxfile.py +++ b/pylibgt/noxfile.py @@ -22,6 +22,7 @@ def tests(session): @nox.session def test_wheel(session): session.install("pip") + session.install("pytest") session.run("pip", "wheel", "-w", "dist", ".") wheel_path = list(pathlib.Path("./dist").glob("gridtools-*.whl"))[0] session.install(str(wheel_path)) diff --git a/pylibgt/py_src/gridtools/__init__.py b/pylibgt/py_src/gridtools/__init__.py index 0702b86df..0a7038cac 100644 --- a/pylibgt/py_src/gridtools/__init__.py +++ b/pylibgt/py_src/gridtools/__init__.py @@ -14,3 +14,7 @@ def get_cmake_dir() -> pathlib.Path: return _file.parent / "data" / "lib" / "cmake" / "GridTools" + + +def get_include_dir() -> pathlib.Path: + return _file.parent / "data" / "include" / "gridtools" diff --git a/pylibgt/tests/test_get_cmake_dir.py b/pylibgt/tests/test_get_cmake_dir.py index 375356d9b..185ac9fac 100644 --- a/pylibgt/tests/test_get_cmake_dir.py +++ b/pylibgt/tests/test_get_cmake_dir.py @@ -6,10 +6,16 @@ # Please, refer to the LICENSE file in the root directory. # SPDX-License-Identifier: BSD-3-Clause -from gridtools import get_cmake_dir +import gridtools def test_cmake_dir_contains_gridtools_cmake(): - main_config_file = get_cmake_dir() / "GridToolsConfig.cmake" + main_config_file = gridtools.get_cmake_dir() / "GridToolsConfig.cmake" assert main_config_file.exists() assert main_config_file.read_text() + + +def test_include_dir_contains_headers(): + include_path = gridtools.get_include_dir() + assert include_path.exists() + assert len(list(include_path.rglob("*.hpp"))) > 0 From c4bb261ed057f7a2f8cbc397ef7b57a57ea7dfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:39:20 +0100 Subject: [PATCH 17/44] remove duplicate setup keys from cfg --- pylibgt/setup.cfg | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pylibgt/setup.cfg b/pylibgt/setup.cfg index 25496fa0a..7a3cec179 100644 --- a/pylibgt/setup.cfg +++ b/pylibgt/setup.cfg @@ -9,18 +9,10 @@ project_urls = Source Code = https://github.com/GridTools/gridtools [options] -zip_safe = False -packages = find: -package_dir = - =py_src -include_package_data = True -python_requires = >= 3.10 +python_requires = >= 3.0 install_requires = cmake>=3.18.1 -[options.packages.find] -where = py_src - [tools:isort] line_length = 100 From 8a9a6744bd70661742fc8fe88b88600e350abd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:42:37 +0100 Subject: [PATCH 18/44] renamed to .python_package --- {pylibgt => .python_package}/MANIFEST.in | 0 {pylibgt => .python_package}/noxfile.py | 0 {pylibgt => .python_package}/py_src/gridtools/__init__.py | 0 {pylibgt => .python_package}/pyproject.toml | 0 {pylibgt => .python_package}/setup.cfg | 0 {pylibgt => .python_package}/setup.py | 0 {pylibgt => .python_package}/tests/test_get_cmake_dir.py | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename {pylibgt => .python_package}/MANIFEST.in (100%) rename {pylibgt => .python_package}/noxfile.py (100%) rename {pylibgt => .python_package}/py_src/gridtools/__init__.py (100%) rename {pylibgt => .python_package}/pyproject.toml (100%) rename {pylibgt => .python_package}/setup.cfg (100%) rename {pylibgt => .python_package}/setup.py (100%) rename {pylibgt => .python_package}/tests/test_get_cmake_dir.py (100%) diff --git a/pylibgt/MANIFEST.in b/.python_package/MANIFEST.in similarity index 100% rename from pylibgt/MANIFEST.in rename to .python_package/MANIFEST.in diff --git a/pylibgt/noxfile.py b/.python_package/noxfile.py similarity index 100% rename from pylibgt/noxfile.py rename to .python_package/noxfile.py diff --git a/pylibgt/py_src/gridtools/__init__.py b/.python_package/py_src/gridtools/__init__.py similarity index 100% rename from pylibgt/py_src/gridtools/__init__.py rename to .python_package/py_src/gridtools/__init__.py diff --git a/pylibgt/pyproject.toml b/.python_package/pyproject.toml similarity index 100% rename from pylibgt/pyproject.toml rename to .python_package/pyproject.toml diff --git a/pylibgt/setup.cfg b/.python_package/setup.cfg similarity index 100% rename from pylibgt/setup.cfg rename to .python_package/setup.cfg diff --git a/pylibgt/setup.py b/.python_package/setup.py similarity index 100% rename from pylibgt/setup.py rename to .python_package/setup.py diff --git a/pylibgt/tests/test_get_cmake_dir.py b/.python_package/tests/test_get_cmake_dir.py similarity index 100% rename from pylibgt/tests/test_get_cmake_dir.py rename to .python_package/tests/test_get_cmake_dir.py From e2f104737f0b3ca7bcae4570c58d54e58a0ab354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 11 Nov 2022 17:44:06 +0100 Subject: [PATCH 19/44] rename test module --- .python_package/tests/{test_get_cmake_dir.py => test_dirs.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .python_package/tests/{test_get_cmake_dir.py => test_dirs.py} (100%) diff --git a/.python_package/tests/test_get_cmake_dir.py b/.python_package/tests/test_dirs.py similarity index 100% rename from .python_package/tests/test_get_cmake_dir.py rename to .python_package/tests/test_dirs.py From 0628d7f82e133eef57d23a319b8c1826a9d2c8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Mon, 14 Nov 2022 10:26:46 +0100 Subject: [PATCH 20/44] update CI with new python package dir --- .github/workflows/pylib-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/pylib-tests.yml index 1c699677b..e7e78203b 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/pylib-tests.yml @@ -26,5 +26,5 @@ jobs: python -m pip install --upgrade pip setuptools python -m pip install nox - name: run tests - working-directory: ./pylibgt + working-directory: ./.python_package run: nox From 2e1b28eff8059a63ef283b6387d839bf61a60669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Tue, 15 Nov 2022 15:49:39 +0100 Subject: [PATCH 21/44] reusable build_wheel session with caching --- .python_package/noxfile.py | 57 ++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index afb65b41e..90517aa78 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -6,24 +6,69 @@ # Please, refer to the LICENSE file in the root directory. # SPDX-License-Identifier: BSD-3-Clause +import argparse import pathlib +import shutil + import nox nox.options.sessions = ["tests", "test_wheel"] +def get_wheel(session: nox.Session) -> pathlib.Path: + return list(session.cache_dir.joinpath("dist").glob("gridtools-*.whl"))[0] + + +@nox.session(tags=["build"]) +def build_wheel(session: nox.Session): + dist_path = session.cache_dir.joinpath("dist").absolute() + workdir = pathlib.Path(".").absolute() + session.install("pip") + with session.chdir(session.cache_dir): + session.run("pip", "wheel", "-w", str(dist_path), str(workdir)) + session.notify("test_wheel") + + @nox.session -def tests(session): +def reuse_wheel(session: nox.Session): + parser = argparse.ArgumentParser() + parser.add_argument("--rebuild-wheel", action="store_true") + args = parser.parse_args(args=session.posargs) + + session.log("checking for cached wheel") + try: + get_wheel(session) + session.log("cached wheel found") + except IndexError: + session.log("cached wheel not found") + build_wheel(session) + else: + if args.rebuild_wheel: + session.log("wheel rebuild requested") + session.posargs.remove("--rebuild-wheel") + build_wheel(session) + + +@nox.session(tags=["test"]) +def tests(session: nox.Session): session.install(".") session.install("pytest") session.run("pytest", "tests", *session.posargs) -@nox.session -def test_wheel(session): - session.install("pip") +@nox.session(tags=["test"]) +def test_wheel(session: nox.Session): + reuse_wheel(session) + wheel_path = get_wheel(session) session.install("pytest") - session.run("pip", "wheel", "-w", "dist", ".") - wheel_path = list(pathlib.Path("./dist").glob("gridtools-*.whl"))[0] session.install(str(wheel_path)) session.run("pytest", "tests", *session.posargs) + + +@nox.session(tags=["build"]) +def copy_wheel(session: nox.Session): + reuse_wheel(session) + wheel_path = get_wheel(session) + dist_path = pathlib.Path("./dist") + dist_path.mkdir(exist_ok=True) + shutil.copy(wheel_path, dist_path) From ccaf5f81f7544cce24c94eb4ccfd84fd93a6e670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 18 Nov 2022 09:37:44 +0100 Subject: [PATCH 22/44] rename python package github action --- .github/workflows/{pylib-tests.yml => python-package-tests.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{pylib-tests.yml => python-package-tests.yml} (96%) diff --git a/.github/workflows/pylib-tests.yml b/.github/workflows/python-package-tests.yml similarity index 96% rename from .github/workflows/pylib-tests.yml rename to .github/workflows/python-package-tests.yml index e7e78203b..cbd0fa3e7 100644 --- a/.github/workflows/pylib-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -1,4 +1,4 @@ -name: Pip install test +name: Python Package Tests on: push: From 8e8be706019eb7bf3cdb75bb38386f3f1ddabd39 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 21 Nov 2022 16:57:34 +0100 Subject: [PATCH 23/44] Update .python_package/py_src/gridtools/__init__.py --- .python_package/py_src/gridtools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.python_package/py_src/gridtools/__init__.py b/.python_package/py_src/gridtools/__init__.py index 0a7038cac..6895d4475 100644 --- a/.python_package/py_src/gridtools/__init__.py +++ b/.python_package/py_src/gridtools/__init__.py @@ -17,4 +17,4 @@ def get_cmake_dir() -> pathlib.Path: def get_include_dir() -> pathlib.Path: - return _file.parent / "data" / "include" / "gridtools" + return _file.parent / "data" / "include" From d2289e97243b2bf1444c1dd4125d0aa527ad78cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Tue, 22 Nov 2022 12:44:48 +0100 Subject: [PATCH 24/44] clean up noxfile --- .python_package/noxfile.py | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index 90517aa78..0cbd9d174 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -6,9 +6,7 @@ # Please, refer to the LICENSE file in the root directory. # SPDX-License-Identifier: BSD-3-Clause -import argparse import pathlib -import shutil import nox @@ -19,56 +17,28 @@ def get_wheel(session: nox.Session) -> pathlib.Path: return list(session.cache_dir.joinpath("dist").glob("gridtools-*.whl"))[0] -@nox.session(tags=["build"]) +@nox.session def build_wheel(session: nox.Session): dist_path = session.cache_dir.joinpath("dist").absolute() workdir = pathlib.Path(".").absolute() session.install("pip") with session.chdir(session.cache_dir): session.run("pip", "wheel", "-w", str(dist_path), str(workdir)) + session.log(f"built wheel in {dist_path}") session.notify("test_wheel") @nox.session -def reuse_wheel(session: nox.Session): - parser = argparse.ArgumentParser() - parser.add_argument("--rebuild-wheel", action="store_true") - args = parser.parse_args(args=session.posargs) - - session.log("checking for cached wheel") - try: - get_wheel(session) - session.log("cached wheel found") - except IndexError: - session.log("cached wheel not found") - build_wheel(session) - else: - if args.rebuild_wheel: - session.log("wheel rebuild requested") - session.posargs.remove("--rebuild-wheel") - build_wheel(session) - - -@nox.session(tags=["test"]) def tests(session: nox.Session): session.install(".") session.install("pytest") session.run("pytest", "tests", *session.posargs) -@nox.session(tags=["test"]) +@nox.session def test_wheel(session: nox.Session): - reuse_wheel(session) + build_wheel(session) wheel_path = get_wheel(session) session.install("pytest") session.install(str(wheel_path)) session.run("pytest", "tests", *session.posargs) - - -@nox.session(tags=["build"]) -def copy_wheel(session: nox.Session): - reuse_wheel(session) - wheel_path = get_wheel(session) - dist_path = pathlib.Path("./dist") - dist_path.mkdir(exist_ok=True) - shutil.copy(wheel_path, dist_path) From c77d8ee2589dd949ebec90426190bc68150af982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Tue, 22 Nov 2022 12:45:36 +0100 Subject: [PATCH 25/44] update minimum compatible python version to 3.4 --- .python_package/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index 7a3cec179..87eb9fc3c 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -9,7 +9,7 @@ project_urls = Source Code = https://github.com/GridTools/gridtools [options] -python_requires = >= 3.0 +python_requires = >= 3.4 install_requires = cmake>=3.18.1 From 23cc4eb98495ee4c75b669e9ff753fa195cb512f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Tue, 22 Nov 2022 12:48:25 +0100 Subject: [PATCH 26/44] remove MANIFEST.in and `include_package_data=True` --- .python_package/MANIFEST.in | 2 -- .python_package/setup.py | 1 - 2 files changed, 3 deletions(-) delete mode 100644 .python_package/MANIFEST.in diff --git a/.python_package/MANIFEST.in b/.python_package/MANIFEST.in deleted file mode 100644 index c0eff43a6..000000000 --- a/.python_package/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include py_src/gridtools/__init__.py -recursive-include py_src/gridtools/data * diff --git a/.python_package/setup.py b/.python_package/setup.py index 6accc118a..88a899c2d 100644 --- a/.python_package/setup.py +++ b/.python_package/setup.py @@ -18,7 +18,6 @@ package_dir={"": "py_src"}, packages=find_packages(where="py_src"), version=str(parse_version(version_file.read_text())), - include_package_data=True, package_data={"gridtools": ["*.hpp", "*.h", "*.cmake"]}, cmake_install_dir="py_src/gridtools/data", cmake_args=["-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF"], From 1085e5beef14c60ca7ee66dbe139340a9f4a75f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 23 Nov 2022 16:57:50 +0100 Subject: [PATCH 27/44] add cmake build/install to nox instead of setup.py --- .github/workflows/python-package-tests.yml | 2 +- .python_package/noxfile.py | 84 ++++++++++++++++++++-- .python_package/pyproject.toml | 2 +- .python_package/setup.cfg | 25 +++++-- .python_package/setup.py | 26 ------- 5 files changed, 101 insertions(+), 38 deletions(-) delete mode 100644 .python_package/setup.py diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index cbd0fa3e7..20864afc6 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -27,4 +27,4 @@ jobs: python -m pip install nox - name: run tests working-directory: ./.python_package - run: nox + run: nox -s test_src_dist build_wheel test_wheel_with_python-${{ matrix.python-version }} diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index 0cbd9d174..fe221fdcc 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -6,11 +6,39 @@ # Please, refer to the LICENSE file in the root directory. # SPDX-License-Identifier: BSD-3-Clause +import configparser import pathlib +import shutil import nox -nox.options.sessions = ["tests", "test_wheel"] +nox.options.sessions = ["test_src_dist", "test_wheel"] + + +def prepare(session: nox.Session): + session.install("cmake>=2.18.1") + session.install("ninja") + build_path = session.cache_dir.joinpath("build").absolute() + build_path.mkdir(exist_ok=True) + install_path = pathlib.Path(".").absolute() / "py_src" / "gridtools" / "data" + 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}", + str(source_path) + ) + session.run("make", "install") + session.log("installed gridttols sources") + version_path = source_path / "version.txt" + setup_path = pathlib.Path(".") / "setup.cfg" + config = configparser.ConfigParser() + config.read(str(setup_path)) + config["metadata"]["version"] = version_path.read_text() + with setup_path.open("w") as setup_fp: + config.write(setup_fp) def get_wheel(session: nox.Session) -> pathlib.Path: @@ -19,17 +47,25 @@ def get_wheel(session: nox.Session) -> pathlib.Path: @nox.session def build_wheel(session: nox.Session): + prepare(session) dist_path = session.cache_dir.joinpath("dist").absolute() workdir = pathlib.Path(".").absolute() - session.install("pip") + session.install("build[virtualenv]") with session.chdir(session.cache_dir): - session.run("pip", "wheel", "-w", str(dist_path), str(workdir)) + session.run( + "python", + "-m", "build", + "--no-isolation", + "--wheel", + "-o", str(dist_path), + str(workdir), + ) session.log(f"built wheel in {dist_path}") - session.notify("test_wheel") @nox.session -def tests(session: nox.Session): +def test_src_dist(session: nox.Session): + prepare(session) session.install(".") session.install("pytest") session.run("pytest", "tests", *session.posargs) @@ -37,8 +73,44 @@ def tests(session: nox.Session): @nox.session def test_wheel(session: nox.Session): - build_wheel(session) + session.notify("build_wheel") + session.notify("test_wheel_with_python-3.8") + session.notify("test_wheel_with_python-3.9") + session.notify("test_wheel_with_python-3.10") + session.notify("test_wheel_with_python-3.11") + + +@nox.session(python=["3.8", "3.9", "3.10", "3.11"]) +def test_wheel_with_python(session: nox.Session): wheel_path = get_wheel(session) 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): + top_dir = pathlib.Path(".") + data_dir = top_dir / "py_src" / "gridtools" / "data" + session.log(f"rm -r {data_dir}") + shutil.rmtree(data_dir, True) + session.log("rm -r py_src/*.egg-info") + for egg_tree in top_dir.joinpath("py_src").glob("*.egg-info"): + shutil.rmtree(egg_tree, True) + session.log("rm -r dist") + shutil.rmtree(top_dir / "dist", True) + session.log("rm -r build") + shutil.rmtree(top_dir / "build", True) diff --git a/.python_package/pyproject.toml b/.python_package/pyproject.toml index f75df675f..7b959378a 100644 --- a/.python_package/pyproject.toml +++ b/.python_package/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=42", "wheel", "cmake>=2.18.1", "scikit-build", "ninja"] +requires = ["setuptools>=64", "wheel"] build-backend = "setuptools.build_meta" diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index 87eb9fc3c..65bb2495c 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -5,16 +5,33 @@ author_email = gridtools@cscs.ch license = bsd3 license_files = LICENSE url = https://gridtools.github.io -project_urls = - Source Code = https://github.com/GridTools/gridtools +project_urls = + Source Code = https://github.com/GridTools/gridtools +platforms = any +version = 2.2.0 + [options] -python_requires = >= 3.4 +packages = find_namespace: +package_dir = + = py_src +python_requires = >=3.4 install_requires = - cmake>=3.18.1 + cmake>=3.18.1 + +[options.package_data] +* = + *.hpp + *.h + *.cmake + +[options.packages.find] +where = py_src +exclude = tests [tools:isort] line_length = 100 [flake8] max-line-length = 100 + diff --git a/.python_package/setup.py b/.python_package/setup.py deleted file mode 100644 index 88a899c2d..000000000 --- a/.python_package/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -# GridTools -# -# Copyright (c) 2014-2021, ETH Zurich -# All rights reserved. -# -# Please, refer to the LICENSE file in the root directory. -# SPDX-License-Identifier: BSD-3-Clause - -import pathlib - -from pkg_resources import parse_version -from setuptools import find_packages -from skbuild import setup - -if __name__ == "__main__": - version_file = pathlib.Path(__file__).absolute().parent.parent / "version.txt" - setup( - package_dir={"": "py_src"}, - packages=find_packages(where="py_src"), - version=str(parse_version(version_file.read_text())), - package_data={"gridtools": ["*.hpp", "*.h", "*.cmake"]}, - cmake_install_dir="py_src/gridtools/data", - cmake_args=["-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF"], - cmake_source_dir="../", - cmake_with_sdist=True, - ) From c6155bf4c50221868f6ade5a0ff8481aa63de3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Wed, 23 Nov 2022 17:01:57 +0100 Subject: [PATCH 28/44] change distribution name --- .python_package/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index 65bb2495c..24c26eb40 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = gridtools +name = gridtools-cpp author = ETH Zurich author_email = gridtools@cscs.ch license = bsd3 From 7ddd67887e1ca3bcb026184597996d957943632e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 11:47:55 +0100 Subject: [PATCH 29/44] update dist name in noxfile --- .python_package/noxfile.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index fe221fdcc..f993e3ae1 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -28,7 +28,7 @@ def prepare(session: nox.Session): "-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF", f"-DCMAKE_INSTALL_PREFIX={install_path}", - str(source_path) + str(source_path), ) session.run("make", "install") session.log("installed gridttols sources") @@ -42,7 +42,7 @@ def prepare(session: nox.Session): def get_wheel(session: nox.Session) -> pathlib.Path: - return list(session.cache_dir.joinpath("dist").glob("gridtools-*.whl"))[0] + return list(session.cache_dir.joinpath("dist").glob("gridtools_cpp-*.whl"))[0] @nox.session @@ -54,13 +54,16 @@ def build_wheel(session: nox.Session): with session.chdir(session.cache_dir): session.run( "python", - "-m", "build", + "-m", + "build", "--no-isolation", "--wheel", - "-o", str(dist_path), + "-o", + str(dist_path), str(workdir), ) - session.log(f"built wheel in {dist_path}") + session.log(f"built wheel in {dist_path}") + session.log("\n".join(str(path) for path in dist_path.iterdir())) @nox.session From 6e2fec7e3f918ca01f96772a89bb98313f25b70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 12:04:55 +0100 Subject: [PATCH 30/44] try testing wheel on matrix of python versions --- .github/workflows/python-package-tests.yml | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index 20864afc6..f60678055 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -7,7 +7,7 @@ on: branches: [ master ] jobs: - nox-tests: + build-wheel: runs-on: ubuntu-latest container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} strategy: @@ -27,4 +27,37 @@ jobs: python -m pip install nox - name: run tests working-directory: ./.python_package - run: nox -s test_src_dist build_wheel test_wheel_with_python-${{ matrix.python-version }} + run: nox -s test_src_dist + - name: build and test wheel + working-directory: ./.python_package + run: nox -s build_wheel test_wheel_with_python-${{ matrix.python-version }} + - name: archive wheel + uses: actions/upload-artifact@v3 + with: + name: gridtools-cpp-wheel + path: .nox/.cache/dist/gridtools_cpp-*.whl + + test-wheel: + runs-on: ubuntu-latest + container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} + strategy: + matrix: + python-version: ["3.8", "3.9", "3.11"] + compiler: [gcc-10] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: install nox + run: | + python -m pip install --upgrade pip setuptools + python -m pip install nox + - name: download wheel + uses: actions/download-artifact@v3 + with: + name: gridtools-cpp-wheel + - name: test wheel + working-directory: ./.python_package + run: nox -s test_wheel_with_python-${{ matrix.python-version }} From e04a3b43ced1092db1a825ef1704e3ce49f3da54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 12:06:44 +0100 Subject: [PATCH 31/44] add dependency between build and test jobs --- .github/workflows/python-package-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index f60678055..6ce432f6b 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -38,6 +38,7 @@ jobs: path: .nox/.cache/dist/gridtools_cpp-*.whl test-wheel: + needs: build-wheel runs-on: ubuntu-latest container: ghcr.io/gridtools/gridtools-base:${{ matrix.compiler }} strategy: From d17034ed0161892a7070fa7354dec5b6a96e13c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 12:08:25 +0100 Subject: [PATCH 32/44] set cwd of wheel upload step --- .github/workflows/python-package-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index 6ce432f6b..d5e25d22f 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -33,6 +33,7 @@ jobs: run: nox -s build_wheel test_wheel_with_python-${{ matrix.python-version }} - name: archive wheel uses: actions/upload-artifact@v3 + working-directory: ./.python_package with: name: gridtools-cpp-wheel path: .nox/.cache/dist/gridtools_cpp-*.whl @@ -57,6 +58,7 @@ jobs: python -m pip install nox - name: download wheel uses: actions/download-artifact@v3 + working-directory: ./.python_package with: name: gridtools-cpp-wheel - name: test wheel From 393649ab72717a02ade1ff0aa30e4d3ff7e8630a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 12:10:55 +0100 Subject: [PATCH 33/44] change artifact path instead of pwd --- .github/workflows/python-package-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index d5e25d22f..658fd1b3d 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -33,10 +33,9 @@ jobs: run: nox -s build_wheel test_wheel_with_python-${{ matrix.python-version }} - name: archive wheel uses: actions/upload-artifact@v3 - working-directory: ./.python_package with: name: gridtools-cpp-wheel - path: .nox/.cache/dist/gridtools_cpp-*.whl + path: .python_package/.nox/.cache/dist/gridtools_cpp-*.whl test-wheel: needs: build-wheel @@ -58,7 +57,6 @@ jobs: python -m pip install nox - name: download wheel uses: actions/download-artifact@v3 - working-directory: ./.python_package with: name: gridtools-cpp-wheel - name: test wheel From 006c0841c1f0cd56fbed99100f455d9e8c14cc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 24 Nov 2022 15:03:55 +0100 Subject: [PATCH 34/44] download wheel to the right path --- .github/workflows/python-package-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index 658fd1b3d..a3979d77c 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -59,6 +59,7 @@ jobs: uses: actions/download-artifact@v3 with: name: gridtools-cpp-wheel + path: .python_package/.nox/.cache/dist - name: test wheel working-directory: ./.python_package run: nox -s test_wheel_with_python-${{ matrix.python-version }} From 1483de842bbb34d9fd63d48916bca86da7a99480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 10:53:11 +0100 Subject: [PATCH 35/44] cleanup and add package metadata --- .github/workflows/python-package-tests.yml | 2 +- .python_package/noxfile.py | 15 +++++++++------ .python_package/setup.cfg | 13 +++++++++---- .../{py_src => src}/gridtools/__init__.py | 0 4 files changed, 19 insertions(+), 11 deletions(-) rename .python_package/{py_src => src}/gridtools/__init__.py (100%) diff --git a/.github/workflows/python-package-tests.yml b/.github/workflows/python-package-tests.yml index a3979d77c..9a055ae27 100644 --- a/.github/workflows/python-package-tests.yml +++ b/.github/workflows/python-package-tests.yml @@ -27,7 +27,7 @@ jobs: python -m pip install nox - name: run tests working-directory: ./.python_package - run: nox -s test_src_dist + run: nox -s test_src - name: build and test wheel working-directory: ./.python_package run: nox -s build_wheel test_wheel_with_python-${{ matrix.python-version }} diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index f993e3ae1..226948f74 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -12,7 +12,7 @@ import nox -nox.options.sessions = ["test_src_dist", "test_wheel"] +nox.options.sessions = ["test_src", "test_wheel"] def prepare(session: nox.Session): @@ -20,7 +20,7 @@ def prepare(session: nox.Session): session.install("ninja") build_path = session.cache_dir.joinpath("build").absolute() build_path.mkdir(exist_ok=True) - install_path = pathlib.Path(".").absolute() / "py_src" / "gridtools" / "data" + install_path = pathlib.Path(".").absolute() / "src" / "gridtools" / "data" source_path = pathlib.Path("..").absolute() with session.chdir(build_path): session.run( @@ -39,6 +39,9 @@ def prepare(session: nox.Session): config["metadata"]["version"] = version_path.read_text() with setup_path.open("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: @@ -67,7 +70,7 @@ def build_wheel(session: nox.Session): @nox.session -def test_src_dist(session: nox.Session): +def test_src(session: nox.Session): prepare(session) session.install(".") session.install("pytest") @@ -107,11 +110,11 @@ def build(session: nox.Session): @nox.session def clean(session: nox.Session): top_dir = pathlib.Path(".") - data_dir = top_dir / "py_src" / "gridtools" / "data" + data_dir = top_dir / "src" / "gridtools" / "data" session.log(f"rm -r {data_dir}") shutil.rmtree(data_dir, True) - session.log("rm -r py_src/*.egg-info") - for egg_tree in top_dir.joinpath("py_src").glob("*.egg-info"): + session.log("rm -r src/*.egg-info") + for egg_tree in top_dir.joinpath("src").glob("*.egg-info"): shutil.rmtree(egg_tree, True) session.log("rm -r dist") shutil.rmtree(top_dir / "dist", True) diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index 24c26eb40..72d872fdd 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -2,7 +2,6 @@ name = gridtools-cpp author = ETH Zurich author_email = gridtools@cscs.ch -license = bsd3 license_files = LICENSE url = https://gridtools.github.io project_urls = @@ -10,12 +9,18 @@ project_urls = platforms = any version = 2.2.0 +classifiers = + Development Status :: 5 - Production/Stable + License :: OSI Approved :: BSD License + Intended Audience :: Science/Research + Operating System :: OS Independent + Programming Language :: Python :: 3 :: Only [options] packages = find_namespace: package_dir = - = py_src -python_requires = >=3.4 + = src +python_requires = >=3.8 install_requires = cmake>=3.18.1 @@ -26,7 +31,7 @@ install_requires = *.cmake [options.packages.find] -where = py_src +where = src exclude = tests [tools:isort] diff --git a/.python_package/py_src/gridtools/__init__.py b/.python_package/src/gridtools/__init__.py similarity index 100% rename from .python_package/py_src/gridtools/__init__.py rename to .python_package/src/gridtools/__init__.py From 01eab369ae989a64a92e5bccea94749a63342bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 11:03:50 +0100 Subject: [PATCH 36/44] do not rely on external `make` being present --- .python_package/noxfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index 226948f74..bdbb4612a 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -28,9 +28,10 @@ def prepare(session: nox.Session): "-DBUILD_TESTING=OFF", "-DGT_INSTALL_EXAMPLES:BOOL=OFF", f"-DCMAKE_INSTALL_PREFIX={install_path}", + "-GNinja", str(source_path), ) - session.run("make", "install") + session.run("cmake", "--install", ".") session.log("installed gridttols sources") version_path = source_path / "version.txt" setup_path = pathlib.Path(".") / "setup.cfg" From 2a96235d81e10ded2624ed5bc53bd58cbf3901c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 11:15:32 +0100 Subject: [PATCH 37/44] add description to metadata --- .python_package/setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index 72d872fdd..a4251970c 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -3,6 +3,8 @@ name = gridtools-cpp author = ETH Zurich author_email = gridtools@cscs.ch license_files = LICENSE +long_description = file: README.rst +long_description_content_type = text/x-rst; charset=UTF-8 url = https://gridtools.github.io project_urls = Source Code = https://github.com/GridTools/gridtools From be0095f41bbcd1be5000a867d193566a69d111d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 11:35:39 +0100 Subject: [PATCH 38/44] fix description metadata --- .python_package/setup.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg index a4251970c..32fdb6cb0 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg @@ -3,13 +3,13 @@ name = gridtools-cpp author = ETH Zurich author_email = gridtools@cscs.ch license_files = LICENSE -long_description = file: README.rst -long_description_content_type = text/x-rst; charset=UTF-8 +long_description = file: README.md +long_description_content_type = text/markdown; charset=UTF-8 url = https://gridtools.github.io project_urls = Source Code = https://github.com/GridTools/gridtools platforms = any -version = 2.2.0 +version = 2.2.1a2 classifiers = Development Status :: 5 - Production/Stable From 5ac7494d1504fe2365d414dc6944f956d8ee10a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 14:25:11 +0100 Subject: [PATCH 39/44] add README, pkg name -> gridtools_cpp, setup.cfg -> setup.cfg.in --- .python_package/README.md | 73 +++++++++++++++++++ .python_package/noxfile.py | 10 +-- .python_package/{setup.cfg => setup.cfg.in} | 10 ++- .../{gridtools => gridtools_cpp}/__init__.py | 0 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 .python_package/README.md rename .python_package/{setup.cfg => setup.cfg.in} (74%) rename .python_package/src/{gridtools => gridtools_cpp}/__init__.py (100%) diff --git a/.python_package/README.md b/.python_package/README.md new file mode 100644 index 000000000..ef978f69b --- /dev/null +++ b/.python_package/README.md @@ -0,0 +1,73 @@ +# Python package for GridTools headers and CMake files + +## Usage + +Use the following when compiling C++ code agains GridTools programatically from Python. +Either by calling a compiler directly or by generating a CMake project and calling CMake on it. + +```python +import gridtools_cpp +include_dir = gridtools.get_include_dir() # header files can be found here +cmake_dir = gridtools.get_cmake_dir() # cmake files can be found here +``` + +## 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. + +All of this requires `nox`, the preparation step runs in an isolated environment and installs additional requirements `cmake` and `ninja` at runtime. + +```bash +# pip install nox +# nox -s prepare +``` + +To delete all generated files run + +```bash +# nox -s clean clean_cache +``` + +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: + +```bash +# nox -s build -- --wheel . +# pip install dist/gridtools_cpp-2.2.0-py3-none-any.whl +``` + +### Testing + +Using nox, the tests will be carried out in isolated python environments for you: + +```bash +# nox -s test_src +``` + +To 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. + +```bash +# nox +``` + +### Building for distribution + +Uses (`build`)[https://pypa-build.readthedocs.io/en/latest/], follow the link for available options. + +```bash +# nox -s build -- +``` diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index bdbb4612a..657df9b7e 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -15,8 +15,9 @@ nox.options.sessions = ["test_src", "test_wheel"] +@nox.session def prepare(session: nox.Session): - session.install("cmake>=2.18.1") + session.install("cmake>=3.18.1") session.install("ninja") build_path = session.cache_dir.joinpath("build").absolute() build_path.mkdir(exist_ok=True) @@ -34,11 +35,10 @@ def prepare(session: nox.Session): session.run("cmake", "--install", ".") session.log("installed gridttols sources") version_path = source_path / "version.txt" - setup_path = pathlib.Path(".") / "setup.cfg" config = configparser.ConfigParser() - config.read(str(setup_path)) - config["metadata"]["version"] = version_path.read_text() - with setup_path.open("w") as setup_fp: + 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", ".") diff --git a/.python_package/setup.cfg b/.python_package/setup.cfg.in similarity index 74% rename from .python_package/setup.cfg rename to .python_package/setup.cfg.in index 32fdb6cb0..ee0f98688 100644 --- a/.python_package/setup.cfg +++ b/.python_package/setup.cfg.in @@ -2,21 +2,23 @@ name = gridtools-cpp author = ETH Zurich author_email = gridtools@cscs.ch -license_files = LICENSE +license_files = LICENSE # this file is automatically copied from the top level long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8 url = https://gridtools.github.io project_urls = Source Code = https://github.com/GridTools/gridtools platforms = any -version = 2.2.1a2 - +version = # leave empty, automatically generated classifiers = Development Status :: 5 - Production/Stable - License :: OSI Approved :: BSD License Intended Audience :: Science/Research + License :: OSI Approved :: BSD License Operating System :: OS Independent Programming Language :: Python :: 3 :: Only + Topic :: Scientific/Engineering :: Atmospheric Science + Topic :: Scientific/Engineering :: Mathematics + Topic :: Scientific/Engineering :: Physics [options] packages = find_namespace: diff --git a/.python_package/src/gridtools/__init__.py b/.python_package/src/gridtools_cpp/__init__.py similarity index 100% rename from .python_package/src/gridtools/__init__.py rename to .python_package/src/gridtools_cpp/__init__.py From 72c54b7b6020ff9f5075472b80fa6544ec46ef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 14:31:31 +0100 Subject: [PATCH 40/44] remove cmake install requirement --- .python_package/setup.cfg.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/.python_package/setup.cfg.in b/.python_package/setup.cfg.in index ee0f98688..a0934e2ad 100644 --- a/.python_package/setup.cfg.in +++ b/.python_package/setup.cfg.in @@ -25,8 +25,6 @@ packages = find_namespace: package_dir = = src python_requires = >=3.8 -install_requires = - cmake>=3.18.1 [options.package_data] * = From 863c647a3cf769683df55b3b41d4620908f476cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 14:36:50 +0100 Subject: [PATCH 41/44] update usage section in README --- .python_package/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.python_package/README.md b/.python_package/README.md index ef978f69b..cba5b15a4 100644 --- a/.python_package/README.md +++ b/.python_package/README.md @@ -7,8 +7,8 @@ Either by calling a compiler directly or by generating a CMake project and calli ```python import gridtools_cpp -include_dir = gridtools.get_include_dir() # header files can be found here -cmake_dir = gridtools.get_cmake_dir() # cmake files can be found here +include_dir = gridtools_cpp.get_include_dir() # header files can be found here +cmake_dir = gridtools_cpp.get_cmake_dir() # cmake files can be found here ``` ## Development From eb9f344a07d668499edffadd971a51de9a135af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 14:37:32 +0100 Subject: [PATCH 42/44] update tests with new package name --- .python_package/tests/test_dirs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.python_package/tests/test_dirs.py b/.python_package/tests/test_dirs.py index 185ac9fac..1bb254b4e 100644 --- a/.python_package/tests/test_dirs.py +++ b/.python_package/tests/test_dirs.py @@ -6,16 +6,16 @@ # Please, refer to the LICENSE file in the root directory. # SPDX-License-Identifier: BSD-3-Clause -import gridtools +import gridtools_cpp def test_cmake_dir_contains_gridtools_cmake(): - main_config_file = gridtools.get_cmake_dir() / "GridToolsConfig.cmake" + main_config_file = gridtools_cpp.get_cmake_dir() / "GridToolsConfig.cmake" assert main_config_file.exists() assert main_config_file.read_text() def test_include_dir_contains_headers(): - include_path = gridtools.get_include_dir() + include_path = gridtools_cpp.get_include_dir() assert include_path.exists() assert len(list(include_path.rglob("*.hpp"))) > 0 From 353dc1dd51000f51977e66b113d6788eb7b2cfa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Fri, 25 Nov 2022 14:44:45 +0100 Subject: [PATCH 43/44] update package name in preparation step --- .python_package/noxfile.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.python_package/noxfile.py b/.python_package/noxfile.py index 657df9b7e..6cc2f52a9 100644 --- a/.python_package/noxfile.py +++ b/.python_package/noxfile.py @@ -12,6 +12,10 @@ import nox + +_RELATIVE_DATA_DIR = pathlib.Path("src/gridtools_cpp/data") + + nox.options.sessions = ["test_src", "test_wheel"] @@ -21,7 +25,7 @@ def prepare(session: nox.Session): session.install("ninja") build_path = session.cache_dir.joinpath("build").absolute() build_path.mkdir(exist_ok=True) - install_path = pathlib.Path(".").absolute() / "src" / "gridtools" / "data" + install_path = pathlib.Path(".").absolute() / _RELATIVE_DATA_DIR source_path = pathlib.Path("..").absolute() with session.chdir(build_path): session.run( @@ -53,7 +57,7 @@ def get_wheel(session: nox.Session) -> pathlib.Path: def build_wheel(session: nox.Session): prepare(session) dist_path = session.cache_dir.joinpath("dist").absolute() - workdir = pathlib.Path(".").absolute() + nox_workdir = pathlib.Path(".").absolute() session.install("build[virtualenv]") with session.chdir(session.cache_dir): session.run( @@ -64,7 +68,7 @@ def build_wheel(session: nox.Session): "--wheel", "-o", str(dist_path), - str(workdir), + str(nox_workdir), ) session.log(f"built wheel in {dist_path}") session.log("\n".join(str(path) for path in dist_path.iterdir())) @@ -110,14 +114,13 @@ def build(session: nox.Session): @nox.session def clean(session: nox.Session): - top_dir = pathlib.Path(".") - data_dir = top_dir / "src" / "gridtools" / "data" + 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 top_dir.joinpath("src").glob("*.egg-info"): + for egg_tree in pathlib.Path("src").glob("*.egg-info"): shutil.rmtree(egg_tree, True) session.log("rm -r dist") - shutil.rmtree(top_dir / "dist", True) + shutil.rmtree("dist", True) session.log("rm -r build") - shutil.rmtree(top_dir / "build", True) + shutil.rmtree("build", True) From 38b1596cafee034025c439ddc62023da6953759a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20H=C3=A4uselmann?= Date: Thu, 1 Dec 2022 16:39:50 +0100 Subject: [PATCH 44/44] change README.md --- .python_package/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.python_package/README.md b/.python_package/README.md index cba5b15a4..7f7716d60 100644 --- a/.python_package/README.md +++ b/.python_package/README.md @@ -2,7 +2,7 @@ ## Usage -Use the following when compiling C++ code agains GridTools programatically from Python. +Use the following when compiling C++ code with GridTools programmatically from Python. Either by calling a compiler directly or by generating a CMake project and calling CMake on it. ```python @@ -20,14 +20,14 @@ It will read the version number from the top-level `version.txt` and copy the `L All of this requires `nox`, the preparation step runs in an isolated environment and installs additional requirements `cmake` and `ninja` at runtime. ```bash -# pip install nox -# nox -s prepare +pip install nox +nox -s prepare ``` To delete all generated files run ```bash -# nox -s clean clean_cache +nox -s clean clean_cache ``` 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/`. @@ -38,8 +38,8 @@ where `clean_cache` deletes chached files from Nox sessions like CMake builds an As always it is recommended to carry out the following steps in a virtual environment: ```bash -# nox -s build -- --wheel . -# pip install dist/gridtools_cpp-2.2.0-py3-none-any.whl +nox -s build -- --wheel . +pip install dist/gridtools_cpp-2.2.0-py3-none-any.whl ``` ### Testing @@ -47,13 +47,13 @@ As always it is recommended to carry out the following steps in a virtual enviro Using nox, the tests will be carried out in isolated python environments for you: ```bash -# nox -s test_src +nox -s test_src ``` To 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 +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) @@ -61,7 +61,7 @@ To test the wheel distribution specifically: The following requires you to have Python interpreters for Python 3.8, 3.9, 3.10 and 3.11 in your system path. ```bash -# nox +nox ``` ### Building for distribution @@ -69,5 +69,5 @@ The following requires you to have Python interpreters for Python 3.8, 3.9, 3.10 Uses (`build`)[https://pypa-build.readthedocs.io/en/latest/], follow the link for available options. ```bash -# nox -s build -- +nox -s build -- ```