Skip to content

Switch the build system to meson - #1948

Closed
DougBurke wants to merge 6 commits into
sherpa:mainfrom
DougBurke:test-mesonpy
Closed

DougBurke wants to merge 6 commits into
sherpa:mainfrom
DougBurke:test-mesonpy

Conversation

@DougBurke

@DougBurke DougBurke commented Jan 8, 2024 •

Copy link
Copy Markdown
Contributor

Summary

Can we build Sherpa with meson?

Details.

Yes.

Well, kind of.

We can see it building for Linux and macOS (both x86 and arm). It also includes "optional" code such as XSPEC.

BUT it builds and the tests pass. So :shipit:

Known issues include

  • I have not tried to verify exactly what's in the sdist or wheel, so there could well be problems (I'm expecting some linkage problems).
    • initial tests have been successful (I have been able to use both the sdist and wheel) but that is on the same system/environment so limited applicability
  • I have not tried building against CIAO and I fully expect that to shake out some buglets
    pip install . --verbose -Csetup-args=-Dxspec-prefix=$ASCDS_INSTALL -Csetup-args=-Dxspec-libraries=XSFunctions,XSUtil,XS -Csetup-args=-Dbuild-group=false -Csetup-args=-Dbuild-stk=false -Csetup-args=-Dbuild-region=false -Csetup-args=-Dregion-prefix=$ASCDS_INSTALL -Csetup-args=-Dbuild-wcssubs=false -Csetup-args=-Dwcssubs-prefix=$ASCDS_INSTALL
    • actually, this seemed to work (after shaking out the buglets)
  • setting the version
    • this has fun consequences for building the documentation
    • this has "kind of" been fixed, but it still uses versioneer but is this the best way to do it, and it requires that python3 is available
  • the current code assumes that the FFTW3 module and include directories [?] are already installed, rather than building it ourselves (since I ran out of time trying to glue together meson and autoconf/tools)
  • the build documentation has not been updated
    • a first pass has been made
  • the setuptools-related code is still present
  • extern has been renamed subprojects as this seems like a sensible way to go with meson, except that these are almost not-really OTS; there's also a question of whether to version-number the directories
  • why do the tests in test_tests.py fail; somehow the assert rewrite that pytest does is not being triggered, possibly because we now use --no-build-isolation;

Notes

Editable install success

With an editable install (and --no-build-isolation) I edited a .cc file and a test (to use the new compiled module feature) and pytest ..../test...py actually recompiled just the code I'd changes and ran the test using it. This is noice.

libraries

Here's the ldd output for sherpa/astro/_xspec from CIAO 4.17

	linux-vdso.so.1 (0x00007ffe44fbf000)
	libXSFunctions.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../libXSFunctions.so (0x00007bb5db400000)
	libXSUtil.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../libXSUtil.so (0x00007bb5db2c2000)
	libstdc++.so.6 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../libstdc++.so.6 (0x00007bb5db0e0000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007bb5daff7000)
	libgcc_s.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../libgcc_s.so.1 (0x00007bb5dcb5c000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007bb5dac00000)
	libXS.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libXS.so (0x00007bb5dcb3a000)
	libwcs-8.2.1.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libwcs-8.2.1.so (0x00007bb5dae7e000)
	libhdsp_6.33.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libhdsp_6.33.so (0x00007bb5daa12000)
	libhdutils_6.33.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libhdutils_6.33.so (0x00007bb5dae78000)
	libfgsl.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libfgsl.so.1 (0x00007bb5da995000)
	libgsl.so.25 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libgsl.so.25 (0x00007bb5da600000)
	libCCfits_2.6.so => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libCCfits_2.6.so (0x00007bb5da200000)
	libcfitsio.so.10 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libcfitsio.so.10 (0x00007bb5d9e00000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007bb5dae73000)
	libgfortran.so.5 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libgfortran.so.5 (0x00007bb5da45b000)
	libfftw3.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libfftw3.so.3 (0x00007bb5d9a00000)
	libopenblas.so.0 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././libopenblas.so.0 (0x00007bb5d7600000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007bb5dae6c000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007bb5dae67000)
	/lib64/ld-linux-x86-64.so.2 (0x00007bb5dcc50000)
	libreadline.so.8 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././libreadline.so.8 (0x00007bb5da93c000)
	libcurl.so.4 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././libcurl.so.4 (0x00007bb5da14f000)
	libz.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././libz.so.1 (0x00007bb5dae4a000)
	libquadmath.so.0 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././libquadmath.so.0 (0x00007bb5dae12000)
	libtinfo.so.6 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libtinfo.so.6 (0x00007bb5da417000)
	libnghttp2.so.14 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libnghttp2.so.14 (0x00007bb5da90e000)
	libssh2.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libssh2.so.1 (0x00007bb5d9dbb000)
	libssl.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libssl.so.3 (0x00007bb5d9d18000)
	libcrypto.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libcrypto.so.3 (0x00007bb5d7000000)
	libgssapi_krb5.so.2 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libgssapi_krb5.so.2 (0x00007bb5d9cc6000)
	libzstd.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../.././././libzstd.so.1 (0x00007bb5d98ec000)
	libkrb5.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././././libkrb5.so.3 (0x00007bb5d7529000)
	libk5crypto.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././././libk5crypto.so.3 (0x00007bb5da136000)
	libcom_err.so.3 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././././libcom_err.so.3 (0x00007bb5da411000)
	libkrb5support.so.0 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././././libkrb5support.so.0 (0x00007bb5da127000)
	libkeyutils.so.1 => /home/dburke/micromamba/envs/ciao417/lib/python3.11/site-packages/sherpa/./astro/xspec/../../../../../././././libkeyutils.so.1 (0x00007bb5da120000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007bb5d9cb3000)

With this build I get

	linux-vdso.so.1 (0x00007ffd68f85000)
	/home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/libXSFunctions.so (0x000073afe4200000)
	/home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/libXSUtil.so (0x000073afe40c2000)
	/home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/libXS.so (0x000073afe595a000)
	libstdc++.so.6 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/libstdc++.so.6 (0x000073afe3ee0000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000073afe3df7000)
	libgcc_s.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/libgcc_s.so.1 (0x000073afe3dd8000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000073afe3a00000)
	libwcs-8.2.1.so => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libwcs-8.2.1.so (0x000073afe3c5f000)
	libhdsp_6.33.so => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libhdsp_6.33.so (0x000073afe3812000)
	libhdutils_6.33.so => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libhdutils_6.33.so (0x000073afe5939000)
	libfgsl.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libfgsl.so.1 (0x000073afe3795000)
	libgsl.so.25 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libgsl.so.25 (0x000073afe3400000)
	libCCfits_2.6.so => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libCCfits_2.6.so (0x000073afe3000000)
	libcfitsio.so.10 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libcfitsio.so.10 (0x000073afe2c00000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x000073afe3c5a000)
	libgfortran.so.5 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libgfortran.so.5 (0x000073afe325b000)
	libfftw3.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libfftw3.so.3 (0x000073afe2800000)
	libopenblas.so.0 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libopenblas.so.0 (0x000073afe0000000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x000073afe3c53000)
	libreadline.so.8 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./libreadline.so.8 (0x000073afe373c000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x000073afe3c4c000)
	/lib64/ld-linux-x86-64.so.2 (0x000073afe5a1e000)
	libz.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././libz.so.1 (0x000073afe3c31000)
	libcurl.so.4 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././libcurl.so.4 (0x000073afe2b2f000)
	libbz2.so.1.0 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././libbz2.so.1.0 (0x000073afe3c1d000)
	libquadmath.so.0 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././libquadmath.so.0 (0x000073afe3223000)
	libtinfo.so.6 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././libtinfo.so.6 (0x000073afe2fbd000)
	libnghttp2.so.14 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libnghttp2.so.14 (0x000073afe3710000)
	libssh2.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libssh2.so.1 (0x000073afe2f6f000)
	libssl.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libssl.so.3 (0x000073afe2a3d000)
	libcrypto.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libcrypto.so.3 (0x000073afdfa00000)
	libgssapi_krb5.so.2 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libgssapi_krb5.so.2 (0x000073afe27ad000)
	libzstd.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/./././libzstd.so.1 (0x000073afe2694000)
	libkrb5.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././././libkrb5.so.3 (0x000073afdf92a000)
	libk5crypto.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././././libk5crypto.so.3 (0x000073afe2f57000)
	libcom_err.so.3 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././././libcom_err.so.3 (0x000073afe370a000)
	libkrb5support.so.0 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././././libkrb5support.so.0 (0x000073afe3215000)
	libkeyutils.so.1 => /home/dburke/micromamba/envs/sherpa-xspec/spectral/../lib/././././libkeyutils.so.1 (0x000073afe2f50000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x000073afe2f3d000)

The obvious changes is that the libXS*.so files are not "named"; they just sit there, lurking in the "new" version. There may be others (as I keep on confusing myself).

Changes

In the following I use "meson backend" rather blithely, when technically I should say "meson-python backend".

Why?

So, we do not need to do this, but the existing setuptools build is difficult to reason about. As changes have been made to the python packaging standards and tooling, it has been somewhat of a game of whack-a-mole to try to fix issues. Moving to a different build backend (in this case meson) is not guaranteed to be immune from this, but it does give us a chance at a clean slate. There are also some technical improvements - the main one being the improved support for parallel builds, but the editable "no isolation" build is probably better-handled with the meson backend rather than setuptools.

How to build

Python must be available as python3 (it can also be accessible via python, but python3 is used to handle setting the version in the top-level meson.build file).

Installation

% pip install .

Editable install

% pip install meson-python ninja numpy
% pip install -e . --no-build-isolation

You can build without the --no-build-isolation flat but then I found things like sherpa_test didn't work, and I am not convinced the "do not rebuild stuff that we don't need rebuilding" works as well).

Build

I have managed

% pip install build
% python -m build

but have only done limited testing.

Build configuration

The setuptools approach is to set the build options (essentially, what compiled extensions are to be built and how to do it) are in the setup.cfg file. This file is changed by the user before building Sherpa.

The meson approach appears to be

  • define the options, and their default values, in a top level meson.options file
  • pass the options in to the build command

For python, this equates to lines like

% pip install . --verbose -Csetup-args=-Dxspec-prefix=$HEADAS/.." -Csetup-args=-Dxspec-libraries=XSFunctions,XSUtil,XS
% pip install . --verbose -Csetup-args=-Dxspec-prefix=$ASCDS_INSTALL -Csetup-args=-Dxspec-libraries=XSFunctions,XSUtil,XS -Csetup-args=-Dbuild-group=false -Csetup-args=-Dbuild-stk=false -Csetup-args=-Dbuild-region=false -Csetup-args=-Dregion-prefix=$ASCDS_INSTALL -Csetup-args=-Dbuild-wcssubs=false -Csetup-args=-Dwcssubs-prefix=$ASCDS_INSTALL

I don't think there's a way to have the equivalent of setup.cfg - that is, set the options in a file that gets picked up by the build.

The "-C" option seems to be the way to send these arguments to whatever build tool you are using (although it may depend on the tool). I have been able to say

% python -m build -Csetup-args=-Dbuild-wcssubs=false

Build options

As the configuration system has changed, we have the chance to potentially simplify and standardize the build options. Of course, it's only standardized "up to a point" (that point being the naming of xspec), but let's see.

existing options

I do not think that the build_sphinx section is relevant, but I forget exactly what picks this up.

% cat setup.cfg 
[sherpa_config]

# Directory where the external dependencies must be installed.
#install_dir=build

# Additional configure flags for building extern dependencies
# Set to 'None' (without quotes) to just override the default flags
#configure=None

# GROUP Python module
#disable-group=True
#group-location=build/lib/python2.7/site-packages/group.so

# Additional flags to be passed to libgrp build
#group-cflags=

# File Stack Python module
#disable-stk=True
#stk-location=build/lib/python2.7/site-packages/stk.so

# FFTW Library
# Uncomment to use a local installation
#fftw=local

# If fftw=local uncomment the following lines and
# change the default location of libraries and the name
# of the library to be linked (usually fftw3)
# (include multiple values by separating them with spaces)
#fftw-include_dirs=build/include
#fftw-lib-dirs=build/lib
#fftw-libraries=fftw3

# Region Library
# Uncomment to use a local installation
#region=local

# If region=local uncomment the following lines and
# change the default location of libraries and headers and the name
# of the library to be linked (usually region)
# (include multiple values by separating them with spaces)
#region-include_dirs=build/include
#region-lib-dirs=build/lib
#region-libraries=region
#
# Should the CXC Data Model parser be used? This enables FITS region
# files but requires the CXC Data Model code is available. If set
# then ascdm should be added to region-libraries and ensure
# that ascdm.h/ascdm.so are added to the region-include-dirs
# and region-lib-dirs directories.
#region-use-cxc-parser=False

# WCS Subroutines
# Uncomment to use a local installation
#wcs=local

# Uncomment and change default location if needed
#wcs-include-dirs=build/include
#wcs-lib-dirs=build/lib
#wcs-libraries=wcs


[build_sphinx]
source-dir = docs


# XSPEC Models
[xspec_config]
# Uncomment (set to True) to build XSPEC extension
#with-xspec=True

# If with-xspec is True, make sure to point Sherpa to right
# XSPEC-related libraries and to indicate the XSPEC version.
#
# The xspec_include_dirs and xspec_lib_dirs items should be set
# to $HEADAS/include and $HEADAS/lib respectively (expand out the
# environment variable).
#
# If you are using a full XSPEC build, then it may be necessary to add
# the correct version numbers to the cfitsio, CCfits, and wcs
# libraries used in the build. For XSPEC 12.12.1 (HEAsoft 6.30.1)
# this means using CCfits_2.6, wcs-7.7, and hdsp_6.30.
#
# If you are using the models-only XSPEC build, then the cfitsio_lib_dirs,
# ccfits_lib_dirs, and wcslib_lib_dirs will need to be set if
# these libraries are installed in a different location to the XSPEC
# libraries.
#
# The gfortran_lib_dirs should be set if needed.
#
#xspec_version = 12.12.0
#xspec_lib_dirs = None
#xspec_include_dirs = None
#xspec_libraries = XSFunctions XSUtil XS hdsp_6.30  # change 6.30 to the correct version
#cfitsio_lib_dirs = None
#cfitsio_libraries = cfitsio
#ccfits_lib_dirs = None
#ccfits_libraries = CCfits
#wcslib_lib_dirs = None
#wcslib_libraries = wcs
#gfortran_lib_dirs = None
#gfortran_libraries = gfortran

proposed options

option('build-group', type: 'boolean', value: true,
       description: 'Is the group module built? CIAO users should ' +
       'set this to false.')
option('build-stk', type: 'boolean', value: true,
       description: 'Is the stack module built? CIAO users should ' +
       'set this to false.')

option('build-region', type: 'boolean', value: true,
       description: 'Is the region support code built? CIAO users ' +
       'should set this to false and set the region-prefix option.')
option('region-prefix', type: 'string', value: '',
       description: 'Location of include/ and lib/ directories for ' +
       'the region library. CIAO users should set this to ' +
       '$ASCDS_INSTALL. Only used if build-region is false.')
option('region-use-cxc-parser', type: 'boolean', value: true,
       description: 'Is the CXC Data Model parser used? Only used ' +
       'if region-prefix is set.')

option('build-wcssubs', type: 'boolean', value: true,
       description: 'Is the wcssubs support module built? CIAO users ' +
       'should set this to false and set the wcssubs-prefix option.')
option('wcssubs-prefix', type: 'string', value: '',
       description: 'Location of include/ and lib/ directories for ' +
       'the wcssubs library. CIAO users should set this to ' +
       '$ASCDS_INSTALL. Only used if build-wcssubs is false.')

option('build-fftw3', type: 'boolean', value: false,
       description: 'Is the FFTW3 support module built? This should only ' +
       'be set if you are unable to install FFTW3 through some other ' +
       'means. DOES NOT WORK WHEN SET')

option('xspec-prefix', type: 'string', value: '',
       description: 'Location of include/ and lib/ directories for ' +
       'the wcssubs library. This is expected to be set to $HEADAS.')
option('xspec-libraries', type: 'array',
       value: ['XSFunctions', 'XSUtil', 'XS', 'hdsp_6.33', 'CCfits_2.6', 'wcs-8.2.1'],
       description: 'The XSPEC libraries that should be linked to. ' +
       'The value depends on the version of the XSPEC library and ' +
       'how it was built.')

Changes

I have tried to use the build-<name> option as the "gate". This is easy forstk and group since we

  • build it (set to true)

  • do not build it (set to false) which covers

    • we are using CIAO so the modules already exist
    • we are not using CIAO and so the user will not have access to this functionality
  • QUESTION do we need to be more explicit about the difference of "will pick up from CIAO" versus "we do not want". I don't think so since we can not know what is in the user's environment, i.e. we can not explicitly say "there is no stk module". However, there is the next item.

Building the region and wcssubs code is a bit trickier since we can take the code from CIAO, but we still need to build something. If you set the build-region or build-wcssubs to false and then do not set the <name>-prefix option (that is, leave it as the empty string) then the code will not build: this is slightly indirect, but it's the best I could come up with, other than perhaps making build-region/wcssubs take an enumeration rather than a boolean (e.g. something like "build", "nobuild", "buildifyoulike").

  • QUESTION in this case saying "I do not need wcssubs or region" feels a little-bit less clear. It can be documented, but is there a better option. Meson has a "feature" option which kind-of maps to this, but I don't think fully maps to what we want.

So, I have made the assumption that we don't need to give separate "install" and "lib" locations when specifying the location of a library; instead you give the "prefix" with the <libname>-prefix option and the install/lib locations are assumed to be this prefix + "/install" or + "/lib". This does limit functionality, but I don't think we need to concern ourselves with people who have the install and lib directories in different places.

This is particularly noticeable for the XSPEC case, where I just assume that all the related projects (e.g. ccfits and the like) are all located in the same place.

For the region code, I have avoided the need for explicitly specifying the ascdm module, as this is subsumed into the ungainly region-use-cxc-parser option, and this is the default (since the assumption is that if you are building with an external region library then you are using the CIAO build).

For XSPEC we have complications since we need the XSPEC version and HEADAS location, as well as the build libraries. We could separate out "actual XSPEC libraries" - so XSFunction', XSUtil, XS - from others (e.g. CCfits), but I think for now it's easier just to have one list that gets sent in.

  • QUESTION for libraries that require a version, such as hdsp_6.30, we could automate finding them (via a script) so that we could label it as hdsp_X say and then this would be found. However, whilst we require the XSPEC version I'm not sure it's worth it. We really need a pkg-config-like system for XSPEC, but that's a different conversation!

I have simplified the options, since we now try to work out the XSPEC version from the installed library rather than have the user say "use this version". There is an argument to say we should be explicit rather than implicit, but I am not sure we want to be that explicit.

@DougBurke

Copy link
Copy Markdown
Contributor Author

Rebased now that 4.17.0 has been released (to pick up a number of build changes and some of the fixes that were orignially created for this PR but then git merged in other PRs).

@DougBurke

Copy link
Copy Markdown
Contributor Author

Rebased as I've made some progress on providing optional support (and removing some hard-coded assumptions), but still a long way to go.

@DougBurke
DougBurke force-pushed the test-mesonpy branch 14 times, most recently from 921fb0d to e5bc5b7 Compare February 28, 2025 16:05
@codecov

codecov Bot commented Feb 28, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.54%. Comparing base (1f164b7) to head (f9764d3).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1948      +/-   ##
==========================================
+ Coverage   87.50%   87.54%   +0.03%     
==========================================
  Files          84       84              
  Lines       29957    29954       -3     
  Branches     3832     3832              
==========================================
+ Hits        26213    26222       +9     
+ Misses       3634     3622      -12     
  Partials      110      110              
Files with missing lines Coverage Δ
sherpa/conftest.py 93.45% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f164b7...f9764d3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DougBurke DougBurke changed the title Test mesonpy WIP Switch the build system to meson Feb 28, 2025
@DougBurke DougBurke linked an issue Mar 1, 2025 that may be closed by this pull request
@eli-schwartz

Copy link
Copy Markdown

For python, this equates to lines like

% pip install . --verbose -Csetup-args="-Dbuild-xspec=true" -Csetup-args="-Dbuild-xspec-location=$HEADAS/.." -Csetup-args=-Dbuild-xspec-libraries=XSFunctions,XSUtil,XS
% pip install . --verbose -Csetup-args=-Dbuild-xspec=true -Csetup-args=-Dbuild-xspec-location=$ASCDS_INSTALL -Csetup-args=-Dbuild-xspec-libraries=XSFunctions,XSUtil,XS -Csetup-args=-Dbuild-grplib=false -Csetup-args=-Dbuild-stklib=false -Csetup-args=-Dbuild-region=false -Csetup-args=-Dregion-install=$ASCDS_INSTALL -Csetup-args=-Dregion-use-cxc-parser=true -Csetup-args=-Dbuild-wcssubs=false -Csetup-args=-Dwcssubs-install=$ASCDS_INSTALL

This may help: https://mesonbuild.com/Machine-files.html

You can specify project options as well as which program binaries to use for things like the C/C++ compiler, pkg-config paths, etc.

(Sorry, can't take a closer look at the meson.build changes right now -- the files changed tab is so big it grinds my browser to a halt.)

DougBurke and others added 6 commits June 2, 2025 11:07
Change the location of the conda environment from within
the sherpa source directory - as given by the github.workspace
value - to its parent directory.

This turns out to be important if we change to a different
build system, such as meson-python [1]. It also seems to make
sense anyway; that is, make sure the condea environment is
separate from the Sherpa code.

I also apply this for the MacOS SDK location, for similar reasons.

Two questions are

a) is the parent directory a sensible location; I can't see why not
b) is there a better way to identify this location (or, some other
   location, following point a) as at present I just hard-code this
   into the yaml as "${{ github.workspace }}/../<value>"
   and also in setup_conda.sh for the macOS code (the macOS SDK)

---

[1] For example

rgommers/scipy#82 (comment)
Ensure that FFTW3 is available on the CI machines (this does not
set the code up to build against these libraries).
With this I can

    pip install .

and then in another directory

    sherpa_test -n auto

Editable installs must use

    pip install -e . --no-build-isolation

which requires that meson, meson-python, ninja, and numpy are
installed in the user's environment.

There is some support for building optional code, but

- FFTW currently requires that it is provided by an external
  entity as updating the local build to meson is currently
  above my pay grade

The extern/ code has been moved to subprojects/ since it feels
like using the meson subproject support makes sense here.
However, this is just a vibe and I may change my mind. Several
thoughts:

- I haven't removed/cleaned up the existing configure support
- although they are labelled subproject, the build is very
  tailored to Sherpa's needs (which may suggest going back to
  just make them part of the general build)
- however, this way we can get per-subproject C standard
  support, such as wcssubs needing -std=g<v> rather than -std=c<v>
- labelling of the subproject directory: do we want to keep the
  version number or not

The editable build now requires the --no-build-isolation flag,
which complicates the build somewhat (as we need to ensure we have
the build components). There are definite improvements when
built like this (I was able to change the code for an extension
module and then the pytest call picked up this change and compiled
just the needed code).

The existing setuptools code has also not been removed.

Initial documentation support has been added, but more is likely
needed.

Version support is incomplete (e.g. the replacement for
sherpa/_version.py and its interactions with the docs build).
There is an assumption that the python3 executable is available,
but this does seem to cause problems with some editable build
changes.
I was getting worried about my understanding of things until I
found

mesonbuild/meson-python#646

which explained why the "tests of the tests" fail here.

So, for now we try to fake the pytest assert and hope it's
somewhat similar (at some level any assertion message is
"nice to have" but I have been in cases where you get a failure
but no information on what actually failed and it is annoying).
This is based on PR sherpa#2220.

It tries to do a full - except for XSPEC and DS9 - build and
test.
This information can be imputed. But let us not impute!
@DougBurke

Copy link
Copy Markdown
Contributor Author

Rebased to addres merge conflicts.

@DougBurke

DougBurke commented Jun 2, 2025 •

Copy link
Copy Markdown
Contributor Author

So, the test_abund_get_invalid_element_table test crashes the system on macOS ARM. That's nice. It also may not be from that test as a number of XSPEC tests have already been run, but gives me a place to start looking.

EDITED TO ADD However, given that these tests run on main/elsewhere, it suggests that the code is not problematic, but maybe the build instructions are?

@DougBurke

Copy link
Copy Markdown
Contributor Author

Replaced by #2484

@DougBurke DougBurke closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updating to a modern build system

2 participants