Skip to content

Commit 555a5e9

Browse files
authored
Merge pull request #100 from simonsobs/feature-mesonpy
Feature mesonpy
2 parents 55c0b9e + 944be4b commit 555a5e9

22 files changed

+282
-3058
lines changed

.github/workflows/testing.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111

12+
env:
13+
FC: gfortran-12
14+
CC: gcc-12
15+
CXX: gcc-12
16+
1217
jobs:
18+
1319
build:
1420

1521
runs-on: ${{ matrix.os }}
1622
strategy:
1723
matrix:
1824
os: [ubuntu-latest, macos-latest]
19-
python-version: ["3.8", "3.9", "3.10", "3.11"]
25+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2026

2127
steps:
2228
- uses: actions/checkout@v4
@@ -29,19 +35,13 @@ jobs:
2935
- name: Set gfortran link on macos-latest
3036
if: matrix.os == 'macos-latest'
3137
run: |
32-
set -x
33-
sudo ln -s /usr/local/bin/gfortran-11 /usr/local/bin/gfortran
38+
ln -s $FC $(dirname $(which $FC))/gfortran
3439
gfortran --version
3540
3641
- name: Install via pip
3742
run: |
38-
python -m pip install --upgrade pip wheel
39-
python -m pip install numpy pytest pytest-cov
40-
python -m pip install -e .
41-
42-
- name: Install extra dependencies (camb)
43-
run: |
44-
python -m pip install camb
43+
python -m pip install --upgrade pip setuptools wheel meson ninja meson-python numpy
44+
python -m pip install --no-build-isolation --editable '.[test]'
4545
4646
- name: Download test data
4747
run: |
@@ -51,18 +51,20 @@ jobs:
5151
5252
- name: Unit tests
5353
run: |
54-
pytest -vv pspy --cov=pspy --cov-report=xml:coverage.xml --ignore=pspy/tests/test_pspy_namaster.py
54+
pytest -vv pspy --cov=pspy --cov-report=xml --cov-report annotate --ignore=pspy/tests/test_pspy_namaster.py
5555
5656
- name: Report Coverage (codecov)
5757
if: matrix.os == 'ubuntu-latest'
5858
uses: codecov/codecov-action@v4
59+
env:
60+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5961

60-
- name: Test notebooks (Only on Linux for saving time)
61-
if: matrix.os == 'ubuntu-latest'
62-
run: |
63-
python -m pip install jupyter ipykernel
64-
python -m ipykernel install --user --name=pspy
65-
jupyter nbconvert --to notebook --execute docs/source/notebooks/tutorial_io.ipynb
62+
# - name: Test notebooks (Only on Linux for saving time)
63+
# if: matrix.os == 'ubuntu-latest'
64+
# run: |
65+
# python -m pip install '.[notebook]'
66+
# python -m ipykernel install --user --name=pspy
67+
# jupyter nbconvert --to notebook --execute docs/source/notebooks/tutorial_io.ipynb
6668

6769
- name: Comparing pspy to NaMaster
6870
if: matrix.os == 'ubuntu-latest'

.github/workflows/wheels.yml

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,25 @@ concurrency:
1414

1515
jobs:
1616
build_wheels:
17-
name: Build wheels on ${{ matrix.os }} for ${{ matrix.cp }}
17+
name: Build wheels on ${{ matrix.os }}
1818
runs-on: ${{ matrix.os }}
1919
strategy:
2020
matrix:
21-
# macos-13 is an intel runner, macos-14 is apple silicon
2221
os: [ubuntu-latest, macos-13, macos-14]
23-
cp: [cp38, cp39, cp310, cp311]
24-
include:
25-
- cp: cp38
26-
numpyver: "1.22"
27-
- cp: cp39
28-
numpyver: "1.22"
29-
- cp: cp310
30-
numpyver: "1.22"
31-
- cp: cp311
32-
numpyver: "1.22"
3322

3423
steps:
3524
- uses: actions/checkout@v4
3625

37-
- name: Set gfortran link for macos-13
38-
if: matrix.os == 'macos-13'
39-
run: |
40-
set -x
41-
sudo ln -s /usr/local/bin/gfortran-11 /usr/local/bin/gfortran
42-
43-
- name: Set gfortran link for macos-14
44-
if: matrix.os == 'macos-14'
45-
run: |
46-
set -x
47-
sudo ln -s /opt/homebrew/bin/gfortran-11 /usr/local/bin/gfortran
48-
4926
- name: Build wheels
50-
uses: pypa/cibuildwheel@v2.17.0
27+
uses: pypa/cibuildwheel@v2.21.1
5128
env:
52-
CIBW_BEFORE_BUILD: "python -m pip install numpy==${{ matrix.numpyver }}"
53-
CIBW_BUILD_VERBOSITY: 3
54-
CIBW_BUILD: "${{ matrix.cp }}-*"
55-
CIBW_SKIP: "*-musllinux_* *i686*"
29+
FC: gfortran-14
30+
CC: gcc-14
31+
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-13' && '13.0' || '14.0' }}
5632

5733
- uses: actions/upload-artifact@v4
5834
with:
59-
name: cibw-wheels-${{ matrix.os }}-${{ matrix.cp }}
35+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
6036
path: ./wheelhouse/*.whl
6137
retention-days: 1
6238

@@ -69,19 +45,14 @@ jobs:
6945
- uses: actions/setup-python@v5
7046
name: Install Python
7147
with:
72-
python-version: '3.8'
73-
74-
- name: Brew packages
75-
if: matrix.os == 'macos-13'
76-
run: |
77-
set -x
78-
sudo ln -s /usr/local/bin/gfortran-11 /usr/local/bin/gfortran
79-
gfortran --version
48+
python-version: '3.10'
8049

8150
- name: Build sdist
8251
run: |
52+
python -m pip install --upgrade pip setuptools wheel
8353
python -m pip install numpy
84-
python setup.py sdist
54+
python -m pip install build
55+
python -m build --sdist
8556
8657
- uses: actions/upload-artifact@v4
8758
with:

MANIFEST.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,29 @@ You can test your installation by running
3737
3838
test-pspy
3939
40-
If everything goes fine, no errors will occur. Otherwise, you can report your problem on the `Issues tracker <https://github.com/simonsobs/pspy/issues>`_.
40+
If everything goes fine, no errors will occur. Otherwise, you can report your problem on the `Issues
41+
tracker <https://github.com/simonsobs/pspy/issues>`_.
4142

4243
If you plan to develop ``pspy``, it is better to checkout the latest version by doing
4344

4445
.. code:: shell
4546
4647
git clone https://github.com/simonsobs/pspy.git /where/to/clone
4748
49+
Once downloaded, you can install using ``pip install .`` inside the project directory. We use the
50+
``meson`` build system, which should be understood by ``pip`` (it will build in an isolated
51+
environment).
52+
53+
To run an editable install, you will need to do so in a way that does not have build isolation (as
54+
the backend build system, ``meson`` and ``ninja``, actually perform micro-builds on usage in this
55+
case):
56+
4857
Then you can install the ``pspy`` library and its dependencies *via*
4958

5059
.. code:: shell
5160
52-
pip install -e /where/to/clone
61+
pip install --upgrade pip setuptools meson ninja meson-python numpy
62+
pip install --no-build-isolation --editable /where/to/clone
5363
5464
The ``-e`` option allow the developer to make changes within the ``pspy`` directory without having
5565
to reinstall at every changes.

codecov.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

meson.build

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Main build file for pspy, helping with building the fortran
2+
project(
3+
'pspy',
4+
['c', 'fortran']
5+
)
6+
7+
py = import('python').find_installation(pure: false)
8+
9+
# Dependencies
10+
py_dep = py.dependency()
11+
omp_dep = dependency('openmp')
12+
13+
# Libraries
14+
cc = meson.get_compiler('c')
15+
c_m_dep = cc.find_library('m', required: true)
16+
17+
fc = meson.get_compiler('fortran')
18+
fortran_m_dep = fc.find_library('m', required: true)
19+
20+
# Directories
21+
library_install_dir = py.get_install_dir() / 'pspy'
22+
23+
# Includes
24+
25+
# Need to massage these into relative paths to keep meson happy.
26+
# It does not allow for absolute paths.
27+
incdir_numpy = run_command(
28+
py,
29+
['-c', 'import numpy; import os; print(os.path.relpath(numpy.get_include()))'],
30+
check: true
31+
).stdout().strip()
32+
33+
incdir_f2py = run_command(
34+
py,
35+
['-c', 'import numpy.f2py; import os; print(os.path.relpath(numpy.f2py.get_include()))'],
36+
check: true
37+
).stdout().strip()
38+
39+
# Build fortran extensions
40+
fortran_include = include_directories(incdir_numpy, incdir_f2py)
41+
42+
fortran_sources = {
43+
'pspy/mcm_fortran/mcm_fortran.f90': '_mcm_fortran',
44+
'pspy/cov_fortran/cov_fortran.f90': '_cov_fortran',
45+
}
46+
47+
foreach source_name, module_name : fortran_sources
48+
f2py_output = custom_target(
49+
input: source_name,
50+
output: [module_name + '-f2pywrappers2.f90', module_name + 'module.c'],
51+
command: [py, '-m', 'numpy.f2py', '@INPUT@', '-m', module_name, '--lower'],
52+
)
53+
54+
py.extension_module(
55+
module_name,
56+
[source_name, f2py_output],
57+
'pspy/wigner3j/wigner3j_sub.f',
58+
incdir_f2py / 'fortranobject.c',
59+
include_directories: fortran_include,
60+
dependencies: [py_dep, omp_dep, c_m_dep, fortran_m_dep],
61+
install: true,
62+
subdir: 'pspy'
63+
)
64+
endforeach
65+
66+
subdir('pspy')
67+
subdir('scripts')

pspy/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
from __future__ import absolute_import, print_function
1+
from importlib.metadata import PackageNotFoundError, version
22

3-
from pspy import (mcm_fortran, pspy_utils, so_config, so_cov, so_dict, so_map,
4-
so_map_preprocessing, so_mcm, so_misc, so_mpi, so_spectra,
5-
so_window, sph_tools, flat_tools)
3+
from pspy import (
4+
flat_tools,
5+
pspy_utils,
6+
so_config,
7+
so_cov,
8+
so_dict,
9+
so_map,
10+
so_map_preprocessing,
11+
so_mcm,
12+
so_misc,
13+
so_mpi,
14+
so_spectra,
15+
so_window,
16+
sph_tools,
17+
)
618

7-
from . import _version
8-
__version__ = _version.get_versions()['version']
19+
try:
20+
__version__ = version("pspy")
21+
except PackageNotFoundError:
22+
__version__ = "unknown"

0 commit comments

Comments
 (0)