From d5bc4435ac49c6f9fa6e3ae8c200963b9fc07607 Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Sun, 25 Oct 2020 17:16:57 -0500 Subject: [PATCH 1/7] Added setup.py for pip install --- setup.py | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0085aba --- /dev/null +++ b/setup.py @@ -0,0 +1,140 @@ +import os +import platform +import subprocess +import sys +from pprint import pprint +import pathlib +import shutil + +from distutils.command.install_data import install_data +from distutils.command.install_headers import install_headers +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext +from setuptools.command.install_lib import install_lib +from setuptools.command.install_scripts import install_scripts + +# Filename for the C extension module library +c_module_name = 'galario' + +# Command line flags forwarded to CMake (for debug purpose) +cmake_cmd_args = [] +for f in sys.argv: + if f.startswith('-D'): + cmake_cmd_args.append(f) + +for f in cmake_cmd_args: + sys.argv.remove(f) + + +def _get_env_variable(name, default='OFF'): + if name not in os.environ.keys(): + return default + return os.environ[name] + + +class CMakeExtension(Extension): + def __init__(self, name, cmake_lists_dir='../..', sources=[], **kwa): + Extension.__init__(self, name, sources=sources, **kwa) + #self.cmake_lists_dir = os.path.abspath(cmake_lists_dir) + self.cmake_lists_dir = cmake_lists_dir + + +class CMakeBuild(build_ext): + + def build_extensions(self): + try: + out = subprocess.check_output(['cmake', '--version']) + except OSError: + raise RuntimeError('Cannot find CMake executable') + + for ext in self.extensions: + cmake_args = [ + '-DCMAKE_INSTALL_PREFIX=../../{}'.format(self.build_temp), + '-DGALARIO_CHECK_CUDA=0', + '-DPython_ADDITIONAL_VERSIONS={0:d}.{1:d}'.format( + sys.version_info[0], sys.version_info[1]), + ] + + cmake_args += cmake_cmd_args + + pprint(cmake_args) + + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + + extension_path = "{}".format(self.build_lib) + + if not os.path.exists(extension_path): + os.makedirs(extension_path) + + # Config and build the extension + subprocess.check_call(['cmake', ext.cmake_lists_dir] + cmake_args, + cwd=self.build_temp) + subprocess.check_call(['make'], cwd=self.build_temp) + subprocess.check_call(['make', 'install'], cwd=self.build_temp) + + # Copy files to the relevant location. + + bin_dir = self.build_temp + self.distribution.bin_dir = bin_dir + + pyd_path = os.path.join(bin_dir, "lib", "python{0:d}.{1:d}".format( + sys.version_info[0], sys.version_info[1]), "site-packages", + "galario") + + shutil.move(pyd_path, extension_path) + +class InstallCMakeHeaders(install_headers): + def run(self): + print(self.install_dir) + + headers = ["{0:s}/include/{1:s}".format(self.distribution.bin_dir, + header) for header in ["galario.h","galario_defs.h","galario_py.h"]] + + for header in headers: + dst = os.path.join(self.install_dir, os.path.dirname(header. + split("/")[-1])) + self.mkpath(dst) + (out, _) = self.copy_file(header, dst) + self.outfiles.append(out) + +class InstallCMakeLibsData(install_data): + def run(self): + print(self.install_dir) + + libs = ["{0:s}/lib/{1:s}".format(self.distribution.bin_dir, + lib) for lib in ["libgalario.dylib","libgalario_single.dylib"]] + + for lib in libs: + dst = os.path.join(self.install_dir, "lib", os.path.dirname(lib. + split("/")[-1])) + self.mkpath(dst) + (out, _) = self.copy_file(lib, dst) + self.outfiles.append(out) + +class InstallCMakeLibs(install_lib): + def run(self): + super().run() + + self.distribution.run_command("install_data") + self.distribution.run_command("install_headers") + +# The following line is parsed by Sphinx +version = '1.2.2' + +setup(name='galario', + version=version, + description='', + author='Marco Tazzari', + url='https://mtazzari.github.io/galario', + long_description=open('README.md').read(), + long_description_content_type='text/markdown', + install_requires=['numpy','pytest','cython'], + ext_modules=[CMakeExtension(c_module_name)], + cmdclass={ + 'build_ext': CMakeBuild, + 'install_headers': InstallCMakeHeaders, + 'install_data': InstallCMakeLibsData, + 'install_lib': InstallCMakeLibs}, + zip_safe=False, + ) From f8dd216a107dbad912f9edccd97fa538d4888dd3 Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Sun, 25 Oct 2020 22:02:59 -0500 Subject: [PATCH 2/7] Added pyproject.toml to make sure build system is set up properly. --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0412da0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools","wheel","Cython", "numpy","pytest"] From 6b8236a15a4fe9cc64fcafbbabeda0d9923b5c7c Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Sun, 25 Oct 2020 22:03:58 -0500 Subject: [PATCH 3/7] Update description in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0085aba..b7cfd0f 100644 --- a/setup.py +++ b/setup.py @@ -124,7 +124,7 @@ def run(self): setup(name='galario', version=version, - description='', + description='Gpu Accelerated Library for Analysing Radio Interferometer Observations', author='Marco Tazzari', url='https://mtazzari.github.io/galario', long_description=open('README.md').read(), From 321443d318997358ef9d033ab5706c3e5e8c2aa5 Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Sun, 15 Nov 2020 21:15:25 -0600 Subject: [PATCH 4/7] Enable different extensions for MacOS and Linux. --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b7cfd0f..7c7f461 100644 --- a/setup.py +++ b/setup.py @@ -102,8 +102,13 @@ class InstallCMakeLibsData(install_data): def run(self): print(self.install_dir) + if sys.platform == 'darwin': + fileext = ".dylib" + else: + fileext = ".so" + libs = ["{0:s}/lib/{1:s}".format(self.distribution.bin_dir, - lib) for lib in ["libgalario.dylib","libgalario_single.dylib"]] + lib) for lib in ["libgalario"+fileext,"libgalario_single"+fileext]] for lib in libs: dst = os.path.join(self.install_dir, "lib", os.path.dirname(lib. From 56ea2546b515cd767b707e80cedb8687a571f5c1 Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Tue, 12 Jan 2021 13:55:41 -0600 Subject: [PATCH 5/7] Make sure sys.base_prefix/lib is in the RPATH for compiled libraries, as that is where they are installed to. --- setup.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 7c7f461..3202313 100644 --- a/setup.py +++ b/setup.py @@ -68,10 +68,13 @@ def build_extensions(self): os.makedirs(extension_path) # Config and build the extension - subprocess.check_call(['cmake', ext.cmake_lists_dir] + cmake_args, - cwd=self.build_temp) - subprocess.check_call(['make'], cwd=self.build_temp) - subprocess.check_call(['make', 'install'], cwd=self.build_temp) + subprocess.check_call(["env"]+ext.extra_compile_args+\ + ['cmake', ext.cmake_lists_dir] + cmake_args, + cwd=self.build_temp) + subprocess.check_call(["env"]+ext.extra_compile_args+\ + ['make'], cwd=self.build_temp) + subprocess.check_call(["env"]+ext.extra_compile_args+\ + ['make', 'install'], cwd=self.build_temp) # Copy files to the relevant location. @@ -124,6 +127,15 @@ def run(self): self.distribution.run_command("install_data") self.distribution.run_command("install_headers") +# Check which set of extra compile args are needed, based on OS. + +extra_compile_args = [] + +if sys.prefix == 'darwin': + extra_compile_args += ['LDFLAGS="-Wl,-rpath='+sys.base_prefix+'/lib"'] +else: + extra_compile_args += ['LDFLAGS="-Wl,-rpath,'+sys.base_prefix+'/lib"'] + # The following line is parsed by Sphinx version = '1.2.2' @@ -135,7 +147,8 @@ def run(self): long_description=open('README.md').read(), long_description_content_type='text/markdown', install_requires=['numpy','pytest','cython'], - ext_modules=[CMakeExtension(c_module_name)], + ext_modules=[CMakeExtension(c_module_name, + extra_compile_args=extra_compile_args)], cmdclass={ 'build_ext': CMakeBuild, 'install_headers': InstallCMakeHeaders, From 0b92b3e3d12f60d638325032a2ba8bf35ef78430 Mon Sep 17 00:00:00 2001 From: Patrick Sheehan Date: Mon, 18 Jan 2021 22:06:29 -0600 Subject: [PATCH 6/7] setup.py can now handle building with CUDA. --- setup.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 3202313..7a7f23e 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,6 @@ def build_extensions(self): for ext in self.extensions: cmake_args = [ '-DCMAKE_INSTALL_PREFIX=../../{}'.format(self.build_temp), - '-DGALARIO_CHECK_CUDA=0', '-DPython_ADDITIONAL_VERSIONS={0:d}.{1:d}'.format( sys.version_info[0], sys.version_info[1]), ] @@ -111,14 +110,16 @@ def run(self): fileext = ".so" libs = ["{0:s}/lib/{1:s}".format(self.distribution.bin_dir, - lib) for lib in ["libgalario"+fileext,"libgalario_single"+fileext]] + lib) for lib in ["libgalario"+fileext,"libgalario_single"+fileext, \ + "libgalario_cuda"+fileext,"libgalario_single_cuda"+fileext]] for lib in libs: - dst = os.path.join(self.install_dir, "lib", os.path.dirname(lib. - split("/")[-1])) - self.mkpath(dst) - (out, _) = self.copy_file(lib, dst) - self.outfiles.append(out) + if os.path.exists(lib): + dst = os.path.join(self.install_dir, "lib", os.path.dirname(lib. + split("/")[-1])) + self.mkpath(dst) + (out, _) = self.copy_file(lib, dst) + self.outfiles.append(out) class InstallCMakeLibs(install_lib): def run(self): From aad28f7a1161e37a8c1a8fee06fb4aeb24205836 Mon Sep 17 00:00:00 2001 From: mtazzari Date: Thu, 11 Mar 2021 12:54:54 +0000 Subject: [PATCH 7/7] [ci] Attempt to run Tests on mtazzari/galario Actions --- .github/workflows/unit-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 155237d..c67dc4f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -6,7 +6,9 @@ name: Build Galario and Run Unit Tests # workflows running on Linux and MacOS have passwordless sudo rights: # https://stackoverflow.com/questions/57982945/how-to-apt-get-install-in-a-github-actions-workflow -on: push +on: + push + pull_request_target jobs: test: