From 7170bc3683be0d4d968a43f68b231b0b879814c2 Mon Sep 17 00:00:00 2001 From: Jost Migenda Date: Fri, 7 Jun 2024 18:22:40 +0100 Subject: [PATCH] add simple build workflow, update setup.py * remove hard-coded paths from setup.py * remove unused distutils import in setup.py (Note that distutils has been removed in Python 3.12) * skip Ubuntu and Windows for now --- .github/workflows/build.yaml | 54 ++++++++++++++++++++++++++++++++++++ setup.py | 20 +++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c7a8126 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,54 @@ +name: Build EMEWS + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the main branch +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + strategy: + fail-fast: false + matrix: + os: [macos-latest] # [macos-latest, ubuntu-latest, windows-latest] + python-version: ['3.12'] # ['3.9', '3.10', '3.11', '3.12'] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies (all OSes) + run: | + python -m pip install --upgrade pip + pip install setuptools wheel pybind11 + - name: Install dependencies (macOS) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + brew install libomp + echo "LIBOMP_INCLUDE=`brew --prefix`/opt/libomp/include" >> $GITHUB_ENV + - name: Install dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + exit 1 # TODO: Add Ubuntu dependencies here + - name: Install dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + exit 1 # TODO: Add Windows dependencies here + + - name: Install EMEWS + run: | + python setup.py sdist bdist_wheel + ls -al dist/ + pip install dist/*.whl + - name: Run example script + run: | + python EMEWS_example.py diff --git a/setup.py b/setup.py index ac665fa..d379313 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,10 @@ import os -from distutils.command.sdist import sdist as DistutilsSdist from setuptools import setup, find_packages from setuptools.extension import Extension +import sysconfig +import pybind11 # # Begin setup @@ -52,13 +53,20 @@ 'docs':['numpydoc'] } +LIBOMP_INCLUDE = os.environ['LIBOMP_INCLUDE'] +PYBIND11_INCLUDE = os.path.join(pybind11.__path__[0], "include") +if os.name == 'posix': # macOS or Linux + LIBDIR = sysconfig.get_config_var('LIBDIR') +elif os.name == 'nt': # Windows + LIBDIR = sysconfig.get_config_var('LIBDEST') + EMEWS = Extension('EMEWS', define_macros = [('MAJOR_VERSION', '1'), ('MINOR_VERSION', '0')], - include_dirs = ['/usr/local/lib/python3.9/site-packages/pybind11/include', './src', './src/mstl', './src/mstl/math2', './src/mstl/math2/algebra', './src/mstl/math2/analysis', './src/mstl/math2/spline', './src/mstl/physics'], - libraries = ['stdc++', 'm', 'gomp', 'python3'], - library_dirs = ['/usr/lib64'], - extra_compile_args = ['-std=c++17', '-fopenmp', '-fPIC', '-nostartfiles'], - extra_link_args = ['-shared'], + include_dirs = [LIBOMP_INCLUDE, PYBIND11_INCLUDE, './src', './src/mstl', './src/mstl/math2', './src/mstl/math2/algebra', './src/mstl/math2/analysis', './src/mstl/math2/spline', './src/mstl/physics'], + # libraries = ['stdc++', 'm', 'gomp', 'python3'], + library_dirs = [LIBDIR], + extra_compile_args = ['-std=c++17', '-fPIC', '-nostartfiles'], + # extra_link_args = ['-shared'], sources = ['./src/EMEWS.cpp', './src/adiabatic_basis.cpp', './src/eigenvalues.cpp', './src/flavour_basis.cpp', './src/input_class.EMEWS.cpp', './src/jacobians.cpp', './src/mixing_angles.cpp', './src/output.EMEWS.cpp', './src/output_matrix.EMEWS.cpp', './src/parameters.cpp', './src/potentials.cpp', './src/RK.EMEWS.cpp', './src/update.EMEWS.cpp', './src/mstl/errors2.cpp', './src/mstl/messages.cpp', './src/mstl/miscellaneous functions.cpp', './src/mstl/stdarg2.cpp', './src/mstl/math2/algebra/column and row vectors.cpp', './src/mstl/math2/algebra/linear algebra.cpp', './src/mstl/math2/algebra/mmatrix.cpp', './src/mstl/math2/analysis/algorithm3.cpp', './src/mstl/math2/analysis/complex2.cpp', './src/mstl/math2/analysis/derivative.cpp', './src/mstl/math2/analysis/polynomial.cpp', './src/mstl/math2/analysis/roots.cpp', './src/mstl/math2/analysis/runge kutta.cpp', './src/mstl/math2/analysis/special functions.cpp', './src/mstl/math2/spline/discontinuous.cpp', './src/mstl/math2/spline/interpolation data.cpp', './src/mstl/physics/units and constants.cpp']) setup_keywords['ext_modules'] = [EMEWS]