-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from DougBurke/add-macos-testing
Add macos testing
- Loading branch information
Showing
8 changed files
with
386 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.