Skip to content

Commit f760b8f

Browse files
authored
Merge branch 'Pyomo:main' into Example-seed-issue
2 parents a1c1073 + 56521be commit f760b8f

File tree

9 files changed

+84
-79
lines changed

9 files changed

+84
-79
lines changed

.github/workflows/test_branches.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ jobs:
7676
fail-fast: false
7777
matrix:
7878
os: [ubuntu-latest]
79-
python: ['3.13.3'] # FIXME: Remove specific 3.13 version once logging tests are fixed
79+
python: [3.13]
8080
other: [""]
8181
category: [""]
8282

8383
include:
8484
- os: ubuntu-latest
85-
python: '3.13.3' # FIXME: Remove specific 3.13 version once logging tests are fixed
85+
python: 3.13
8686
test_docs: 1
8787
TARGET: linux
8888
PYENV: pip

.github/workflows/test_pr_and_main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
fail-fast: false
8989
matrix:
9090
os: [ubuntu-latest, macos-latest, windows-latest]
91-
python: [ 3.9, '3.10', 3.11, 3.12, '3.13.3' ] # FIXME: Remove specific 3.13 version once logging tests are fixed
91+
python: [ 3.9, '3.10', 3.11, 3.12, 3.13 ]
9292
other: [""]
9393
category: [""]
9494

pyomo/common/download.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,20 @@ def filter_fcn(info):
440440
info.mode &= 0o755
441441
return True
442442

443+
if sys.version_info[:2] < (3, 12):
444+
tar_args = {}
445+
else:
446+
# Add a tar filter to suppress deprecation warning in Python 3.12+
447+
#
448+
# Note that starting in Python 3.14 the default is 'data',
449+
# however, this method is already filtering for many of the
450+
# things that 'data' would catch (and raise an exception
451+
# for). For backwards compatibility, we will use the more
452+
# permissive "tar" filter.
453+
tar_args = {'filter': tarfile.tar_filter}
443454
with tarfile.open(fileobj=io.BytesIO(self.retrieve_url(url))) as TAR:
444455
dest = os.path.realpath(self._fname)
445-
TAR.extractall(dest, filter(filter_fcn, TAR.getmembers()))
456+
TAR.extractall(dest, filter(filter_fcn, TAR.getmembers()), **tar_args)
446457

447458
def get_gzipped_binary_file(self, url):
448459
if self._fname is None:

pyomo/common/log.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ def is_debug_set(logger):
7373
"""
7474
if logger.manager.disable >= _DEBUG:
7575
return False
76-
_level = logger.getEffectiveLevel()
7776
# Filter out NOTSET and higher levels
78-
return _NOTSET < _level <= _DEBUG
77+
return _NOTSET < logger.getEffectiveLevel() <= _DEBUG
7978

80-
else:
79+
elif sys.version_info[:3] < (3, 13, 4):
8180
# This is inefficient (it indirectly checks effective level twice),
8281
# but is included for [as yet unknown] platforms that ONLY implement
8382
# the API documented in the logging library
@@ -86,6 +85,15 @@ def is_debug_set(logger):
8685
return False
8786
return logger.getEffectiveLevel() > _NOTSET
8887

88+
else:
89+
# Python 3.14 (and backported to python 3.13.4) changed the behavior
90+
# of isEnabledFor() so that it always returns False when called
91+
# while a log record is in flight (learned this from
92+
# https://github.com/hynek/structlog/pull/723). In newer versions
93+
# of Python, we will only rely on getEffectiveLevel().
94+
def is_debug_set(logger):
95+
return _NOTSET < logger.getEffectiveLevel() <= _DEBUG
96+
8997

9098
class WrappingFormatter(logging.Formatter):
9199
_flag = "<<!MSG!>>"
@@ -262,7 +270,7 @@ def filter(self, record):
262270
pyomo_logger = logging.getLogger('pyomo')
263271
pyomo_handler = logging.StreamHandler(sys.stdout)
264272
pyomo_formatter = LegacyPyomoFormatter(
265-
base=PYOMO_ROOT_DIR, verbosity=lambda: pyomo_logger.isEnabledFor(logging.DEBUG)
273+
base=PYOMO_ROOT_DIR, verbosity=lambda: is_debug_set(pyomo_logger)
266274
)
267275
pyomo_handler.setFormatter(pyomo_formatter)
268276
pyomo_handler.addFilter(_GlobalLogFilter())
@@ -469,7 +477,7 @@ def __enter__(self):
469477
# #3587), so we will just handle it explicitly ourselves.
470478
self.local_fd = os.dup(self.fd)
471479
self.handler.stream = os.fdopen(
472-
self.local_fd, mode="a", closefd=False
480+
self.local_fd, mode="w", closefd=False
473481
).__enter__()
474482

475483
def __exit__(self, et, ev, tb):
@@ -495,7 +503,7 @@ def __enter__(self):
495503
# #3587), so we will just handle it explicitly ourselves.
496504
self.local_fd = os.dup(self.fd)
497505
logging.lastResort = logging.StreamHandler(
498-
os.fdopen(self.local_fd, mode="a", closefd=False).__enter__()
506+
os.fdopen(self.local_fd, mode="w", closefd=False).__enter__()
499507
)
500508

501509
def __exit__(self, et, ev, tb):

pyomo/common/tee.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __enter__(self):
169169

170170
if self.synchronize and self.std:
171171
# Cause Python's stdout to point to our new file
172-
self.target_file = os.fdopen(self.fd, 'a', closefd=False)
172+
self.target_file = os.fdopen(self.fd, "w", closefd=False)
173173
setattr(sys, self.std, self.target_file)
174174

175175
return self
@@ -349,7 +349,7 @@ def _enter_impl(self):
349349
log_stream = self._enter_context(
350350
os.fdopen(
351351
self._enter_context(_fd_closer(os.dup(old_fd[1] or 2))),
352-
mode="a",
352+
mode="w",
353353
closefd=False,
354354
)
355355
)
@@ -358,7 +358,7 @@ def _enter_impl(self):
358358
self._enter_context(LoggingIntercept(log_stream, logger=logger, level=None))
359359

360360
if isinstance(self.output, str):
361-
self.output_stream = self._enter_context(open(self.output, 'a'))
361+
self.output_stream = self._enter_context(open(self.output, "a"))
362362
elif self.output is None:
363363
self.output_stream = io.StringIO()
364364
else:
@@ -415,7 +415,7 @@ def _enter_impl(self):
415415
_fd_closer(os.dup(fd_redirect[fd].original_fd)),
416416
prior_to=self.tee,
417417
),
418-
mode="a",
418+
mode="w",
419419
closefd=False,
420420
),
421421
prior_to=self.tee,
@@ -673,7 +673,7 @@ def STDERR(self):
673673
self._stderr = self.open(buffering=b)
674674
return self._stderr
675675

676-
def open(self, mode='a', buffering=-1, encoding=None, newline=None):
676+
def open(self, mode="w", buffering=-1, encoding=None, newline=None):
677677
if encoding is None:
678678
encoding = self.encoding
679679
handle = _StreamHandle(mode, buffering, encoding, newline)

0 commit comments

Comments
 (0)