diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..074cf01 --- /dev/null +++ b/README.rst @@ -0,0 +1,7 @@ + +xndpy +===== + +xndpy is intended for packaging the Python bindings for xnd. The authoritative +sources for the Python modules are in the xnd repository, where they are built +for testing libndtypes, libxnd and libgumath. diff --git a/gumath/LICENSE.txt b/gumath/LICENSE.txt new file mode 100644 index 0000000..53b287e --- /dev/null +++ b/gumath/LICENSE.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2024, Stefan Krah +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/gumath/README.rst b/gumath/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/gumath/build.bat b/gumath/build.bat new file mode 100755 index 0000000..aae8b87 --- /dev/null +++ b/gumath/build.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +if "%~1" == "" goto usage +if "%~2" == "" goto usage +if "%~3" == "" goto usage +if not "%~4" == "" goto usage + +set executable=%1 || goto out +set arch=%2 || goto out +set install_prefix=%3 || goto out + +if exist xnd_build rd /q /s xnd_build || goto out +mkdir xnd_build || goto out +cd xnd_build || goto out + +"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath > vcpath.txt || goto out +set /p vcpath= ^ ^" +exit /b 1 diff --git a/gumath/gumath/__init__.py b/gumath/gumath/__init__.py new file mode 100644 index 0000000..d50de91 --- /dev/null +++ b/gumath/gumath/__init__.py @@ -0,0 +1,2 @@ +# DO NOT EDIT: This file may be overwritten by in-tree builds. The real +# sources are in src/xnd/mod/ndtypes. diff --git a/gumath/gumath_backend.py b/gumath/gumath_backend.py new file mode 100644 index 0000000..0b2e8c9 --- /dev/null +++ b/gumath/gumath_backend.py @@ -0,0 +1,48 @@ +from flit.buildapi import build_wheel as _build_wheel +from flit.buildapi import build_sdist as _build_sdist +import os ,platform, shutil +import subprocess, sys, sysconfig + +def check_err(proc): + if proc.returncode != 0: + raise RuntimeError("executing cmake commands failed") + +def call_cmake(install_prefix): + proc = subprocess.run(["cmake", + "-S", "../source/xnd", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=%s" % install_prefix, + "-DPython3_EXECUTABLE=%s" % sys.executable, + "-DMOD_GUMATH_WITH_XNDLIB=ON"]) + check_err(proc) + + proc = subprocess.run(["cmake", + "--build", ".", + "--config", "Release", + "--target", "install", + "--parallel"]) + check_err(proc) + +def build_wheel(wheel_dir, config_settings=None, metadata_directory=None): + + arch = "x64" if platform.architecture()[0] == "64bit" else "x86" + mingw = "mingw" in sysconfig.get_platform() + install_prefix = os.path.abspath(os.path.dirname(__file__)) + + if sys.platform == "win32" and not mingw: + proc = subprocess.run(["build.bat", sys.executable, arch, install_prefix]) + else: + if os.path.isdir("gumath_build"): + shutil.rmtree("gumath_build") + os.mkdir("gumath_build") + os.chdir("gumath_build") + + try: + call_cmake(install_prefix) + finally: + os.chdir("..") + + return _build_wheel(wheel_dir, config_settings, metadata_directory) + +def build_sdist(sdist_dir, config_settings=None): + return _build_sdist(sdist_dir, config_settings) diff --git a/gumath/pyproject.toml b/gumath/pyproject.toml new file mode 100644 index 0000000..4f3b5ab --- /dev/null +++ b/gumath/pyproject.toml @@ -0,0 +1,33 @@ +[project] +name = "gumath" +version = "0.3.2" +dependencies = ["xndlibs==0.3.2", "ndtypes==0.3.2", "xnd==0.3.2"] +requires-python = ">=3.8" + +authors = [ { name = "Stefan Krah", email = "skrah@bytereef.org" } ] +license = { file = "LICENSE.txt" } +description = "Dynamic types for data description and in-memory computations" +keywords = ["gumath", "array computing", "data description"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Financial and Insurance Industry", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD-3-clause", + "Programming Language :: C", + "Programming Language :: C++", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Software Development"] + +[build-system] +requires = ["flit"] +build-backend = "gumath_backend" +backend-path = ["."] + +[tool.flit.sdist] +include = ["gumath", "source", "gumath_backend.py", "build.bat", + "pyproject.toml"] +exclude = ["source/xnd/.git"] diff --git a/ndtypes/LICENSE.txt b/ndtypes/LICENSE.txt new file mode 100644 index 0000000..53b287e --- /dev/null +++ b/ndtypes/LICENSE.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2024, Stefan Krah +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ndtypes/README.rst b/ndtypes/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/ndtypes/build.bat b/ndtypes/build.bat new file mode 100755 index 0000000..e2a89bd --- /dev/null +++ b/ndtypes/build.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +if "%~1" == "" goto usage +if "%~2" == "" goto usage +if "%~3" == "" goto usage +if not "%~4" == "" goto usage + +set executable=%1 || goto out +set arch=%2 || goto out +set install_prefix=%3 || goto out + +if exist xnd_build rd /q /s xnd_build || goto out +mkdir xnd_build || goto out +cd xnd_build || goto out + +"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath > vcpath.txt || goto out +set /p vcpath= ^ ^" +exit /b 1 diff --git a/ndtypes/ndtypes/__init__.py b/ndtypes/ndtypes/__init__.py new file mode 100644 index 0000000..d50de91 --- /dev/null +++ b/ndtypes/ndtypes/__init__.py @@ -0,0 +1,2 @@ +# DO NOT EDIT: This file may be overwritten by in-tree builds. The real +# sources are in src/xnd/mod/ndtypes. diff --git a/ndtypes/ndtypes_backend.py b/ndtypes/ndtypes_backend.py new file mode 100644 index 0000000..47bf5fe --- /dev/null +++ b/ndtypes/ndtypes_backend.py @@ -0,0 +1,48 @@ +from flit.buildapi import build_wheel as _build_wheel +from flit.buildapi import build_sdist as _build_sdist +import os ,platform, shutil +import subprocess, sys, sysconfig + +def check_err(proc): + if proc.returncode != 0: + raise RuntimeError("executing cmake commands failed") + +def call_cmake(install_prefix): + proc = subprocess.run(["cmake", + "-S", "../source/xnd", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=%s" % install_prefix, + "-DPython3_EXECUTABLE=%s" % sys.executable, + "-DMOD_NDTYPES_WITH_XNDLIB=ON"]) + check_err(proc) + + proc = subprocess.run(["cmake", + "--build", ".", + "--config", "Release", + "--target", "install", + "--parallel"]) + check_err(proc) + +def build_wheel(wheel_dir, config_settings=None, metadata_directory=None): + + arch = "x64" if platform.architecture()[0] == "64bit" else "x86" + mingw = "mingw" in sysconfig.get_platform() + install_prefix = os.path.abspath(os.path.dirname(__file__)) + + if sys.platform == "win32" and not mingw: + proc = subprocess.run(["build.bat", sys.executable, arch, install_prefix]) + else: + if os.path.isdir("ndtypes_build"): + shutil.rmtree("ndtypes_build") + os.mkdir("ndtypes_build") + os.chdir("ndtypes_build") + + try: + call_cmake(install_prefix) + finally: + os.chdir("..") + + return _build_wheel(wheel_dir, config_settings, metadata_directory) + +def build_sdist(sdist_dir, config_settings=None): + return _build_sdist(sdist_dir, config_settings) diff --git a/ndtypes/pyproject.toml b/ndtypes/pyproject.toml new file mode 100644 index 0000000..efb6530 --- /dev/null +++ b/ndtypes/pyproject.toml @@ -0,0 +1,33 @@ +[project] +name = "ndtypes" +version = "0.3.2" +dependencies = ["xndlibs==0.3.2"] +requires-python = ">=3.8" + +authors = [ { name = "Stefan Krah", email = "skrah@bytereef.org" } ] +license = { file = "LICENSE.txt" } +description = "Dynamic types for data description and in-memory computations" +keywords = ["ndtypes", "array computing", "data description"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Financial and Insurance Industry", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD-3-clause", + "Programming Language :: C", + "Programming Language :: C++", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Software Development"] + +[build-system] +requires = ["flit"] +build-backend = "ndtypes_backend" +backend-path = ["."] + +[tool.flit.sdist] +include = ["ndtypes", "source", "ndtypes_backend.py", "build.bat", + "pyproject.toml"] +exclude = ["source/xnd/.git"] diff --git a/xnd/LICENSE.txt b/xnd/LICENSE.txt new file mode 100644 index 0000000..53b287e --- /dev/null +++ b/xnd/LICENSE.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2024, Stefan Krah +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/xnd/README.rst b/xnd/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/xnd/build.bat b/xnd/build.bat new file mode 100755 index 0000000..7a23485 --- /dev/null +++ b/xnd/build.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +if "%~1" == "" goto usage +if "%~2" == "" goto usage +if "%~3" == "" goto usage +if not "%~4" == "" goto usage + +set executable=%1 || goto out +set arch=%2 || goto out +set install_prefix=%3 || goto out + +if exist xnd_build rd /q /s xnd_build || goto out +mkdir xnd_build || goto out +cd xnd_build || goto out + +"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath > vcpath.txt || goto out +set /p vcpath= ^ ^" +exit /b 1 diff --git a/xnd/pyproject.toml b/xnd/pyproject.toml new file mode 100644 index 0000000..f6de92b --- /dev/null +++ b/xnd/pyproject.toml @@ -0,0 +1,35 @@ +[project] +name = "xnd" +version = "0.3.2" +dependencies = ["xndlibs==0.3.2", "ndtypes==0.3.2"] +requires-python = ">=3.8" + +authors = [ { name = "Stefan Krah", email = "skrah@bytereef.org" } ] +license = { file = "LICENSE.txt" } +description = "Dynamic types for data description and in-memory computations" +keywords = ["ndtypes", "array computing", "data description"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Financial and Insurance Industry", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD-3-clause", + "Programming Language :: C", + "Programming Language :: C++", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Software Development"] + +[build-system] +requires = ["flit"] +build-backend = "xnd_backend" +backend-path = ["."] + +[tool.flit.module] +name = "xnd" + +[tool.flit.sdist] +include = ["xnd", "source", "xnd_backend.py", "build.bat", "pyproject.toml"] +exclude = ["source/xnd/.git"] diff --git a/xnd/xnd/__init__.py b/xnd/xnd/__init__.py new file mode 100644 index 0000000..0c90d5b --- /dev/null +++ b/xnd/xnd/__init__.py @@ -0,0 +1,2 @@ +# DO NOT EDIT: This file may be overwritten by in-tree builds. The real +# sources are in src/xnd/mod/xnd. diff --git a/xnd/xnd_backend.py b/xnd/xnd_backend.py new file mode 100644 index 0000000..07bb77a --- /dev/null +++ b/xnd/xnd_backend.py @@ -0,0 +1,48 @@ +from flit.buildapi import build_wheel as _build_wheel +from flit.buildapi import build_sdist as _build_sdist +import os ,platform, shutil +import subprocess, sys, sysconfig + +def check_err(proc): + if proc.returncode != 0: + raise RuntimeError("executing cmake commands failed") + +def call_cmake(install_prefix): + proc = subprocess.run(["cmake", + "-S", "../source/xnd", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=%s" % install_prefix, + "-DPython3_EXECUTABLE=%s" % sys.executable, + "-DMOD_XND_WITH_XNDLIB=ON"]) + check_err(proc) + + proc = subprocess.run(["cmake", + "--build", ".", + "--config", "Release", + "--target", "install", + "--parallel"]) + check_err(proc) + +def build_wheel(wheel_dir, config_settings=None, metadata_directory=None): + + arch = "x64" if platform.architecture()[0] == "64bit" else "x86" + mingw = "mingw" in sysconfig.get_platform() + install_prefix = os.path.abspath(os.path.dirname(__file__)) + + if sys.platform == "win32" and not mingw: + proc = subprocess.run(["build.bat", sys.executable, arch, install_prefix]) + else: + if os.path.isdir("ndtypes_build"): + shutil.rmtree("ndtypes_build") + os.mkdir("xnd_build") + os.chdir("xnd_build") + + try: + call_cmake(install_prefix) + finally: + os.chdir("..") + + return _build_wheel(wheel_dir, config_settings, metadata_directory) + +def build_sdist(sdist_dir, config_settings=None): + return _build_sdist(sdist_dir, config_settings) diff --git a/xndlib/LICENSE.txt b/xndlib/LICENSE.txt new file mode 100644 index 0000000..53b287e --- /dev/null +++ b/xndlib/LICENSE.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2024, Stefan Krah +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/xndlib/README.rst b/xndlib/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/xndlib/build.bat b/xndlib/build.bat new file mode 100755 index 0000000..5e1584c --- /dev/null +++ b/xndlib/build.bat @@ -0,0 +1,32 @@ +@ECHO OFF + +if "%~1" == "" goto usage +if "%~2" == "" goto usage +if not "%~3" == "" goto usage + +set arch=%1 || goto out +set install_prefix=%2 || goto out + +if exist xnd_build rd /q /s xnd_build || goto out +mkdir xnd_build || goto out +cd xnd_build || goto out + +"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath > vcpath.txt || goto out +set /p vcpath=" +exit /b 1 diff --git a/xndlib/pyproject.toml b/xndlib/pyproject.toml new file mode 100644 index 0000000..a09f7d7 --- /dev/null +++ b/xndlib/pyproject.toml @@ -0,0 +1,33 @@ +[project] +name = "xndlib" +version = "0.3.2" +requires-python = ">=3.8" + +authors = [ { name = "Stefan Krah", email = "skrah@bytereef.org" } ] +license = { file = "LICENSE.txt" } +description = "libndtypes, libxnd and libgumath" +keywords = ["ndtypes", "xnd", "gumath", "array computing", + "data description"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Financial and Insurance Industry", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD-3-clause", + "Programming Language :: C", + "Programming Language :: C++", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Software Development"] + +[build-system] +requires = ["flit"] +build-backend = "xndlib_backend" +backend-path = ["."] + +[tool.flit.sdist] +include = ["xndlib", "source", "xndlib_backend.py", "build.bat", + "pyproject.toml"] +exclude = ["source/xnd/.git"] diff --git a/xndlib/xndlib/__init__.py b/xndlib/xndlib/__init__.py new file mode 100644 index 0000000..d6c3c3b --- /dev/null +++ b/xndlib/xndlib/__init__.py @@ -0,0 +1,5 @@ +raise ImportError(""" +The xndlib module is a directory for the libndtypes, libxnd and libgumath +libraries required by the ndtypes, xnd and gumath modules. It is not intended +to be imported. +""") diff --git a/xndlib/xndlib_backend.py b/xndlib/xndlib_backend.py new file mode 100644 index 0000000..82d9a06 --- /dev/null +++ b/xndlib/xndlib_backend.py @@ -0,0 +1,47 @@ +from flit.buildapi import build_wheel as _build_wheel +from flit.buildapi import build_sdist as _build_sdist +import os, platform, shutil +import subprocess, sys, sysconfig + +def check_err(proc): + if proc.returncode != 0: + raise RuntimeError("executing cmake commands failed") + +def call_cmake(install_prefix): + proc = subprocess.run(["cmake", + "-S", "../source/xnd", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=%s" % install_prefix, + "-DLIB_XNDLIB_WITH_MOD_HEADERS=ON"]) + check_err(proc) + + proc = subprocess.run(["cmake", + "--build", ".", + "--config", "Release", + "--target", "install", + "--parallel"]) + check_err(proc) + +def build_wheel(wheel_dir, config_settings=None, metadata_directory=None): + + arch = "x64" if platform.architecture()[0] == "64bit" else "x86" + mingw = "mingw" in sysconfig.get_platform() + install_prefix = os.path.abspath(os.path.dirname(__file__)) + + if sys.platform == "win32" and not mingw: + proc = subprocess.run(["build.bat", arch, install_prefix]) + else: + if os.path.isdir("xndlib_build"): + shutil.rmtree("xndlib_build") + os.mkdir("xndlib_build") + os.chdir("xndlib_build") + + try: + call_cmake(install_prefix) + finally: + os.chdir("..") + + return _build_wheel(wheel_dir, config_settings, metadata_directory) + +def build_sdist(sdist_dir, config_settings=None): + return _build_sdist(sdist_dir, config_settings)