Skip to content

warnings raised by test_peg_generator when setuptools_scm is installed #133509

Open
@kulikjak

Description

@kulikjak

Bug report

Bug description:

Hi, since #131802, we see test_peg_generator failing with the following warning:

Warning -- logging._handlerList was modified by test_peg_generator
Warning --   Before: (140617884985088, [<weakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620>, <weakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0>], [<weakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620>])
Warning --   After:  (140617884985088, [<weakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620>, <weakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0>], [<weakref at 0x7fe4271c8720; to 'logging._StderrHandler' at 0x7fe427ceb620>, <weakref at 0x7fe421d4d350; to 'setuptools_scm._log.AlwaysStdErrHandler' at 0x7fe420b25fd0>])

For some reason, during the execution, second reference to the same 'setuptools_scm._log.AlwaysStdErrHandler' appears in the _handlerList.

When I remove setuptools_scm, the issue is gone.

Interestingly (at least to me), when I revert changes done in #131802 in lib/test/support/__init__.py and os_helper.py (commenting out import logging is enough), the issue is gone as well, so it seems like some weird side effect of the import?

I tried to track the issue and got through setuptools all the way to ep.load() in finalize_options() which triggers the issue (see trace below).

I added some debug prints to _addHandlerRef function, and it's apparently called only once with this handler. Though I also see a single call for the logging._StderrHandler' and it's there twice as well, so I am probably overlooking something...

Here is the trace from when the handler ref is being added during the test execution:

.....
  File "/build/cpython-3.13/Lib/test/test_peg_generator/test_c_parser.py", line 131, in build_extension
    generate_parser_c_extension(grammar, Path('.'), library_dir=self.library_dir)
  File "/build/cpython-3.13/Tools/peg_generator/pegen/testutil.py", line 107, in generate_parser_c_extension
    compile_c_extension(
  File "/build/cpython-3.13/Tools/peg_generator/pegen/build.py", line 160, in compile_c_extension
    dist = Distribution({"name": extension_name, "ext_modules": [extension]})
  File "/usr/lib/python3.13/vendor-packages/setuptools/dist.py", line 323, in __init__
    _Distribution.__init__(self, dist_attrs)
  File "/usr/lib/python3.13/vendor-packages/setuptools/_distutils/dist.py", line 309, in __init__
    self.finalize_options()
  File "/usr/lib/python3.13/vendor-packages/setuptools/dist.py", line 787, in finalize_options
    for ep in sorted(loaded, key=by_order):
  File "/usr/lib/python3.13/vendor-packages/setuptools/dist.py", line 786, in <lambda>
    loaded = map(lambda e: e.load(), filtered)
  File "/build/cpython-3.13/Lib/importlib/metadata/__init__.py", line 179, in load
    module = import_module(match.group('module'))
  File "/build/cpython-3.13/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/lib/python3.13/vendor-packages/setuptools_scm/__init__.py", line 8, in <module>
    from ._config import DEFAULT_LOCAL_SCHEME
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/lib/python3.13/vendor-packages/setuptools_scm/_config.py", line 15, in <module>
    from . import _log
  File "<frozen importlib._bootstrap>", line 1415, in _handle_fromlist
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py", line 48, in <module>
    _default_handler = make_default_handler()
  File "/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py", line 43, in make_default_handler
    handler = AlwaysStdErrHandler()
  File "/usr/lib/python3.13/vendor-packages/setuptools_scm/_log.py", line 23, in __init__
    super().__init__(sys.stderr)
  File "/build/cpython-3.13/Lib/logging/__init__.py", line 1128, in __init__
    Handler.__init__(self)
  File "/build/cpython-3.13/Lib/logging/__init__.py", line 941, in __init__
    _addHandlerRef(self)

All this is with Python 3.13 (latest changes), setuptools 80.3.1, setuptools_scm 8.3.1, and on Oracle Solaris, but I don't think this is necessarily platform dependent.

I also reproduced this with older setuptools 73.0.1 and setuptools_scm 8.1.0.

CPython versions tested on:

3.13

Operating systems tested on:

Other

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions