Open wangyinz opened 2 weeks ago
That makes sense. I'll need some help on how to set up CMake to do that but the C++ change should be simple. I think the MsPASS _HOME functionality should still be retained but is the final fallback if all else fails.
I need to further refine this idea. It is tricky to do it right actually. I was just writing down my thought above as a memo.
In any case, I agree the MSPASS_HOME
should be kept, but we should just follow the logic of the python code: when MSPASS_HOME
is defined, we use that, and if it is not, we try the relative path.
Right now, in our C++ code, we rely on the following function to determine the default directory for the parameter files: https://github.com/mspass-team/mspass/blob/bf7e2f05609888b56a238095ff2aa3527e304694/cxx/src/lib/utility/data_directory.cc#L7 Basically, a
MSPASS_HOME
environment variable needs to be set for any of those C++ code to work.In the Python code, such requirement is avoided by the following constructs: https://github.com/mspass-team/mspass/blob/bf7e2f05609888b56a238095ff2aa3527e304694/python/mspasspy/db/schema.py#L17-L26 Because we always install the
data
directory with the Python package, we can use__file__
(which is the pathname of the file from which the running Python module was loaded) to locate the relative path to thedata
directory .I should also note that there are Python codes that didn't use this robust method: https://github.com/mspass-team/mspass/blob/bf7e2f05609888b56a238095ff2aa3527e304694/python/mspasspy/preprocessing/css30/datascope.py#L87-L95
Now, I think we should improve the C++ code such that it is not necessary to define
MSPASS_HOME
especially when it is compiled and installed as a Python modules. This can be done by using CMake to set a variable to tell the code that it is being built as a Python module. Then, CMake can also set a global variable to code in the relative path to the data directory within the python installed directory.