Skip to content

Commit

Permalink
Merge pull request #26 from DougBurke/add-macos-testing
Browse files Browse the repository at this point in the history
Add macos testing
  • Loading branch information
DougBurke authored Oct 7, 2024
2 parents 33338a2 + c445643 commit f06a62b
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 205 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ci-ciao-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ jobs:
strategy:
matrix:
include:
- name: Linux Minimum Setup (Python 3.12)
- name: Linux (Python 3.12)
os: ubuntu-latest
python-version: 3.12
xspec-version: 12.14.0i
xspec-channel: https://cxc.cfa.harvard.edu/conda/xspec
conda-compilers: "gcc_linux-64 gxx_linux-64 gfortran_linux-64"

- name: macOS ARM (Python 3.12)
os: macos-latest
python-version: 3.12
xspec-version: 12.13.1e
xspec-channel: https://cxc.cfa.harvard.edu/conda/ciao
conda-compilers: "clang_osx-arm64 clangxx_osx-arm64 gfortran_osx-arm64"

steps:
- name: Checkout Code
Expand All @@ -50,8 +59,10 @@ jobs:
env:
PYTHONVER: ${{ matrix.python-version }}
XSPECVER: ${{ matrix.xspec-version }}
XSPECCHAN: ${{ matrix.xspec-channel }}
COMPILERS: ${{ matrix.conda-compilers }}
run: |
conda create --yes -n build -c conda-forge -c https://cxc.cfa.harvard.edu/conda/xspec "python=$PYTHONVER" "xspec-modelsonly=$XSPECVER"
conda create --yes -n build -c conda-forge -c $XSPECCHAN "python=$PYTHONVER" "xspec-modelsonly=$XSPECVER" $COMPILERS
- name: Install
run: |
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
*~
build/
*.egg-info/
src/xspec_models_cxc/_compiled.*.so
src/xspec_models_cxc/__init__.py
__pycache__

src/xspec.cxx
src/xspec_models_cxc/_compiled.*.so
src/xspec_models_cxc/xspec.cxx
src/xspec_models_cxc/__init__.py

helpers/report_xspec_version
73 changes: 73 additions & 0 deletions helpers/apply_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python

# SPDX-License-Identifier: GPL-3.0-or-later

"""Process the templates to create the module files.
Usage:
./apply_templates.py modeldat xspecver outcompiled outpython
This uses the model.dat file to identify what models and parameters
are needed to create the python and C++ code. The xspecver argument
is the XSPEC version string (e.g. "12.14.1" or "12.14.1c").
"""

from pathlib import Path
import sys

# local import
import template


def doit(modeldat: str,
xspecver: str,
*,
out_python: str,
out_compiled: str
) -> None:

modelfile = Path(modeldat)
models, unsupported = template.find_models(modelfile)

template_dir = Path('template')
template_compiled = template_dir / 'xspec.cxx'
template_python = template_dir / '__init__.py'
for temp in [template_compiled, template_python]:
if not temp.is_file():
raise ValueError(f"Unable to find template: {temp}")

# Check that the directories exist. This is ugly and potentially
# dangerous.
#
outc = Path(out_compiled).resolve()
outp = Path(out_python).resolve()
for out in [outc, outp]:
if out.exists():
continue

for parent in reversed(out.parents):
if parent.is_dir():
continue

parent.mkdir()

# Create the code we want to compile
#
template.apply_compiled(models, template_compiled, outc)
template.apply_python(modelfile, models, template_python,
xspecver, outp)

template.report(models, unsupported)


if __name__ == "__main__":

if len(sys.argv) != 5:
sys.stderr.write(f"Usage: {sys.argv[0]} modeldat xspecver outcompiled outpython\n")
sys.exit(1)

doit(sys.argv[1], sys.argv[2],
out_compiled=sys.argv[3],
out_python=sys.argv[4])
47 changes: 47 additions & 0 deletions helpers/report_xspec_directories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python

# SPDX-License-Identifier: GPL-3.0-or-later

"""Return the library and include directories.
This should just be $HEADAS/lib and $HEADAS/include, except for the
fact that the CXC xspec-modelsonly conda package does things a little
differently (or, perhaps, that XSPEC doesn't have the equivalent of a
share/ directory in which to place the extra files).
It is assumed that the HEADAS environment variable exists.
"""

from pathlib import Path
import os

HEADAS_ENV = os.getenv('HEADAS')
HEADAS = Path(HEADAS_ENV)

if (HEADAS / 'include').is_dir():
base_path = HEADAS
else:
base_path = (HEADAS / '..').resolve()

xspec_libdir = base_path / 'lib'
xspec_incdir = base_path / 'include'

if not xspec_libdir.is_dir():
sys.stderr.write('###########################################\n')
sys.stderr.write('ERROR: unable to find HEADAS lib directory.\n')
sys.stderr.write(str(HEADAS / platlibdir))
sys.stderr.write(str(HEADAS / '..' / platlibdir))
sys.stderr.write('###########################################\n')
sys.exit(1)

if not xspec_incdir.is_dir():
sys.stderr.write('###########################################\n')
sys.stderr.write('ERROR: unable to find HEADAS lib directory.\n')
sys.stderr.write(str(HEADAS / 'include'))
sys.stderr.write(str(HEADAS / '..' / 'include'))
sys.stderr.write('###########################################\n')
sys.exit(1)

print(xspec_incdir)
print(xspec_libdir)
66 changes: 66 additions & 0 deletions helpers/report_xspec_libraries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python

# SPDX-License-Identifier: GPL-3.0-or-later

"""Return the library names needed to compile against XSPEC.
"""

import glob
from pathlib import Path
import os
import sys
import sysconfig


def doit(libdir: str) -> None:
"""Given the library directory, find the libraries"""

xspec_libdir = Path(libdir)

# There's some attempt to be platform independent, but
# is it worth it?
#
if sysconfig.get_config_var("WITH_DYLD"):
suffix = ".dylib"
else:
# Should this just be hard-coded?
suffix = sysconfig.get_config_var('SHLIB_SUFFIX')

# The tricky thing is that we have XSFunctions, XSUtil, and XS as
# arguments. So we can not just look for XS*, as that will match
# multiple libraries. We also don't want to include all matches to XS
# as there are a number of matches we do not need.
#
def match(name: str) -> str:
# Would it make sense to take the lib prefix from sysconfig?
head = f"lib{name}{suffix}"
ms = glob.glob(str(xspec_libdir / head))
if len(ms) == 1:
return name

head = f"lib{name}_*{suffix}"
ms = glob.glob(str(xspec_libdir / head))
if len(ms) == 1:
return Path(ms[0]).stem[3:]

head = f"lib{name}-*{suffix}"
ms = glob.glob(str(xspec_libdir / head))
if len(ms) == 1:
return Path(ms[0]).stem[3:]

raise OSError(f"Unable to find a match for lib{name}*{suffix} in {xspec_libdir}")

for libname in ["XSFunctions", "XSUtil", "XS", "hdsp",
"cfitsio", "CCfits", "wcs"]:
# Note: not all names are versioned
print(match(libname))


if __name__ == "__main__":

if len(sys.argv) != 2:
sys.stderr.write(f"Usage: {sys.argv[0]} libdir\n")
sys.exit(1)

doit(sys.argv[1])
33 changes: 33 additions & 0 deletions helpers/report_xspec_modelfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

# SPDX-License-Identifier: GPL-3.0-or-later

"""Return the location of the XSPEC model.dat file.
"""

from pathlib import Path
import os
import sys

HEADAS_ENV = os.getenv('HEADAS')
if HEADAS_ENV is None:
sys.stderr.write('##################################################\n')
sys.stderr.write('ERROR: unable to find HEADAS environment variable.\n')
sys.stderr.write('##################################################\n')
sys.exit(1)

HEADAS = Path(HEADAS_ENV)

modelfile = HEADAS / '../spectral/manager/model.dat'
modelfile = modelfile.resolve()

if not modelfile.is_file():
sys.stderr.write('##################################################\n')
sys.stderr.write('ERROR: model.dat file not found:\n')
sys.stderr.write(str(modelfile) + '\n')
sys.stderr.write('##################################################\n')
sys.exit(1)

print(str(modelfile))
sys.exit(0)
Loading

0 comments on commit f06a62b

Please sign in to comment.