Skip to content

Commit

Permalink
Add stacklevel to warnings
Browse files Browse the repository at this point in the history
Make it easier to find out where warnings originate from.
  • Loading branch information
dweindl committed May 2, 2024
1 parent 6b05ddd commit 265fe3b
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/sdist/amici/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def get_logger(
elif kwargs:
warnings.warn(
"AMICI logger already exists, ignoring keyword "
"arguments to setup_logger"
"arguments to setup_logger",
stacklevel=2,
)

logger = logging.getLogger(logger_name)
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
warnings.warn(
"Importing amici.parameter_mapping is deprecated. Use `amici.petab.parameter_mapping` instead.",
DeprecationWarning,
stacklevel=2,
)

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def fill_in_parameters(
"The following problem parameters were not used: "
+ str(unused_parameters),
RuntimeWarning,
stacklevel=2,
)

for edata, mapping_for_condition in zip(
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
warnings.warn(
"Importing amici.petab_import is deprecated. Use `amici.petab` instead.",
DeprecationWarning,
stacklevel=2,
)

from .petab.import_helpers import ( # noqa # pylint: disable=unused-import
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab_import_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
warnings.warn(
"Importing amici.petab_import_pysb is deprecated. Use `amici.petab.pysb_import` instead.",
DeprecationWarning,
stacklevel=2,
)

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
warnings.warn(
f"Importing {__name__} is deprecated. Use `amici.petab.simulations` instead.",
DeprecationWarning,
stacklevel=2,
)

from .petab.conditions import fill_in_parameters # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
warnings.warn(
f"Importing {__name__} is deprecated. Use `amici.petab.simulator` instead.",
DeprecationWarning,
stacklevel=2,
)

from .petab.simulator import PetabSimulator # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/petab_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
warnings.warn(
f"Importing {__name__} is deprecated. Use `amici.petab.util` instead.",
DeprecationWarning,
stacklevel=2,
)

__all__ = [
Expand Down
3 changes: 2 additions & 1 deletion python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def sbml2amici(
if not has_clibs:
warnings.warn(
"AMICI C++ extensions have not been built. "
"Generated model code, but unable to compile."
"Generated model code, but unable to compile.",
stacklevel=2,
)
exporter.compile_model()

Expand Down

0 comments on commit 265fe3b

Please sign in to comment.