Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
skrah committed Apr 27, 2024
0 parents commit 461180f
Show file tree
Hide file tree
Showing 25 changed files with 596 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 29 additions & 0 deletions gumath/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
Empty file added gumath/README.rst
Empty file.
35 changes: 35 additions & 0 deletions gumath/build.bat
Original file line number Diff line number Diff line change
@@ -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=<vcpath.txt || goto out
del vcpath.txt || goto out
call "%vcpath%\VC\Auxiliary\Build\vcvarsall.bat" %arch% || goto out

cmake -S ..\source\xnd -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=%install_prefix% ^
-DPython3_EXECUTABLE="%executable%" ^
-DMOD_GUMATH_WITH_XNDLIB=ON || goto out

cmake --build . --config Release --target install --parallel || goto out

cd ..

:out
exit /b 0

:usage
echo "build.bat: usage: build.bat ^<python3 executable^> ^<architecture^> ^<install_prefix^>"
exit /b 1
2 changes: 2 additions & 0 deletions gumath/gumath/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
48 changes: 48 additions & 0 deletions gumath/gumath_backend.py
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 33 additions & 0 deletions gumath/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
29 changes: 29 additions & 0 deletions ndtypes/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
Empty file added ndtypes/README.rst
Empty file.
35 changes: 35 additions & 0 deletions ndtypes/build.bat
Original file line number Diff line number Diff line change
@@ -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=<vcpath.txt || goto out
del vcpath.txt || goto out
call "%vcpath%\VC\Auxiliary\Build\vcvarsall.bat" %arch% || goto out

cmake -S ..\source\xnd -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=%install_prefix% ^
-DPython3_EXECUTABLE="%executable%" ^
-DMOD_NDTYPES_WITH_XNDLIB=ON || goto out

cmake --build . --config Release --target install --parallel || goto out

cd ..

:out
exit /b 0

:usage
echo "build.bat: usage: build.bat ^<python3 executable^> ^<architecture^> ^<install_prefix^>"
exit /b 1
2 changes: 2 additions & 0 deletions ndtypes/ndtypes/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
48 changes: 48 additions & 0 deletions ndtypes/ndtypes_backend.py
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 33 additions & 0 deletions ndtypes/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
29 changes: 29 additions & 0 deletions xnd/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
Empty file added xnd/README.rst
Empty file.
35 changes: 35 additions & 0 deletions xnd/build.bat
Original file line number Diff line number Diff line change
@@ -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=<vcpath.txt || goto out
del vcpath.txt || goto out
call "%vcpath%\VC\Auxiliary\Build\vcvarsall.bat" %arch% || goto out

cmake -S ..\source\xnd -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=%install_prefix% ^
-DPython3_EXECUTABLE="%executable%" ^
-DMOD_XND_WITH_XNDLIB=ON || goto out

cmake --build . --config Release --target install --parallel || goto out

cd ..

:out
exit /b 0

:usage
echo "build.bat: usage: build.bat ^<python3 executable^> ^<architecture^> ^<install_prefix^>"
exit /b 1
Loading

0 comments on commit 461180f

Please sign in to comment.