Skip to content

Commit

Permalink
Remove wurlitzer dependency (#2423)
Browse files Browse the repository at this point in the history
When using the Python interface, we don't rely on C(++) output anywhere anymore, and thus, we don't need wurlitzer anymore.


Closes #2409
  • Loading branch information
dweindl committed May 6, 2024
1 parent e3490d5 commit da19a55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
1 change: 0 additions & 1 deletion python/sdist/amici/setup.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_extension() -> CMakeExtension:
ext_modules=[MODEL_EXT],
packages=find_namespace_packages(),
install_requires=["amici==TPL_AMICI_VERSION"],
extras_require={"wurlitzer": ["wurlitzer"]},
python_requires=">=3.10",
package_data={},
zip_safe=False,
Expand Down
42 changes: 11 additions & 31 deletions python/sdist/amici/swig_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Convenience wrappers for the swig interface"""

import logging
import sys
import warnings
from contextlib import contextmanager, suppress
from typing import Any

import amici
Expand All @@ -30,22 +28,6 @@
"get_model_settings",
]

try:
from wurlitzer import sys_pipes
except ModuleNotFoundError:
sys_pipes = suppress


@contextmanager
def _capture_cstdout():
"""Redirect C/C++ stdout to python stdout if python stdout is redirected,
e.g. in ipython notebook"""
if sys.stdout == sys.__stdout__:
yield
else:
with sys_pipes():
yield


def runAmiciSimulation(
model: AmiciModel,
Expand Down Expand Up @@ -82,10 +64,9 @@ def runAmiciSimulation(
stacklevel=1,
)

with _capture_cstdout():
rdata = amici_swig.runAmiciSimulation(
_get_ptr(solver), _get_ptr(edata), _get_ptr(model)
)
rdata = amici_swig.runAmiciSimulation(
_get_ptr(solver), _get_ptr(edata), _get_ptr(model)
)
_log_simulation(rdata)
if solver.getReturnDataReportingMode() == amici.RDataReporting.full:
_ids_and_names_to_rdata(rdata, model)
Expand Down Expand Up @@ -124,15 +105,14 @@ def runAmiciSimulations(
stacklevel=1,
)

with _capture_cstdout():
edata_ptr_vector = amici_swig.ExpDataPtrVector(edata_list)
rdata_ptr_list = amici_swig.runAmiciSimulations(
_get_ptr(solver),
edata_ptr_vector,
_get_ptr(model),
failfast,
num_threads,
)
edata_ptr_vector = amici_swig.ExpDataPtrVector(edata_list)
rdata_ptr_list = amici_swig.runAmiciSimulations(
_get_ptr(solver),
edata_ptr_vector,
_get_ptr(model),
failfast,
num_threads,
)
for rdata in rdata_ptr_list:
_log_simulation(rdata)
if solver.getReturnDataReportingMode() == amici.RDataReporting.full:
Expand Down
1 change: 0 additions & 1 deletion python/sdist/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies = [
"python-libsbml",
"pandas>=2.0.2",
"pyarrow",
"wurlitzer",
"toposort",
"setuptools>=48",
"mpmath",
Expand Down

0 comments on commit da19a55

Please sign in to comment.