Skip to content

Commit

Permalink
Standardize use of in_testing_environment(), building_documentation()
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Aug 30, 2024
1 parent e97965f commit e6d7445
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions doc/OnlineDocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,7 @@ def check_output(self, want, got, optionflags):
asl_available = False
ma27_available = False
mumps_available = False
from pyomo.common.flags import in_testing_environment
in_testing_environment(True)
'''
9 changes: 5 additions & 4 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from types import ModuleType
from typing import List

from .deprecation import deprecated, deprecation_warning, in_testing_environment
import pyomo
from .deprecation import deprecated, deprecation_warning
from .errors import DeferredImportError

from .flags import in_testing_environment, building_documentation

SUPPRESS_DEPENDENCY_WARNINGS = False

Expand Down Expand Up @@ -240,12 +241,12 @@ def UnavailableClass(unavailable_module):

class UnavailableMeta(type):
def __getattr__(cls, name):
if 'sphinx' in sys.modules:
if building_documentation():
# If we are building documentation, avoid the
# DeferredImportError (we will still raise one if
# someone attempts to *create* an instance of this
# class)
super().__getattr__(name)
return getattr(super(), name)
raise DeferredImportError(
unavailable_module._moduleunavailable_message(
f"The class attribute '{cls.__name__}.{name}' is not available "
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def deprecation_warning(
logger.warning(msg)


if in_testing_environment():
if in_testing_environment() or building_documentation():
deprecation_warning.emitted_warnings = None
else:
deprecation_warning.emitted_warnings = set()
Expand Down
12 changes: 5 additions & 7 deletions pyomo/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@
from pyomo.version.info import releaselevel
from pyomo.common.deprecation import deprecated
from pyomo.common.fileutils import PYOMO_ROOT_DIR
from pyomo.common.flags import in_testing_environment
from pyomo.common.formatting import wrap_reStructuredText

_indentation_re = re.compile(r'\s*')

_RTD_URL = "https://pyomo.readthedocs.io/en/%s/errors.html" % (
'stable'
if (releaselevel == 'final' or 'sphinx' in sys.modules or 'Sphinx' in sys.modules)
else 'latest'
)


def RTD(_id):
_id = str(_id).lower()
assert _id[0] in 'wex'
return f"{_RTD_URL}#{_id}"
return "https://pyomo.readthedocs.io/en/%s/errors.html#%s" % (
'stable' if (releaselevel == 'final' or in_testing_environment()) else 'latest',
_id,
)


_DEBUG = logging.DEBUG
Expand Down
3 changes: 2 additions & 1 deletion pyomo/contrib/simplemodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.common.deprecation import deprecation_warning, in_testing_environment
from pyomo.common.deprecation import deprecation_warning
from pyomo.common.flags import in_testing_environment

try:
deprecation_warning(
Expand Down
3 changes: 2 additions & 1 deletion pyomo/pysp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import logging
import sys
from pyomo.common.deprecation import deprecation_warning, in_testing_environment
from pyomo.common.deprecation import deprecation_warning
from pyomo.common.flags import in_testing_environment

try:
# Warn the user
Expand Down

0 comments on commit e6d7445

Please sign in to comment.