Skip to content

Forward warning options to subprocess #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented May 22, 2025

This PR is inspired by the discussions in:

The main idea is to forward whichever warning options have been specified for the "parent" process to the subprocess, as a complement to #157 1.

For example, if the user passes python -W ignore -m build, then _in_process.py would also be called with -W ignore.

This is an initial investigation to test the waters, it can be incrementally improved based on feedback.

One thing that I considered is a finer control over the warnings or allowing the API callers to customise the values. But I rejected this idea as over engineering. Based on YAGNI, we can implement something very simple.

Footnotes

  1. This way frontends could re-use Python's UI for warning filters without the necessity to implement their own. (They can still implement it if they want, but re-using Python's is handy).

@abravalheri abravalheri force-pushed the forward-warnoptions branch from e439d85 to 9c9e3a2 Compare May 22, 2025 16:30
@abravalheri
Copy link
Contributor Author

/cc @pradyunsg @notatallshaw as this is related to the work in #215.

I think it would actually be interesting to run #215 against the tests in this PR just as a form of regression tests.

@abravalheri
Copy link
Contributor Author

abravalheri commented May 22, 2025

As a manual sanity check I did the following from my local clone of pyproject-hooks:

cd .nox/
./test-3-10/bin/python -m pip install -U pip
./test-3-10/bin/python -m pip install build -e ..


./test-3-10/bin/python -W ignore -m build ~/workspace/setuptools
# No warnings


./test-3-10/bin/python -W error -m build ~/workspace/setuptools
# ...
#   File "/home/abravalheri/workspace/setuptools/setuptools/warnings.py", line 52, in emit
#    warnings.warn(text, cls, stacklevel=stacklevel + 1)
# setuptools.config.pyprojecttoml._ExperimentalConfiguration: `[tool.distutils]` in `pyproject.toml` is still *experimental* and likely to change in future releases.
#
# ERROR Backend subprocess exited when trying to invoke build_sdist


./test-3-10/bin/python -W default -m build ~/workspace/setuptools
# ... a bunch of things, including:
# WARNING `[tool.distutils]` in `pyproject.toml` is still *experimental* and likely to change in future releases.
# ...

@abravalheri abravalheri marked this pull request as ready for review May 22, 2025 16:41
"""
# `sys.warnoptions` is documented/mentioned in
# https://docs.python.org/3.13/library/warnings.html#describing-warning-filters
return chain.from_iterable(("-W", opt) for opt in sys.warnoptions)
Copy link
Contributor Author

@abravalheri abravalheri May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python docs do mention that sys.warnoptions should not be modified but they do not prevent reading it.

In fact, docs for 3.12 even include examples using it for quick checks https://docs.python.org/3.12/library/warnings.html#overriding-the-default-filter:

import sys

if not sys.warnoptions:
    import warnings
    warnings.simplefilter("ignore")

@abravalheri abravalheri force-pushed the forward-warnoptions branch from 9c9e3a2 to 4c2fd35 Compare May 22, 2025 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant