From eea2cc74f2f78f67aa172485a860da94145c5552 Mon Sep 17 00:00:00 2001 From: pierrepebay Date: Thu, 23 Nov 2023 19:34:17 +0100 Subject: [PATCH] #16: bindings: Switch to modern python package build method and clean up usage --- pyproject.toml | 33 --------------------------------- setup.py | 38 ++++++++++++++++++++++---------------- tests/testvttv.py | 24 ++++++++++++++++++++++++ testvttv.py | 19 ------------------- 4 files changed, 46 insertions(+), 68 deletions(-) delete mode 100644 pyproject.toml create mode 100644 tests/testvttv.py delete mode 100644 testvttv.py diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index f2265a7f76..0000000000 --- a/pyproject.toml +++ /dev/null @@ -1,33 +0,0 @@ -[build-system] -requires = ["setuptools>=42", "wheel", "nanobind>=1.3.2", "cmake>=3.17.0"] -build-backend = "setuptools.build_meta" - -[project] -name = "vttv" -version = "0.0.1" -description = "vt-tv test" -readme = "README.md" -requires-python = ">=3.8" -authors = [ - { name = "Jonathan Lifflander"}, - { name = "Pierre Pebay"} -] -classifiers = [ - "License :: OSI Approved :: BSD License", -] - -[project.urls] -Homepage = "https://github.com/DARMA-tasking/vt-tv" - - -[tool.cibuildwheel] -# Necessary to see build output from the actual compilation -build-verbosity = 1 - -# # Run pytest to ensure that the package was correctly built -# test-command = "pytest {project}/tests" -# test-requires = "pytest" - -# Needed for full C++17 support -[tool.cibuildwheel.macos.environment] -MACOSX_DEPLOYMENT_TARGET = "10.14" diff --git a/setup.py b/setup.py index 777781cf74..6f8a8659ce 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,10 @@ import os import sys +# Ensure python-build directory exists +build_dir = 'python-build' +os.makedirs(build_dir, exist_ok=True) + class CMakeExtension(Extension): def __init__(self, name, sourcedir=''): Extension.__init__(self, name, sources=[]) @@ -14,39 +18,41 @@ def run(self): try: out = subprocess.check_output(['cmake', '--version']) except OSError: - raise RuntimeError('CMake must be installed to build the following extensions: ' + - ', '.join(e.name for e in self.extensions)) + raise RuntimeError("CMake must be installed to build the following extensions: " + + ", ".join(e.name for e in self.extensions)) for ext in self.extensions: self.build_extension(ext) def build_extension(self, ext): extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) - - # Create a temporary build directory build_temp = os.path.join('python-build', 'build', 'temp') os.makedirs(build_temp, exist_ok=True) + vtk_dir = os.environ.get('VTK_DIR') + if not vtk_dir: + raise RuntimeError("Environment variable VTK_DIR is required") + + jobs = os.environ.get('JOBS', os.cpu_count()) + cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DPYTHON_EXECUTABLE=' + sys.executable, - '-DVTK_DIR:PATH=~/Develop/vtk-build', - '-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=13.5'] + '-DVTK_DIR:PATH=' + vtk_dir] + + if sys.platform == "darwin": + import platform + macos_version = platform.mac_ver()[0] + cmake_args.append('-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=' + macos_version) cfg = 'Debug' if self.debug else 'Release' build_args = ['--config', cfg] - # Change to the build directory os.chdir(build_temp) - - # Run CMake and build commands self.spawn(['cmake', ext.sourcedir] + cmake_args) if not self.dry_run: - self.spawn(['cmake', '--build', '.', '--parallel', '-j8'] + build_args) - - # Change back to the original directory + self.spawn(['cmake', '--build', '.', '--parallel', '-j' + str(jobs)] + build_args) os.chdir(ext.sourcedir) - setup( name='vttv', version='0.0.1', @@ -57,7 +63,7 @@ def build_extension(self, ext): long_description='', ext_modules=[CMakeExtension('vttv', sourcedir='.')], cmdclass=dict(build_ext=CMakeBuild), - package_dir={'': 'python-build'}, - packages=find_packages('python-build'), + package_dir={'': build_dir}, + packages=find_packages(build_dir), zip_safe=False, -) \ No newline at end of file +) diff --git a/tests/testvttv.py b/tests/testvttv.py new file mode 100644 index 0000000000..de33a7005f --- /dev/null +++ b/tests/testvttv.py @@ -0,0 +1,24 @@ +import json +import yaml +import vttv + +import sys +import os + +# source dir is the directory a level above this file +source_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +with open(f'{source_dir}/tests/unit/lb_test_data/data.0.json', 'r') as f: + data = json.load(f) + +with open(f'{source_dir}/config/conf.yaml', 'r') as stream: + try: + params = yaml.safe_load(stream) + except yaml.YAMLError as exc: + print(exc) + + +data_serialized = json.dumps(data) +params_serialized = yaml.dump(params) + +vttv.tv_from_json(data_serialized, params_serialized) diff --git a/testvttv.py b/testvttv.py deleted file mode 100644 index 104aaf35f8..0000000000 --- a/testvttv.py +++ /dev/null @@ -1,19 +0,0 @@ -import json -import yaml -import vttv - -with open('/Users/pierrepebay/Develop/vt-tv/tests/unit/lb_test_data/data.0.json') as f: - data = json.load(f) - - -with open("/Users/pierrepebay/Develop/vt-tv/config/conf.yaml", "r") as stream: - try: - params = yaml.safe_load(stream) - except yaml.YAMLError as exc: - print(exc) - - -data_serialized = json.dumps(data) -params_serialized = yaml.dump(params) - -vttv.tv_from_json(data_serialized, params_serialized) \ No newline at end of file