From 75f9185b85df0a821e26d07715d840913272d86a Mon Sep 17 00:00:00 2001 From: Douglas Burke Date: Tue, 8 Oct 2024 08:55:11 -0400 Subject: [PATCH] Add get_include_path While we could make users use importlib.resources.files manually, it is annoying, so provide a helper routine (this is based on the logic we use in Sherpa). --- CHANGELOG.md | 5 +++++ template/__init__.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5775781..7981cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ from the refactoring done in 0.0.30, and move the include directory into xspec_models_cxc/ so it is more-obvious why is is installed (although it probably should be done more as some form of a data-file). +The module has gained the get_include_path() routine to provide access +to the include file, which will hopefully be needed to support access +to XSPEC user models (I have got this working for Sherpa so we should +be able to do something similar here). + ## 0.0.30 Potential build improvements, including support for using the CXC diff --git a/template/__init__.py b/template/__init__.py index 93e3e98..5a05ba7 100644 --- a/template/__init__.py +++ b/template/__init__.py @@ -8,7 +8,7 @@ The XSPEC model library is automatically initialized when the first call is made, and not when the module is loaded. -There are three types of symbols in this package: +There are four types of symbols in this package: 1. model functions, such as `apec` and `TBabs`, and `tableModel` for table models. @@ -16,6 +16,7 @@ table (`abundance`), cross-section table (`cross_sections`), cosmology (`cosmology`), and the chatter level (`chatter`). 3. routines about the models: `info` and `list_models`. +4. routines about the API: `get_include_path`. Examples -------- @@ -131,7 +132,9 @@ from dataclasses import dataclass from enum import Enum, auto +from importlib import resources import logging +from pathlib import Path from typing import List, Optional, Sequence try: @@ -324,3 +327,10 @@ def list_models(modeltype: Optional[ModelType] = None, out.add(k) return sorted(out) + + +def get_include_path() -> Path: + """Return the location of the C++ include file.""" + + path = resources.files("xspec_models_cxc.include") + return path / "xspec_models_cxc.hh"