Skip to content

Commit 3a8339d

Browse files
authored
Merge pull request #3643 from jsiirola/python314-fixes
Resolve Python 3.14 compatibility issues
2 parents c3c95ad + 60e7c0b commit 3a8339d

File tree

5 files changed

+73
-60
lines changed

5 files changed

+73
-60
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: 12 additions & 4 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())

0 commit comments

Comments
 (0)