Skip to content

Commit

Permalink
Implemented build using meson backend (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Sep 26, 2022
1 parent 13543ea commit d689181
Show file tree
Hide file tree
Showing 22 changed files with 487 additions and 358 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/* export-ignore
47 changes: 24 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,64 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
name: Build wheel for ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }} ${{ matrix.buildplat[2] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-12]
buildplat:
- [ubuntu-20.04, manylinux, x86_64]
- [macos-12, macosx, x86_64]
- [windows-2019, win, AMD64]
python: [["cp38", "3.8"], ["cp39", "3.9"], ["cp310", "3.10"]]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python[1]}}
- name: Set up Windows
run: |
choco install rtools --no-progress
echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
if: ${{ runner.os == 'Windows' }}

- name: Link gfortran on macos
if: runner.os == 'macOS'
- name: Set up macOS
run: brew unlink gfortran && brew link --overwrite gfortran

if: ${{ runner.os == 'macOS' }}
- uses: pypa/cibuildwheel@v2.10.1
env:
CIBW_BUILD: "cp3?-*"
CIBW_SKIP: "cp35-* *-win32 *-manylinux_i686"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014

- uses: actions/upload-artifact@v2
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}*
CIBW_ARCHS: ${{ matrix.buildplat[2] }}
CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_OS
CIBW_TEST_COMMAND_LINUX: "SPS_HOME={project}/src/fsps/libfsps python {project}/tests/simple.py"
SPS_HOME: ${{ github.workspace }}/src/fsps/libfsps
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.9"

- name: Build sdist
run: |
python -m pip install -U pip
python -m pip install -U build
python -m build --sdist .
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

Expand All @@ -69,12 +71,11 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
- uses: pypa/gh-action-pypi-publish@v1.5.1
with:
user: __token__
password: ${{ secrets.pypi_password }}
Expand Down
91 changes: 46 additions & 45 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,72 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
name: "py${{ matrix.python-version }} / ${{ matrix.os }}"
name: "py${{ matrix.python-version }} / ${{ matrix.os }} / ${{ matrix.nox-session }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]
os: [ubuntu-latest]
nox-session: ["tests"]
include:
- os: macos-latest
python-version: "3.10"
nox-session: "tests"
- os: windows-latest
python-version: "3.10"
nox-session: "tests"
- os: ubuntu-latest
python-version: "3.10"
nox-session: "options"
steps:
- name: Clone the repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Link gfortran on macos
if: runner.os == 'macOS'
- name: Set up Linux
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y gcc g++ gfortran
if: ${{ runner.os == 'Linux' }}
- name: Set up macOS
run: brew unlink gfortran && brew link --overwrite gfortran
- name: Set up windows compilers
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
- name: Install dependencies
if: ${{ runner.os == 'macOS' }}
- name: Set up Windows
run: |
python -m pip install -U pip pytest
python -m pip install .
env:
DISTUTILS_USE_SDK: 1
MSSdk: 1
- name: Run tests
run: python -m pytest --durations=0 --maxfail=1 -vs tests/tests.py
env:
SPS_HOME: ${{ github.workspace }}/src/fsps/libfsps

options:
name: "check compiler options"
runs-on: ubuntu-latest
steps:
- name: Clone the repo
uses: actions/checkout@v2
choco install rtools --no-progress
echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
if: ${{ runner.os == 'Windows' }}
- name: Cache pip packages
uses: actions/cache@v3
with:
fetch-depth: 0
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v2
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.nox-session }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/noxfile.py') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.nox-session }}-${{ hashFiles('**/pyproject.toml') }}-
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.nox-session }}-
- name: Cache nox session files
uses: actions/cache@v3
with:
python-version: 3.9
path: .nox
key: ${{ runner.os }}-nox-${{ matrix.python-version }}-${{ matrix.nox-session }}-${{ hashFiles('**/noxfile.py') }}
restore-keys: |
${{ runner.os }}-nox-${{ matrix.python-version }}-${{ matrix.nox-session }}-
- name: Install dependencies
run: |
python -m pip install -U pip
FFLAGS="-DMIST=0 -DPADOVA=1 -DMILES=0 -DBASEL=1" python -m pip install .
- name: Check libraries
run: |
python << EOF
import fsps
sps = fsps.StellarPopulation()
assert sps.libraries[0] == b'pdva', "Incorrect isochrone library"
assert sps.libraries[1] == b'basel', "Incorrect spectral library"
print("success")
EOF
python -m pip install -U nox
- name: Run tests
run: python -m nox --non-interactive --no-error-on-missing-interpreters -s ${{ matrix.nox-session }}-${{ matrix.python-version }}
env:
SPS_HOME: ${{ github.workspace }}/src/fsps/libfsps

Expand All @@ -79,12 +80,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone the repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ fsps_version.py
.vscode
*.dll
.libs
demos/figures
demos/figures
.mesonpy*
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

35 changes: 29 additions & 6 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,35 @@ FSPS clone and you can just set the `SPS_HOME` variable as:
export SPS_HOME=$(pwd)/src/fsps/libfsps
It is recommended that you install using `pip` (even for a local clone), and you
can use `pip install -e .` to install an "editable" version (like you would get
with `setup.py develop`). But if you want to use the `setup.py` script directly,
you'll need to install some prerequisites in advance:
It is recommended that you install using `pip` even for a local clone. In the
root directory of the repository, run:

.. code-block:: bash
python -m pip install numpy "setuptools_scm[toml]"
python setup.py develop
python -m pip install .
Starting with version 0.5.0, Python-FSPS no longer supports "development" or
"editable" builds, but the builds should be cached and re-used if you run `pip
install` multiple times.

Running the unit tests
----------------------

The unit tests are implemented in the `tests` subdirectory, and can be executed
using `nox <https://nox.thea.codes>`_:

.. code-block:: bash
python -m pip install nox
python -m nox
or `pytest <https://docs.pytest.org>`_ directly:

.. code-block:: bash
python -m pip install ".[test]"
python -m pytest -n 2 -v tests/tests.py
where `-n 2` specifies the number of parallel processes to use. The tests can be
quite slow, but also memory intensive, so it can be useful to run them in
parallel, but don't overdo it and run out of memory!
40 changes: 40 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
project(
'fsps',
'c', 'cpp', 'fortran',
version: run_command(
['python3', 'tools/version.py'],
check : true
).stdout().strip(),
default_options: ['warning_level=0', 'optimization=3'],
meson_version: '>=0.63.0'
)

# Enable fortran and check arguments
# add_languages('fortran', native: false)
ff = meson.get_compiler('fortran')
f_args = ff.get_supported_arguments('-Wno-conversion', '-cpp', '-fPIC')
add_project_arguments(f_args, language: 'fortran')

# Find and link the quadmath library on Windows
if host_machine.system() == 'windows'
cc = meson.get_compiler('c')
quadmath_dep = cc.find_library('quadmath', required: false)
if quadmath_dep.found()
add_project_link_arguments('-lquadmath', language: ['c', 'cpp', 'fortran'])
endif
endif

# Check to see if the submodule is initialized
fs = import('fs')
if not fs.exists('src/fsps/libfsps/src/sps_vars.f90')
error('It looks like FSPS is not included in your source distribution. If you\'re installing using git, don\'t forget to include the submodules using a recursive clone or by running: \ngit submodule update --init')
endif

# Python setup
py_mod = import('python')
py3 = py_mod.find_installation('python3')

# Handle distribution
meson.add_dist_script('tools/dist.py')

subdir('src/fsps')
39 changes: 39 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
from pathlib import Path

import nox

ALL_PYTHON_VS = ["3.8", "3.9", "3.10"]


def _run_with_sps_home(session, *args, **kwargs):
sps_home = os.environ.get(
"SPS_HOME", Path(__file__).parent / "src" / "fsps" / "libfsps"
)
kwargs["env"] = dict(kwargs.get("env", {}), SPS_HOME=str(sps_home))
return session.run(*args, **kwargs)


@nox.session(python=ALL_PYTHON_VS)
def tests(session):
session.install(".[test]")
_run_with_sps_home(session, "python", "tests/simple.py")
_run_with_sps_home(
session,
"python",
"-m",
"pytest",
"-n",
"2",
"--durations=0",
"-v",
"tests/tests.py",
)


@nox.session(python=ALL_PYTHON_VS)
def options(session):
session.install(
".[test]", env={"FFLAGS": "-DMIST=0 -DPADOVA=1 -DMILES=0 -DBASEL=1"}
)
_run_with_sps_home(session, "python", "tests/options.py")

0 comments on commit d689181

Please sign in to comment.