Skip to content

Commit 339d1e7

Browse files
authored
Merge pull request #3633 from jsiirola/default-pyomo-log-handler
Fix `capture_output` management of logger file descriptors
2 parents dc503c2 + 1922d28 commit 339d1e7

File tree

13 files changed

+145
-45
lines changed

13 files changed

+145
-45
lines changed

doc/OnlineDocs/_templates/recursive-base.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# import everything from the module containing this class so that
88
# doctests for the class docstrings see the correct environment
99
from {{ module }} import *
10+
try:
11+
from {{ module }} import _autosummary_doctest_setup
12+
_autosummary_doctest_setup()
13+
except ImportError:
14+
pass
1015

1116
.. currentmodule:: {{ module }}
1217

doc/OnlineDocs/_templates/recursive-class.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# import everything from the module containing this class so that
88
# doctests for the class docstrings see the correct environment
99
from {{ module }} import *
10+
try:
11+
from {{ module }} import _autosummary_doctest_setup
12+
_autosummary_doctest_setup()
13+
except ImportError:
14+
pass
1015

1116
.. currentmodule:: {{ module }}
1217

doc/OnlineDocs/_templates/recursive-enum.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# import everything from the module containing this class so that
88
# doctests for the class docstrings see the correct environment
99
from {{ module }} import *
10+
try:
11+
from {{ module }} import _autosummary_doctest_setup
12+
_autosummary_doctest_setup()
13+
except ImportError:
14+
pass
1015

1116
.. currentmodule:: {{ module }}
1217

doc/OnlineDocs/_templates/recursive-module.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ Library Reference
55
{{ name | escape | underline}}
66
{% endif %}
77

8+
.. testsetup:: *
9+
10+
# import everything from the module containing this class so that
11+
# doctests for the class docstrings see the correct environment
12+
from {{ module }} import *
13+
try:
14+
from {{ module }} import _autosummary_doctest_setup
15+
_autosummary_doctest_setup()
16+
except ImportError:
17+
pass
18+
19+
.. currentmodule:: {{ module }}
20+
821
.. automodule:: {{ fullname }}
922
:undoc-members:
1023

doc/OnlineDocs/errors.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ Common Warnings/Errors
88
for backwards compatibility, DO NOT recycle old ID (no longer used)
99
numbers.
1010
11-
.. doctest::
12-
:hide:
11+
.. testsetup::
1312

14-
>>> import pyomo.environ as pyo
13+
import pyomo.environ as pyo
14+
# Ensure that all logged messages are sent to stdout
15+
# (so they show up in the doctest output and can be tested)
16+
import pyomo.common.log as _log
17+
_log.pyomo_handler.__class__ = _log.StdoutHandler
1518

1619
.. py:currentmodule:: pyomo.environ
1720

doc/OnlineDocs/explanation/developer_utils/deprecation.rst

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,29 @@ Deprecation
99
-----------
1010

1111
We offer a set of tools to help with deprecation in
12-
``pyomo.common.deprecation``.
12+
:py:mod:`pyomo.common.deprecation`.
1313

1414
By policy, when deprecating or moving an existing capability, one of the
1515
following utilities should be leveraged. Each has a required
1616
``version`` argument that should be set to current development version (e.g.,
1717
``"6.6.2.dev0"``). This version will be updated to the next actual
1818
release as part of the Pyomo release process. The current development version
19-
can be found by running ``pyomo --version`` on your local fork/branch.
19+
can be found by running
20+
21+
``pyomo --version``
22+
23+
on your local fork/branch.
2024

2125
.. currentmodule:: pyomo.common.deprecation
2226

2327
.. autosummary::
2428

2529
deprecated
2630
deprecation_warning
27-
relocated_module
31+
moved_module
2832
relocated_module_attribute
2933
RenamedClass
3034

31-
.. autodecorator:: pyomo.common.deprecation.deprecated
32-
:noindex:
33-
34-
.. autofunction:: pyomo.common.deprecation.deprecation_warning
35-
:noindex:
36-
37-
.. autofunction:: pyomo.common.deprecation.relocated_module
38-
:noindex:
39-
40-
.. autofunction:: pyomo.common.deprecation.relocated_module_attribute
41-
:noindex:
42-
43-
.. autoclass:: pyomo.common.deprecation.RenamedClass
44-
:noindex:
45-
4635

4736
Removal
4837
-------
@@ -52,10 +41,8 @@ warning, pending extenuating circumstances. The functionality should
5241
be deprecated, following the information above.
5342

5443
If the functionality is documented in the most recent
55-
edition of [`Pyomo - Optimization Modeling in Python`_], it may not be removed
56-
until the next major version release.
57-
58-
.. _Pyomo - Optimization Modeling in Python: https://doi.org/10.1007/978-3-030-68928-5
44+
edition of :ref:`Pyomo - Optimization Modeling in Python <pyomobookiii>`,
45+
it may not be removed until the next major version release.
5946

6047
For other functionality, it is preferred that ample time is given
6148
before removing the functionality. At minimum, significant functionality

doc/OnlineDocs/explanation/solvers/pynumero/tutorial.linear_solver_interfaces.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Interface to MA27
4242
>>> status = solver.do_numeric_factorization(A)
4343
>>> x, status = solver.do_back_solve(rhs)
4444
>>> np.max(np.abs(A*x - rhs)) <= 1e-15
45-
True
45+
np.True_
4646

4747

4848
Interface to MUMPS

doc/OnlineDocs/reference/bibliography.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ These publications describe various Pyomo capabilitites or subpackages:
2929
Vol. 67. Springer. 2021. DOI `10.1007/978-3-030-68928-5
3030
<https://doi.org/10.1007/978-3-030-68928-5>`_
3131
32+
..
33+
NOTE: When adding a new edition of the Pyomo Book, search the codebase
34+
both for citation references "[PyomoBookIII]" and references "pyomobookiii"
35+
3236
.. [PyomoDAE-paper] Bethany Nicholson, John D. Siirola, Jean-Paul Watson,
3337
Victor M. Zavala, and Lorenz T. Biegler. "pyomo.dae: a modeling and
3438
automatic discretization framework for optimization with differential
@@ -126,7 +130,7 @@ Bibliography
126130
127131
.. [RB01] W. C. Rooney and L. T. Biegler. "Design for model parameter
128132
uncertainty using nonlinear confidence regions", *AIChE Journal*,
129-
47(8). 2001.
133+
47(8). 2001. DOI `10.1002/aic.690470811 <https://doi.org/10.1002/aic.690470811>`_
130134
131135
.. [RG94] R. Raman and I. E. Grossmann. "Modelling and computational
132136
techniques for logic based integer programming", *Computers and

pyomo/common/dependencies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ def declare_deferred_modules_as_importable(globals_dict):
856856
... 'scipy', callback=_finalize_scipy,
857857
... deferred_submodules=['stats', 'sparse', 'spatial', 'integrate'])
858858
>>> declare_deferred_modules_as_importable(globals())
859-
WARNING: DEPRECATED: ...
860859
861860
Which enables users to use:
862861

pyomo/common/deprecation.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
_doc_flag = '.. deprecated::'
3737

3838

39+
def _autosummary_doctest_setup():
40+
"""This function gets called to setup the doctest environment before
41+
running any autosummary doctests in this module.
42+
"""
43+
44+
# Ensure that all logged messages are sent to stdout
45+
# (so they show up in the doctest output and can be tested)
46+
import pyomo.common.log as _log
47+
48+
_log.pyomo_handler.__class__ = _log.StdoutHandler
49+
50+
3951
def default_deprecation_msg(obj, user_msg, version, remove_in):
4052
"""Generate the default deprecation message.
4153
@@ -157,7 +169,7 @@ def _find_calling_frame(module_offset):
157169
def deprecation_warning(
158170
msg, logger=None, version=None, remove_in=None, calling_frame=None
159171
):
160-
"""Standardized formatter for deprecation warnings
172+
"""Standardized function for formatting and emitting deprecation warnings.
161173
162174
This is a standardized routine for formatting deprecation warnings
163175
so that things look consistent and "nice".

0 commit comments

Comments
 (0)