From dcd6e199cbf27e0e2a006582d78545fc4423778c Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 09:41:19 +0200 Subject: [PATCH 01/33] remove setuptools Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- MANIFEST.in | 11 --- pyproject.toml | 20 +---- setup.py | 239 ------------------------------------------------- 3 files changed, 3 insertions(+), 267 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index b03f524719..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: Contributors to the Power Grid Model project -# -# SPDX-License-Identifier: MPL-2.0 - -include PYPI_VERSION -include VERSION -recursive-include power_grid_model_c * - -# the following is needed for running tests in conda recipe -recursive-include tests/unit * -recursive-include tests/data * diff --git a/pyproject.toml b/pyproject.toml index 0dc74d61d1..cdfb967b61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,14 +4,10 @@ [build-system] requires = [ - "setuptools", - "wheel", - "pybuild-header-dependency", - "msgpack-cxx", - "nlohmann-json", - "libboost-headers" + "scikit-build-core", + "pgm-build-dependencies@git+https://github.com/PowerGridModel/pgm-build-dependencies.git" ] -build-backend = "setuptools.build_meta" +build-backend = "scikit_build_core.build" [project] name = "power-grid-model" @@ -61,16 +57,6 @@ Documentation = "https://power-grid-model.readthedocs.io/en/stable/" Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" Discussion = "https://github.com/orgs/PowerGridModel/discussions" -[tool.setuptools.packages.find] -where = ["src"] -namespaces = false - -[tool.setuptools.dynamic] -version = { file = "PYPI_VERSION" } - -[tool.setuptools.package-data] -"power_grid_model" = ["py.typed"] - [tool.pytest.ini_options] testpaths = ["tests/unit"] addopts = [ diff --git a/setup.py b/setup.py deleted file mode 100644 index aa2f894425..0000000000 --- a/setup.py +++ /dev/null @@ -1,239 +0,0 @@ -# SPDX-FileCopyrightText: Contributors to the Power Grid Model project -# -# SPDX-License-Identifier: MPL-2.0 - -import os -import platform -import shutil -from itertools import chain -from pathlib import Path - -# noinspection PyPackageRequirements -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext -from wheel.bdist_wheel import bdist_wheel - -# determine platform, only windows or linux -if platform.system() == "Windows": - if_win = True -elif platform.system() in ["Linux", "Darwin"]: - if_win = False - if platform.system() == "Darwin": - os.environ["MACOSX_DEPLOYMENT_TARGET"] = "13.4" -else: - raise SystemError("Only Windows, Linux, or MacOS is supported!") - - -def get_required_dependency_include() -> list[str]: - """ - Get build requirements includes. - - Returns: - either empty list or a list of header path - """ - try: - import libboost_headers - import msgpack_cxx - import nlohmann_json - - return [str(msgpack_cxx.get_include()), str(nlohmann_json.get_include()), str(libboost_headers.get_include())] - except ImportError: - return [] - - -def get_pre_installed_header_include() -> list[str]: - """ - Get header files from pybuild_header_dependency, if it is installed - - Returns: - either empty list or a list of header path - """ - try: - from pybuild_header_dependency import HeaderResolver - - resolver = HeaderResolver({"eigen": None}) - return [str(resolver.get_include())] - except ImportError: - return [] - - -# custom class for ctypes -class CTypesExtension(Extension): - pass - - -class bdist_wheel_abi_none(bdist_wheel): - def finalize_options(self): - bdist_wheel.finalize_options(self) - self.root_is_pure = False - - def get_tag(self): - python, abi, plat = bdist_wheel.get_tag(self) - return "py3", "none", plat - - -# custom compiler for linux -class MyBuildExt(build_ext): - def build_extensions(self): - if not if_win: - if "CXX" in os.environ: - cxx = os.environ["CXX"] - else: - cxx = self.compiler.compiler_cxx[0] - # check setuptools has an update change in the version 72.2 about cxx compiler options - # to be compatible with both version, we check if compiler_so_cxx exists - if not hasattr(self.compiler, "compiler_so_cxx"): - compiler_so_cxx = self.compiler.compiler_so - linker_so_cxx = self.compiler.linker_so - else: - compiler_so_cxx = self.compiler.compiler_so_cxx - linker_so_cxx = self.compiler.linker_so_cxx - # customize compiler and linker options - compiler_so_cxx[0] = cxx - linker_so_cxx[0] = cxx - self.compiler.compiler_cxx = [cxx] - # add link time optimization - if "clang" in cxx: - lto_flag = "-flto=thin" - else: - lto_flag = "-flto" - compiler_so_cxx += [lto_flag] - linker_so_cxx += [lto_flag] - # remove debug and optimization flags - for x in compiler_so_cxx.copy(): - if x in ["-g", "-O2"]: - compiler_so_cxx.remove(x) - for x in linker_so_cxx.copy(): - if x in ["-g", "-O2", "-Wl,-O1"]: - linker_so_cxx.remove(x) - - print("-------compiler arguments----------") - print(compiler_so_cxx) - print("-------linker arguments----------") - print(linker_so_cxx) - return super().build_extensions() - - def get_export_symbols(self, ext): - return ext.export_symbols - - def get_ext_filename(self, ext_name): - return os.path.join(*ext_name.split(".")) + (".dll" if if_win else ".so") - - -def generate_build_ext(pkg_dir: Path, pkg_name: str): - """ - Generate extension dict for setup.py - the return value ext_dict, can be called in setup(**ext_dict) - Args: - pkg_dir: - pkg_name: - Returns: - - """ - pkg_bin_dir = pkg_dir / "src" / pkg_name - # remove old extension build - build_dir = pkg_dir / "build" - if build_dir.exists(): - shutil.rmtree(build_dir) - # remove binary - bin_files = list(chain(pkg_bin_dir.rglob("*.so"), pkg_bin_dir.rglob("*.dll"), pkg_bin_dir.rglob("*.dylib"))) - for bin_file in bin_files: - print(f"Remove binary file: {bin_file}") - bin_file.unlink() - - # By setting POWER_GRID_MODEL_NO_BINARY_BUILD we do not build the extension. - # This is usually set in conda-build recipe, so conda build process only wraps the pure Python package. - # As a user or developer, DO NOT set this environment variable unless you really know what you are doing. - if "POWER_GRID_MODEL_NO_BINARY_BUILD" in os.environ: - return {} - - # fetch dependent headers - pgm = Path("power_grid_model") - pgm_c = Path("power_grid_model_c") - - # include-folders - include_dirs = [ - str(pkg_dir / pgm_c / pgm / "include"), # The include-folder of the library - str(pkg_dir / pgm_c / pgm_c / "include"), # The include-folder of the C API self - ] - include_dirs += get_required_dependency_include() - include_dirs += get_pre_installed_header_include() - # compiler and link flag - cflags: list[str] = [] - lflags: list[str] = [] - library_dirs: list[str] = [] - libraries: list[str] = [] - sources = [ - str(pgm_c / pgm_c / "src" / "handle.cpp"), - str(pgm_c / pgm_c / "src" / "meta_data.cpp"), - str(pgm_c / pgm_c / "src" / "model.cpp"), - str(pgm_c / pgm_c / "src" / "options.cpp"), - str(pgm_c / pgm_c / "src" / "dataset.cpp"), - str(pgm_c / pgm_c / "src" / "serialization.cpp"), - str(pgm_c / pgm_c / "src" / "math_solver.cpp"), - ] - # macro - define_macros = [ - ("EIGEN_MPL2_ONLY", "1"), # only MPL-2 part of eigen3 - ] - - # build steps for Windows and Linux - # different treat for windows and linux - # determine platform specific options - if if_win: - # flag for C++20 - cflags += ["/std:c++20"] - else: - # flags for Linux and Mac - cflags += ["-std=c++20", "-O3", "-fvisibility=hidden"] - lflags += ["-lpthread", "-O3"] - - # list of extensions - exts = [ - CTypesExtension( - name="power_grid_model._core._power_grid_core", - sources=sources, - include_dirs=include_dirs, - library_dirs=library_dirs, - libraries=libraries, - extra_compile_args=cflags, - extra_link_args=lflags, - define_macros=define_macros, - language="c++", - ) - ] - - # return dict of exts - return dict(ext_modules=exts, cmdclass={"build_ext": MyBuildExt, "bdist_wheel": bdist_wheel_abi_none}) - - -def set_version(pkg_dir: Path): - # if PYPI_VERSION does not exist, copy from VERSION - pypi_file = pkg_dir / "PYPI_VERSION" - if not pypi_file.exists(): - with open(pkg_dir / "VERSION") as f: - version = f.read().strip().strip("\n") - with open(pypi_file, "w") as f: - f.write(version) - - -def prepare_pkg(setup_file: Path) -> dict: - """ - - Args: - setup_file: - Returns: - - """ - print(f"Build wheel from {setup_file}") - pkg_dir = setup_file.parent - # package description - pkg_pip_name = "power-grid-model" - pkg_name = pkg_pip_name.replace("-", "_") - set_version(pkg_dir) - return generate_build_ext(pkg_dir=pkg_dir, pkg_name=pkg_name) - - -setup( - **prepare_pkg(setup_file=Path(__file__).resolve()), -) From 1d374988ee5cee0569b9df8dadb596a21603fc3b Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 10:03:32 +0200 Subject: [PATCH 02/33] try first build Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 26 +++++++++++++++++++ .../power_grid_model_c/__init__.py | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 src/power_grid_model/power_grid_model_c/__init__.py diff --git a/pyproject.toml b/pyproject.toml index cdfb967b61..0834509002 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,32 @@ Documentation = "https://power-grid-model.readthedocs.io/en/stable/" Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" Discussion = "https://github.com/orgs/PowerGridModel/discussions" +[tool.scikit-build] +build.verbose = true +logging.level = "INFO" + +cmake.version = ">=3.23" +cmake.build-type = "Release" +cmake.args = ["-GNinja"] +build.tool-args = ["-j1"] + +search.site-packages = false + +ninja.version = ">=1.10" +ninja.make-fallback = false + +sdist.include = ["CMakeLists.txt", "power_grid_model_c/", "cmake/", "VERSION"] + +wheel.install-dir = "power_grid_model/power_grid_model_c" +wheel.py-api = "py3" + +[tool.scikit-build.metadata.version] +provider = "scikit_build_core.metadata.regex" +input = "VERSION" +regex = "^\\s*(?P[^\\s]+)\\s*$" +result = "{version}" + + [tool.pytest.ini_options] testpaths = ["tests/unit"] addopts = [ diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py new file mode 100644 index 0000000000..1296dc4dcb --- /dev/null +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: Contributors to the Power Grid Model project +# +# SPDX-License-Identifier: MPL-2.0 From 1a9454c793aea58fefb4f285587529e00a881975 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 10:07:39 +0200 Subject: [PATCH 03/33] don't know if header works Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0834509002..b29da2afab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,6 @@ Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" Discussion = "https://github.com/orgs/PowerGridModel/discussions" [tool.scikit-build] -build.verbose = true logging.level = "INFO" cmake.version = ">=3.23" From 95988d5d914ee894db66037bce72ddf3fc662d55 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 10:51:02 +0200 Subject: [PATCH 04/33] export cmake Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b29da2afab..83861f9b13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,9 @@ Documentation = "https://power-grid-model.readthedocs.io/en/stable/" Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" Discussion = "https://github.com/orgs/PowerGridModel/discussions" +[project.entry-points."cmake.root"] +power_grid_model = "power_grid_model.power_grid_model_c" + [tool.scikit-build] logging.level = "INFO" From e41af08dc4b381bfdce41b3ace6356de0081aafc Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:02:57 +0200 Subject: [PATCH 05/33] try python Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- src/power_grid_model/_core/power_grid_core.py | 24 ++----------- .../power_grid_model_c/__init__.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/power_grid_model/_core/power_grid_core.py b/src/power_grid_model/_core/power_grid_core.py index c6e29ef3ab..01f5ff9aad 100644 --- a/src/power_grid_model/_core/power_grid_core.py +++ b/src/power_grid_model/_core/power_grid_core.py @@ -6,15 +6,13 @@ Loader for the dynamic library """ -import os -import platform from ctypes import CDLL, POINTER, c_char, c_char_p, c_double, c_size_t, c_void_p from inspect import signature from itertools import chain -from pathlib import Path from typing import Callable from power_grid_model._core.index_integer import IdC, IdxC +from power_grid_model.power_grid_model_c import get_pgm_dll_path # integer index IdxPtr = POINTER(IdxC) @@ -125,25 +123,7 @@ def _load_core() -> CDLL: Returns: DLL/SO object """ - # first try to find the DLL local - if platform.system() == "Windows": - dll_file = "_power_grid_core.dll" - else: - dll_file = "_power_grid_core.so" - dll_path = Path(__file__).parent / dll_file - - # if local DLL is not found, try to find the DLL from conda environment - if (not dll_path.exists()) and ("CONDA_PREFIX" in os.environ): - if platform.system() == "Windows": - dll_file = "power_grid_model_c.dll" - elif platform.system() == "Darwin": - dll_file = "libpower_grid_model_c.dylib" - elif platform.system() == "Linux": - dll_file = "libpower_grid_model_c.so" - else: - raise NotImplementedError(f"Unsupported platform: {platform.system()}") - # the dll will be found through conda environment - dll_path = Path(dll_file) + dll_path = get_pgm_dll_path() cdll = CDLL(str(dll_path)) # assign return types diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index 1296dc4dcb..3264a43269 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -1,3 +1,37 @@ # SPDX-FileCopyrightText: Contributors to the Power Grid Model project # # SPDX-License-Identifier: MPL-2.0 + +import platform +from importlib.resources import files +from pathlib import Path + + +def get_pgm_dll_path() -> Path: + """ + Returns the path to PGM dynamic library. + """ + package_dir = files(__package__) + if platform.system() == "Windows": + lib_dir = package_dir / "bin" + else: + lib_dir = package_dir / "lib" + # determine DLL file name + if platform.system() == "Windows": + dll_file = Path("power_grid_model_c.dll") + elif platform.system() == "Darwin": + dll_file = Path("libpower_grid_model_c.dylib") + elif platform.system() == "Linux": + dll_file = Path("libpower_grid_model_c.so") + else: + raise NotImplementedError(f"Unsupported platform: {platform.system()}") + lib_dll_path = lib_dir / dll_file + + # first try to load from lib_dll_path + # then just load dll_file, the system tries to find it in the PATH + if lib_dll_path.exists(): + final_dll_path = lib_dll_path + else: + final_dll_path = dll_file + + return final_dll_path From 4d382d10e72f6e1469c6c667e80a82abe1bd8798 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:54:28 +0200 Subject: [PATCH 06/33] seperate build dir Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 83861f9b13..6973ca17e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,6 +66,8 @@ logging.level = "INFO" cmake.version = ">=3.23" cmake.build-type = "Release" cmake.args = ["-GNinja"] + +build-dir = "build" build.tool-args = ["-j1"] search.site-packages = false From 817d10558c0c47c7d70ac4906c847fcfa304f5fd Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:56:31 +0200 Subject: [PATCH 07/33] try editable Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- src/power_grid_model/power_grid_model_c/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index 3264a43269..bc56ebe0c3 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -16,6 +16,7 @@ def get_pgm_dll_path() -> Path: lib_dir = package_dir / "bin" else: lib_dir = package_dir / "lib" + # determine DLL file name if platform.system() == "Windows": dll_file = Path("power_grid_model_c.dll") @@ -27,11 +28,20 @@ def get_pgm_dll_path() -> Path: raise NotImplementedError(f"Unsupported platform: {platform.system()}") lib_dll_path = lib_dir / dll_file + # determine editable path to the DLL + # __file__ -> power_grid_model_c -> power_grid_model -> src -> repo_root -> build -> bin + editable_dir = Path(__file__).resolve().parent.parent.parent.parent / "build" / "bin" + editable_dll_path = editable_dir / dll_file + # first try to load from lib_dll_path + # then editable_dll_path # then just load dll_file, the system tries to find it in the PATH if lib_dll_path.exists(): final_dll_path = lib_dll_path + elif editable_dll_path.exists(): + final_dll_path = editable_dll_path else: final_dll_path = dll_file + return final_dll_path From 5487ab95c646512351e6d00c5e48cb3c3b0a2e49 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 12:00:41 +0200 Subject: [PATCH 08/33] editable works Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- src/power_grid_model/power_grid_model_c/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index bc56ebe0c3..8c705118e3 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -29,7 +29,13 @@ def get_pgm_dll_path() -> Path: lib_dll_path = lib_dir / dll_file # determine editable path to the DLL - # __file__ -> power_grid_model_c -> power_grid_model -> src -> repo_root -> build -> bin + # __file__ + # -> power_grid_model_c (..) + # -> power_grid_model (..) + # -> src (..) + # -> repo_root (..) + # -> build + # -> bin editable_dir = Path(__file__).resolve().parent.parent.parent.parent / "build" / "bin" editable_dll_path = editable_dir / dll_file @@ -43,5 +49,4 @@ def get_pgm_dll_path() -> Path: else: final_dll_path = dll_file - return final_dll_path From 120b8f3de4e5e2340d25522b25f1f44423694b37 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 12:06:27 +0200 Subject: [PATCH 09/33] add conda Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/conda_pgm_env.yml | 3 +-- .github/workflows/build-test-release.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/conda_pgm_env.yml b/.github/conda_pgm_env.yml index 00e1b24ce7..1845c03ec8 100644 --- a/.github/conda_pgm_env.yml +++ b/.github/conda_pgm_env.yml @@ -7,8 +7,7 @@ dependencies: # build env - python=3.12 - pip - - wheel - - setuptools + - scikit-build-core # build deps - libboost-headers - eigen diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 1fe2eaa73c..717cdc8d96 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -275,7 +275,7 @@ jobs: cmake --install build/ - name: Build python - run: python -m pip install . -vv --no-build-isolation --no-deps + run: python -m pip install . --no-build-isolation --no-deps -C wheel.cmake=false - name: Test run: pytest From b0238092fab5c24261e4240922ecb89b14cf8b76 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 20:24:41 +0200 Subject: [PATCH 10/33] change PYPI version Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/workflows/build-test-release.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 717cdc8d96..68fe7ff6f5 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -44,7 +44,8 @@ jobs: - name: Build SDist run: | - cat PYPI_VERSION + cp PYPI_VERSION VERSION + cat VERSION pip install build python -m build --sdist --outdir wheelhouse . @@ -52,7 +53,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: version - path: PYPI_VERSION + path: VERSION - name: Keep SDist uses: actions/upload-artifact@v4 @@ -319,7 +320,7 @@ jobs: - name: Get tag id: tag - run: echo "tag=v$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT + run: echo "tag=v$(cat VERSION)" >> $GITHUB_OUTPUT - name: Display tag run: echo "${{ steps.tag.outputs.tag }}" From 3bec816f4bc329f7c6c59359ab26ca4e975c2fff Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 20:40:03 +0200 Subject: [PATCH 11/33] start msvc Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/enable-msvc.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/actions/enable-msvc.yml diff --git a/.github/actions/enable-msvc.yml b/.github/actions/enable-msvc.yml new file mode 100644 index 0000000000..ea585359c8 --- /dev/null +++ b/.github/actions/enable-msvc.yml @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: Contributors to the Power Grid Model project +# +# SPDX-License-Identifier: MPL-2.0 + +name: 'Enable MSVC' +description: 'Sets up Microsoft Visual C++ Build Tools on the runner' + +runs: + using: "composite" + if: runner.os == 'windows' + shell: pwsh + steps: + - name: Setup MSVC Build Tools + run: | + $vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath + Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll') + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' + + Add-Content $env:GITHUB_ENV "VCINSTALLDIR=$env:VCINSTALLDIR" + Add-Content $env:GITHUB_ENV "PATH=$env:PATH" + Add-Content $env:GITHUB_ENV "INCLUDE=$env:INCLUDE" + Add-Content $env:GITHUB_ENV "LIB=$env:LIB" + Add-Content $env:GITHUB_ENV "LIBPATH=$env:LIBPATH" From b81346f758b8ce7d3ce211f79fc9d34a792106de Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 20:53:23 +0200 Subject: [PATCH 12/33] modify ci Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/enable-msvc.yml | 3 ++- .github/workflows/build-test-release.yml | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/actions/enable-msvc.yml b/.github/actions/enable-msvc.yml index ea585359c8..0c24b17657 100644 --- a/.github/actions/enable-msvc.yml +++ b/.github/actions/enable-msvc.yml @@ -7,7 +7,7 @@ description: 'Sets up Microsoft Visual C++ Build Tools on the runner' runs: using: "composite" - if: runner.os == 'windows' + if: runner.os == 'Windows' shell: pwsh steps: - name: Setup MSVC Build Tools @@ -21,3 +21,4 @@ runs: Add-Content $env:GITHUB_ENV "INCLUDE=$env:INCLUDE" Add-Content $env:GITHUB_ENV "LIB=$env:LIB" Add-Content $env:GITHUB_ENV "LIBPATH=$env:LIBPATH" + \ No newline at end of file diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 68fe7ff6f5..52f06ace65 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -123,13 +123,11 @@ jobs: - name: Install conda environment run: | conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest - + + - uses: ./.github/actions/enable-msvc.yml + - name: Build and test run: | - $vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath - Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll') - Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' - # Resolve dirty PATH environment # TODO(mgovers): Remove after https://github.com/actions/runner-images/issues/10001 is resolved $env:PATH = ($env:PATH -split ';' | Where-Object { $_ -ne 'C:\Program Files\LLVM\bin' }) -join ';' @@ -151,7 +149,7 @@ jobs: install\${{ env.PRESET }}\bin\power_grid_model_package_test; if(!$?) { Exit $LASTEXITCODE } build-cpp-test-macos: - runs-on: macos-14 + runs-on: macos-15 strategy: matrix: build-option: [ debug, release ] @@ -203,6 +201,8 @@ jobs: name: version path: . + - uses: ./.github/actions/enable-msvc.yml + - name: Set up XCode if: matrix.os == 'macos-15' uses: maxim-lobanov/setup-xcode@v1 @@ -258,12 +258,11 @@ jobs: conda info conda list + - uses: ./.github/actions/enable-msvc.yml + - name: Build and install cmake target for Windows if: matrix.os == 'windows' run: | - $vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath - Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll') - Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' cmake -GNinja -DCMAKE_BUILD_TYPE=Release -B build/ -S . cmake --build build/ --verbose -j1 cmake --install build/ --prefix ${env:CONDA_PREFIX}/Library From 86cb044cd64efb12ce0c99756cb3466cd87328df Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:00:36 +0200 Subject: [PATCH 13/33] action.yml Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/{enable-msvc.yml => enable-msvc/action.yml} | 0 .github/workflows/build-test-release.yml | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/actions/{enable-msvc.yml => enable-msvc/action.yml} (100%) diff --git a/.github/actions/enable-msvc.yml b/.github/actions/enable-msvc/action.yml similarity index 100% rename from .github/actions/enable-msvc.yml rename to .github/actions/enable-msvc/action.yml diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 52f06ace65..a6707dced6 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -124,7 +124,7 @@ jobs: run: | conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest - - uses: ./.github/actions/enable-msvc.yml + - uses: ./.github/actions/enable-msvc - name: Build and test run: | @@ -201,7 +201,7 @@ jobs: name: version path: . - - uses: ./.github/actions/enable-msvc.yml + - uses: ./.github/actions/enable-msvc - name: Set up XCode if: matrix.os == 'macos-15' @@ -258,7 +258,7 @@ jobs: conda info conda list - - uses: ./.github/actions/enable-msvc.yml + - uses: ./.github/actions/enable-msvc - name: Build and install cmake target for Windows if: matrix.os == 'windows' From be22c1394d8e6a6780eff3cd69e20f471aa5c94b Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:03:15 +0200 Subject: [PATCH 14/33] if windows Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/enable-msvc/action.yml | 1 - .github/workflows/build-test-release.yml | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/enable-msvc/action.yml b/.github/actions/enable-msvc/action.yml index 0c24b17657..9e30680501 100644 --- a/.github/actions/enable-msvc/action.yml +++ b/.github/actions/enable-msvc/action.yml @@ -7,7 +7,6 @@ description: 'Sets up Microsoft Visual C++ Build Tools on the runner' runs: using: "composite" - if: runner.os == 'Windows' shell: pwsh steps: - name: Setup MSVC Build Tools diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index a6707dced6..ca3dcefac6 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -125,6 +125,7 @@ jobs: conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest - uses: ./.github/actions/enable-msvc + if: runner.os == 'Windows' - name: Build and test run: | @@ -202,6 +203,7 @@ jobs: path: . - uses: ./.github/actions/enable-msvc + if: runner.os == 'Windows' - name: Set up XCode if: matrix.os == 'macos-15' @@ -259,6 +261,7 @@ jobs: conda list - uses: ./.github/actions/enable-msvc + if: runner.os == 'Windows' - name: Build and install cmake target for Windows if: matrix.os == 'windows' From b370f901fd71fa33a79b933ef384040887ee06b7 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:05:59 +0200 Subject: [PATCH 15/33] if windows Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/enable-msvc/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/enable-msvc/action.yml b/.github/actions/enable-msvc/action.yml index 9e30680501..2351e1ebc1 100644 --- a/.github/actions/enable-msvc/action.yml +++ b/.github/actions/enable-msvc/action.yml @@ -7,9 +7,9 @@ description: 'Sets up Microsoft Visual C++ Build Tools on the runner' runs: using: "composite" - shell: pwsh steps: - name: Setup MSVC Build Tools + shell: pwsh run: | $vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll') From e8a85762c1413a05652a2456110e70e8ec578ab8 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:14:10 +0200 Subject: [PATCH 16/33] [skip ci] version invalid for cmake Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- src/power_grid_model/power_grid_model_c/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index 8c705118e3..c3f23b59fd 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -11,7 +11,7 @@ def get_pgm_dll_path() -> Path: """ Returns the path to PGM dynamic library. """ - package_dir = files(__package__) + package_dir = Path(str(files(__package__))) if platform.system() == "Windows": lib_dir = package_dir / "bin" else: From 9d03e9f8692750e26179225899b6405d06acfc5f Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:24:33 +0200 Subject: [PATCH 17/33] strip version for cmake Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- cmake/pgm_version.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/pgm_version.cmake b/cmake/pgm_version.cmake index 0644f1193d..dc821be341 100644 --- a/cmake/pgm_version.cmake +++ b/cmake/pgm_version.cmake @@ -5,4 +5,5 @@ cmake_minimum_required (VERSION 3.23) file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" _PGM_VERSION) -string(STRIP ${_PGM_VERSION} PGM_VERSION) +string(STRIP ${_PGM_VERSION} _PGM_VERSION_STRIPPED) +string(REGEX REPLACE "^([0-9]+\\.[0-9]+(\\.[0-9]+)?).*" "\\1" PGM_VERSION "${_PGM_VERSION_STRIPPED}") From 989f10bdb47d51ac66135be49b7502865cf9f74f Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:38:55 +0200 Subject: [PATCH 18/33] add lib64 Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .../power_grid_model_c/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index c3f23b59fd..9ae21b07cc 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -13,9 +13,11 @@ def get_pgm_dll_path() -> Path: """ package_dir = Path(str(files(__package__))) if platform.system() == "Windows": - lib_dir = package_dir / "bin" + lib_dir_1 = package_dir / "bin" + lib_dir_2 = package_dir / "bin" else: - lib_dir = package_dir / "lib" + lib_dir_1 = package_dir / "lib" + lib_dir_2 = package_dir / "lib64" # determine DLL file name if platform.system() == "Windows": @@ -26,7 +28,8 @@ def get_pgm_dll_path() -> Path: dll_file = Path("libpower_grid_model_c.so") else: raise NotImplementedError(f"Unsupported platform: {platform.system()}") - lib_dll_path = lib_dir / dll_file + lib_dll_path_1 = lib_dir_1 / dll_file + lib_dll_path_2 = lib_dir_2 / dll_file # determine editable path to the DLL # __file__ @@ -42,8 +45,10 @@ def get_pgm_dll_path() -> Path: # first try to load from lib_dll_path # then editable_dll_path # then just load dll_file, the system tries to find it in the PATH - if lib_dll_path.exists(): - final_dll_path = lib_dll_path + if lib_dll_path_1.exists(): + final_dll_path = lib_dll_path_1 + elif lib_dll_path_2.exists(): + final_dll_path = lib_dll_path_2 elif editable_dll_path.exists(): final_dll_path = editable_dll_path else: From 20747f10a0d768d06d2ab31e7d3b8f0de5a019b6 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 16 Jun 2025 11:12:02 +0200 Subject: [PATCH 19/33] move get dll path Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- src/power_grid_model/_core/power_grid_core.py | 2 +- .../power_grid_model_c/__init__.py | 54 ------------------ .../power_grid_model_c/get_pgm_dll_path.py | 57 +++++++++++++++++++ 3 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py diff --git a/src/power_grid_model/_core/power_grid_core.py b/src/power_grid_model/_core/power_grid_core.py index 01f5ff9aad..53f6a0ed08 100644 --- a/src/power_grid_model/_core/power_grid_core.py +++ b/src/power_grid_model/_core/power_grid_core.py @@ -12,7 +12,7 @@ from typing import Callable from power_grid_model._core.index_integer import IdC, IdxC -from power_grid_model.power_grid_model_c import get_pgm_dll_path +from power_grid_model.power_grid_model_c.get_pgm_dll_path import get_pgm_dll_path # integer index IdxPtr = POINTER(IdxC) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/power_grid_model_c/__init__.py index 9ae21b07cc..1296dc4dcb 100644 --- a/src/power_grid_model/power_grid_model_c/__init__.py +++ b/src/power_grid_model/power_grid_model_c/__init__.py @@ -1,57 +1,3 @@ # SPDX-FileCopyrightText: Contributors to the Power Grid Model project # # SPDX-License-Identifier: MPL-2.0 - -import platform -from importlib.resources import files -from pathlib import Path - - -def get_pgm_dll_path() -> Path: - """ - Returns the path to PGM dynamic library. - """ - package_dir = Path(str(files(__package__))) - if platform.system() == "Windows": - lib_dir_1 = package_dir / "bin" - lib_dir_2 = package_dir / "bin" - else: - lib_dir_1 = package_dir / "lib" - lib_dir_2 = package_dir / "lib64" - - # determine DLL file name - if platform.system() == "Windows": - dll_file = Path("power_grid_model_c.dll") - elif platform.system() == "Darwin": - dll_file = Path("libpower_grid_model_c.dylib") - elif platform.system() == "Linux": - dll_file = Path("libpower_grid_model_c.so") - else: - raise NotImplementedError(f"Unsupported platform: {platform.system()}") - lib_dll_path_1 = lib_dir_1 / dll_file - lib_dll_path_2 = lib_dir_2 / dll_file - - # determine editable path to the DLL - # __file__ - # -> power_grid_model_c (..) - # -> power_grid_model (..) - # -> src (..) - # -> repo_root (..) - # -> build - # -> bin - editable_dir = Path(__file__).resolve().parent.parent.parent.parent / "build" / "bin" - editable_dll_path = editable_dir / dll_file - - # first try to load from lib_dll_path - # then editable_dll_path - # then just load dll_file, the system tries to find it in the PATH - if lib_dll_path_1.exists(): - final_dll_path = lib_dll_path_1 - elif lib_dll_path_2.exists(): - final_dll_path = lib_dll_path_2 - elif editable_dll_path.exists(): - final_dll_path = editable_dll_path - else: - final_dll_path = dll_file - - return final_dll_path diff --git a/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py b/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py new file mode 100644 index 0000000000..9ae21b07cc --- /dev/null +++ b/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py @@ -0,0 +1,57 @@ +# SPDX-FileCopyrightText: Contributors to the Power Grid Model project +# +# SPDX-License-Identifier: MPL-2.0 + +import platform +from importlib.resources import files +from pathlib import Path + + +def get_pgm_dll_path() -> Path: + """ + Returns the path to PGM dynamic library. + """ + package_dir = Path(str(files(__package__))) + if platform.system() == "Windows": + lib_dir_1 = package_dir / "bin" + lib_dir_2 = package_dir / "bin" + else: + lib_dir_1 = package_dir / "lib" + lib_dir_2 = package_dir / "lib64" + + # determine DLL file name + if platform.system() == "Windows": + dll_file = Path("power_grid_model_c.dll") + elif platform.system() == "Darwin": + dll_file = Path("libpower_grid_model_c.dylib") + elif platform.system() == "Linux": + dll_file = Path("libpower_grid_model_c.so") + else: + raise NotImplementedError(f"Unsupported platform: {platform.system()}") + lib_dll_path_1 = lib_dir_1 / dll_file + lib_dll_path_2 = lib_dir_2 / dll_file + + # determine editable path to the DLL + # __file__ + # -> power_grid_model_c (..) + # -> power_grid_model (..) + # -> src (..) + # -> repo_root (..) + # -> build + # -> bin + editable_dir = Path(__file__).resolve().parent.parent.parent.parent / "build" / "bin" + editable_dll_path = editable_dir / dll_file + + # first try to load from lib_dll_path + # then editable_dll_path + # then just load dll_file, the system tries to find it in the PATH + if lib_dll_path_1.exists(): + final_dll_path = lib_dll_path_1 + elif lib_dll_path_2.exists(): + final_dll_path = lib_dll_path_2 + elif editable_dll_path.exists(): + final_dll_path = editable_dll_path + else: + final_dll_path = dll_file + + return final_dll_path From 994eedfd40e53caba099ef2278047ffd8cb30fc3 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:47:37 +0200 Subject: [PATCH 20/33] [skip ci] well known labels Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6973ca17e7..429e0e84a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,11 +51,11 @@ doc = [ ] [project.urls] -Home-page = "https://lfenergy.org/projects/power-grid-model/" -GitHub = "https://github.com/PowerGridModel/power-grid-model" -Documentation = "https://power-grid-model.readthedocs.io/en/stable/" -Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" -Discussion = "https://github.com/orgs/PowerGridModel/discussions" +homepage = "https://lfenergy.org/projects/power-grid-model/" +github = "https://github.com/PowerGridModel/power-grid-model" +documentation = "https://power-grid-model.readthedocs.io/en/stable/" +mailing-list = "https://lists.lfenergy.org/g/powergridmodel" +discussion = "https://github.com/orgs/PowerGridModel/discussions" [project.entry-points."cmake.root"] power_grid_model = "power_grid_model.power_grid_model_c" From c77fd52b9f6448920947da5eec0d3bfd47bd63eb Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:58:58 +0200 Subject: [PATCH 21/33] markdown Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- docs/advanced_documentation/build-guide.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/advanced_documentation/build-guide.md b/docs/advanced_documentation/build-guide.md index 55975975e5..f0f4977b30 100644 --- a/docs/advanced_documentation/build-guide.md +++ b/docs/advanced_documentation/build-guide.md @@ -91,9 +91,8 @@ The table below shows the Python dependencies | Library name | Remark | License | | --------------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------ | -| [pybuild-header-dependency](https://github.com/TonyXiang8787/pybuild-header-dependency) | build dependency | [BSD-3](https://github.com/TonyXiang8787/pybuild-header-dependency/blob/main/LICENSE) | -| [numpy](https://numpy.org/) | build/runtime dependency | [BSD-3](https://github.com/numpy/numpy/blob/main/LICENSE.txt) | -| [wheel](https://github.com/pypa/wheel) | build dependency | [MIT](https://github.com/pypa/wheel/blob/main/LICENSE.txt) | +| [numpy](https://numpy.org/) | runtime dependency | [BSD-3](https://github.com/numpy/numpy/blob/main/LICENSE.txt) | +| [scikit-build-core](https://github.com/scikit-build/scikit-build-core) | build dependency | [Apache](https://github.com/scikit-build/scikit-build-core/blob/main/LICENSE) | | [pytest](https://github.com/pytest-dev/pytest) | Development dependency | [MIT](https://github.com/pytest-dev/pytest/blob/main/LICENSE) | | [pytest-cov](https://github.com/pytest-dev/pytest-cov) | Development dependency | [MIT](https://github.com/pytest-dev/pytest-cov/blob/master/LICENSE) | | [msgpack-python](https://github.com/msgpack/msgpack-python) | Development dependency | [Apache License, Version 2.0](https://github.com/msgpack/msgpack-python/blob/main/COPYING) | From 4e5b9651f2441caac3c38dbc1ecd0695d81266c2 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:24:33 +0200 Subject: [PATCH 22/33] default parallel, force single thread in CI Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ecc107c5ef..f4ea00af28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,6 @@ cmake.build-type = "Release" cmake.args = ["-GNinja"] build-dir = "build" -build.tool-args = ["-j1"] search.site-packages = false @@ -86,6 +85,12 @@ input = "VERSION" regex = "^\\s*(?P[^\\s]+)\\s*$" result = "{version}" +# when build in CI, force single thread to avoid out of memory errors +[[tool.scikit-build.overrides]] +if.any.env.CIBUILDWHEEL = true +if.any.env.GITHUB_ACTIONS = true +if.any.env.READTHEDOCS = true +build.tool-args = ["-j1"] [tool.pytest.ini_options] testpaths = ["tests/unit"] From cf71df3b44371184b0eb41f855b8e3a133e09f2c Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Wed, 18 Jun 2025 14:58:30 +0200 Subject: [PATCH 23/33] sdist include by default Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f4ea00af28..5b3d8a7c5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,8 +74,6 @@ search.site-packages = false ninja.version = ">=1.10" ninja.make-fallback = false -sdist.include = ["CMakeLists.txt", "power_grid_model_c/", "cmake/", "VERSION"] - wheel.install-dir = "power_grid_model/power_grid_model_c" wheel.py-api = "py3" From 0d8bd379c055e36669fd41a812428fce5636f63c Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:58:28 +0200 Subject: [PATCH 24/33] Update .github/actions/enable-msvc/action.yml Co-authored-by: Martijn Govers Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .github/actions/enable-msvc/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/enable-msvc/action.yml b/.github/actions/enable-msvc/action.yml index 2351e1ebc1..ddec9b4855 100644 --- a/.github/actions/enable-msvc/action.yml +++ b/.github/actions/enable-msvc/action.yml @@ -19,5 +19,4 @@ runs: Add-Content $env:GITHUB_ENV "PATH=$env:PATH" Add-Content $env:GITHUB_ENV "INCLUDE=$env:INCLUDE" Add-Content $env:GITHUB_ENV "LIB=$env:LIB" - Add-Content $env:GITHUB_ENV "LIBPATH=$env:LIBPATH" - \ No newline at end of file + Add-Content $env:GITHUB_ENV "LIBPATH=$env:LIBPATH" \ No newline at end of file From 92e5f2a33710de0cde55962b32d3b0a0836cbe41 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:11:07 +0200 Subject: [PATCH 25/33] check conda separately Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .../power_grid_model_c/get_pgm_dll_path.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py b/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py index 9ae21b07cc..864057fdbe 100644 --- a/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py +++ b/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MPL-2.0 +import os import platform from importlib.resources import files from pathlib import Path @@ -44,14 +45,17 @@ def get_pgm_dll_path() -> Path: # first try to load from lib_dll_path # then editable_dll_path - # then just load dll_file, the system tries to find it in the PATH + # then if it is inside conda, just load dll_file, the system tries to find it in the PATH + # then for anything else, raise an error if lib_dll_path_1.exists(): final_dll_path = lib_dll_path_1 elif lib_dll_path_2.exists(): final_dll_path = lib_dll_path_2 elif editable_dll_path.exists(): final_dll_path = editable_dll_path - else: + elif os.environ.get("CONDA_PREFIX"): final_dll_path = dll_file + else: + raise ImportError(f"Could not find shared library: {dll_file}. Your PGM installation may be broken.") return final_dll_path From c843bfec4589fe58bc33275a7a381fd79cfd2121 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:01:19 +0200 Subject: [PATCH 26/33] use wheel file Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 96867d33a8..a4a20f1286 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [build-system] requires = [ "scikit-build-core", - "pgm-build-dependencies@git+https://github.com/PowerGridModel/pgm-build-dependencies.git" + "pgm-build-dependencies@https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl" ] build-backend = "scikit_build_core.build" From 1dbf650945e910534d5644f661984a2614156bf8 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 4 Aug 2025 09:56:10 +0200 Subject: [PATCH 27/33] Update pyproject.toml Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a4a20f1286..903526deaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,11 +51,11 @@ doc = [ ] [project.urls] -homepage = "https://lfenergy.org/projects/power-grid-model/" -github = "https://github.com/PowerGridModel/power-grid-model" -documentation = "https://power-grid-model.readthedocs.io/en/stable/" -mailing-list = "https://lists.lfenergy.org/g/powergridmodel" -discussion = "https://github.com/orgs/PowerGridModel/discussions" +Home-page = "https://lfenergy.org/projects/power-grid-model/" +GitHub = "https://github.com/PowerGridModel/power-grid-model" +Documentation = "https://power-grid-model.readthedocs.io/en/stable/" +Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" +Discussion = "https://github.com/orgs/PowerGridModel/discussions" [project.entry-points."cmake.root"] power_grid_model = "power_grid_model.power_grid_model_c" From 778aa334e77a8654bc846efe9b93485fbd46758a Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 4 Aug 2025 13:21:09 +0200 Subject: [PATCH 28/33] move pgm c to private module Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 4 ++-- src/power_grid_model/_core/power_grid_core.py | 2 +- .../{ => _core}/power_grid_model_c/__init__.py | 0 .../power_grid_model_c/get_pgm_dll_path.py | 13 +++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) rename src/power_grid_model/{ => _core}/power_grid_model_c/__init__.py (100%) rename src/power_grid_model/{ => _core}/power_grid_model_c/get_pgm_dll_path.py (90%) diff --git a/pyproject.toml b/pyproject.toml index 903526deaf..0535c7374a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ Mailing-list = "https://lists.lfenergy.org/g/powergridmodel" Discussion = "https://github.com/orgs/PowerGridModel/discussions" [project.entry-points."cmake.root"] -power_grid_model = "power_grid_model.power_grid_model_c" +power_grid_model = "power_grid_model._core.power_grid_model_c" [tool.scikit-build] logging.level = "INFO" @@ -74,7 +74,7 @@ search.site-packages = false ninja.version = ">=1.10" ninja.make-fallback = false -wheel.install-dir = "power_grid_model/power_grid_model_c" +wheel.install-dir = "power_grid_model/_core/power_grid_model_c" wheel.py-api = "py3" [tool.scikit-build.metadata.version] diff --git a/src/power_grid_model/_core/power_grid_core.py b/src/power_grid_model/_core/power_grid_core.py index be63be4b68..67d265a3cd 100644 --- a/src/power_grid_model/_core/power_grid_core.py +++ b/src/power_grid_model/_core/power_grid_core.py @@ -12,7 +12,7 @@ from typing import Callable from power_grid_model._core.index_integer import IdC, IdxC -from power_grid_model.power_grid_model_c.get_pgm_dll_path import get_pgm_dll_path +from power_grid_model._core.power_grid_model_c.get_pgm_dll_path import get_pgm_dll_path # integer index IdxPtr = POINTER(IdxC) diff --git a/src/power_grid_model/power_grid_model_c/__init__.py b/src/power_grid_model/_core/power_grid_model_c/__init__.py similarity index 100% rename from src/power_grid_model/power_grid_model_c/__init__.py rename to src/power_grid_model/_core/power_grid_model_c/__init__.py diff --git a/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py similarity index 90% rename from src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py rename to src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py index 864057fdbe..be72d420ee 100644 --- a/src/power_grid_model/power_grid_model_c/get_pgm_dll_path.py +++ b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py @@ -35,12 +35,13 @@ def get_pgm_dll_path() -> Path: # determine editable path to the DLL # __file__ # -> power_grid_model_c (..) - # -> power_grid_model (..) - # -> src (..) - # -> repo_root (..) - # -> build - # -> bin - editable_dir = Path(__file__).resolve().parent.parent.parent.parent / "build" / "bin" + # -> _core (..) + # -> power_grid_model (..) + # -> src (..) + # -> repo_root (..) + # -> build + # -> bin + editable_dir = Path(__file__).resolve().parent.parent.parent.parent.parent / "build" / "bin" editable_dll_path = editable_dir / dll_file # first try to load from lib_dll_path From ab9ebbcf59a439c8a85ff77007801db836bf6d8f Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 4 Aug 2025 12:34:04 +0200 Subject: [PATCH 29/33] use sonarqube-scan-action instead of sonar-scanner Signed-off-by: Martijn Govers --- .github/workflows/sonar.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 761a69ae7c..58863c8aaf 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -46,8 +46,8 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install sonar-scanner and build-wrapper - uses: SonarSource/sonarcloud-github-c-cpp@v3 + - name: Install build-wrapper + uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5 - name: Python test and coverage run: | @@ -70,11 +70,13 @@ jobs: # remove branch hits count, since it does not make sense in heavy C++ templates sed -i -r "s/\s*branchesToCover\s*=\s*\"[0-9]+\"\s+coveredBranches\s*=\s*\"[0-9]+\"//g" cpp_coverage.xml - - name: Run sonar-scanner + - name: SonarQube Scan # only run sonar server in push event or pull request event from own repo - if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }} + if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - sonar-scanner --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" + uses: SonarSource/sonarqube-scan-action@v5 + with: + args: > + --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" From 4041938980cd35634f1297b29c1c5b449ba403d4 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 4 Aug 2025 15:17:45 +0200 Subject: [PATCH 30/33] Update src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py Co-authored-by: Martijn Govers Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .../_core/power_grid_model_c/get_pgm_dll_path.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py index be72d420ee..566cf36120 100644 --- a/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py +++ b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py @@ -13,7 +13,8 @@ def get_pgm_dll_path() -> Path: Returns the path to PGM dynamic library. """ package_dir = Path(str(files(__package__))) - if platform.system() == "Windows": + platform_name = platform.system() + if platform_name == "Windows": lib_dir_1 = package_dir / "bin" lib_dir_2 = package_dir / "bin" else: @@ -21,14 +22,14 @@ def get_pgm_dll_path() -> Path: lib_dir_2 = package_dir / "lib64" # determine DLL file name - if platform.system() == "Windows": + if platform_name == "Windows": dll_file = Path("power_grid_model_c.dll") - elif platform.system() == "Darwin": + elif platform_name == "Darwin": dll_file = Path("libpower_grid_model_c.dylib") elif platform.system() == "Linux": dll_file = Path("libpower_grid_model_c.so") else: - raise NotImplementedError(f"Unsupported platform: {platform.system()}") + raise NotImplementedError(f"Unsupported platform: {platform_name}") lib_dll_path_1 = lib_dir_1 / dll_file lib_dll_path_2 = lib_dir_2 / dll_file From 52591a55203f2ea8f761479ac3a0f553a83ac6c0 Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Mon, 4 Aug 2025 15:24:14 +0200 Subject: [PATCH 31/33] use uname Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- .../_core/power_grid_model_c/get_pgm_dll_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py index 566cf36120..9c53e5e881 100644 --- a/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py +++ b/src/power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py @@ -13,7 +13,7 @@ def get_pgm_dll_path() -> Path: Returns the path to PGM dynamic library. """ package_dir = Path(str(files(__package__))) - platform_name = platform.system() + platform_name = platform.uname().system if platform_name == "Windows": lib_dir_1 = package_dir / "bin" lib_dir_2 = package_dir / "bin" From 898070bac043a9cc224ed9647d3defaf202d3211 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Tue, 5 Aug 2025 10:01:18 +0200 Subject: [PATCH 32/33] format table Signed-off-by: Martijn Govers --- docs/advanced_documentation/build-guide.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/advanced_documentation/build-guide.md b/docs/advanced_documentation/build-guide.md index 5c5473a52a..25fb3c97d5 100644 --- a/docs/advanced_documentation/build-guide.md +++ b/docs/advanced_documentation/build-guide.md @@ -89,13 +89,13 @@ The table below shows the C++ build dependencies The table below shows the Python dependencies -| Library name | Remark | License | -| --------------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------ | -| [numpy](https://numpy.org/) | runtime dependency | [BSD-3](https://github.com/numpy/numpy/blob/main/LICENSE.txt) | -| [scikit-build-core](https://github.com/scikit-build/scikit-build-core) | build dependency | [Apache](https://github.com/scikit-build/scikit-build-core/blob/main/LICENSE) | -| [pytest](https://github.com/pytest-dev/pytest) | Development dependency | [MIT](https://github.com/pytest-dev/pytest/blob/main/LICENSE) | -| [pytest-cov](https://github.com/pytest-dev/pytest-cov) | Development dependency | [MIT](https://github.com/pytest-dev/pytest-cov/blob/master/LICENSE) | -| [msgpack-python](https://github.com/msgpack/msgpack-python) | Development dependency | [Apache License, Version 2.0](https://github.com/msgpack/msgpack-python/blob/main/COPYING) | +| Library name | Remark | License | +| ---------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------ | +| [numpy](https://numpy.org/) | runtime dependency | [BSD-3](https://github.com/numpy/numpy/blob/main/LICENSE.txt) | +| [scikit-build-core](https://github.com/scikit-build/scikit-build-core) | build dependency | [Apache](https://github.com/scikit-build/scikit-build-core/blob/main/LICENSE) | +| [pytest](https://github.com/pytest-dev/pytest) | Development dependency | [MIT](https://github.com/pytest-dev/pytest/blob/main/LICENSE) | +| [pytest-cov](https://github.com/pytest-dev/pytest-cov) | Development dependency | [MIT](https://github.com/pytest-dev/pytest-cov/blob/master/LICENSE) | +| [msgpack-python](https://github.com/msgpack/msgpack-python) | Development dependency | [Apache License, Version 2.0](https://github.com/msgpack/msgpack-python/blob/main/COPYING) | ## Build Python Package From a5546a48d115f25c052044f25d00a7c5dad738bd Mon Sep 17 00:00:00 2001 From: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:31:12 +0200 Subject: [PATCH 33/33] disable Python 3.14 Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com> --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0535c7374a..5c368e28d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -164,7 +164,8 @@ test-command = "pytest {package}/tests" # we do not support # PyPy # musllinux in aarch64 -skip = ["pp*", "*-musllinux_aarch64"] +# disable Python 3.14 for now until it is released +skip = ["pp*", "*-musllinux_aarch64", "cp314*"] [tool.cibuildwheel.linux] archs = ["x86_64", "aarch64"]