@@ -8,10 +8,11 @@ import sysconfig
88from pathlib import Path
99
1010ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
11+ extension_path = Path(__file__).parent / f'_model_calvetti_py{ext_suffix}'
1112_model_calvetti_py = amici._module_from_path(
1213 'model_calvetti_py._model_calvetti_py' if __package__ or '.' in __name__
1314 else '_model_calvetti_py',
14- Path(__file__).parent / f'_model_calvetti_py{ext_suffix}' ,
15+ extension_path ,
1516)
1617
1718def _get_import_time():
@@ -36,6 +37,28 @@ if t_imported < t_modified:
3637
3738%module (package=" model_calvetti_py" ,moduleimport=MODULEIMPORT) model_calvetti_py
3839
40+ // store swig version
41+ %constant int SWIG_VERSION_MAJOR = (SWIG_VERSION >> 16 );
42+ %constant int SWIG_VERSION_MINOR = ((SWIG_VERSION >> 8 ) & 0xff );
43+ %constant int SWIG_VERSION_PATCH = (SWIG_VERSION & 0xff );
44+
45+ %pythoncode %{
46+ # SWIG version used to build the model extension as `(major, minor, patch)`
47+ _SWIG_VERSION = (SWIG_VERSION_MAJOR, SWIG_VERSION_MINOR, SWIG_VERSION_PATCH)
48+
49+ if (amici_swig := amici.amici ._SWIG_VERSION ) != (model_swig := _SWIG_VERSION):
50+ import warnings
51+ warnings.warn (
52+ f" SWIG version mismatch between amici ({amici_swig}) and model "
53+ f" ({model_swig}). This may lead to unexpected behavior. "
54+ " In that case, please recompile the model with swig=="
55+ f" {amici_swig[0]}.{amici_swig[1]}.{amici_swig[2]} or rebuild amici "
56+ f" with swig=={model_swig[0]}.{model_swig[1]}.{model_swig[2]}." ,
57+ RuntimeWarning,
58+ stacklevel=2 ,
59+ )
60+ %}
61+
3962%pythoncode %{
4063# the model-package __init__.py module (will be set during import )
4164_model_module = None
@@ -56,7 +79,7 @@ using namespace amici;
5679// store the time a module was imported
5780%{
5881#include < chrono>
59- static std::chrono::time_point<std::chrono::system_clock> _module_import_time;
82+ static std::chrono::time_point<std::chrono::system_clock> _module_import_time = std::chrono::system_clock::now () ;
6083
6184static double _get_import_time () {
6285 auto epoch = _module_import_time.time_since_epoch ();
@@ -67,7 +90,9 @@ static double _get_import_time() {
6790static double _get_import_time ();
6891
6992%init %{
70- _module_import_time = std::chrono::system_clock::now ();
93+ // NOTE: from SWIG 4.4.0 onwards, %init code is executed every time the
94+ // module is executed - not only on first import
95+ // This code ends up in `SWIG_mod_exec`.
7196%}
7297
7398
0 commit comments