Skip to content
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

Add compiler warning tracking tooling failure remediation guidance #1364

Merged
merged 7 commits into from
Aug 24, 2024

Conversation

nohlson
Copy link
Contributor

@nohlson nohlson commented Aug 7, 2024

New warning tracking tooling was introduced to CPython GitHub Actions jobs for Ubuntu with python/cpython#121730.

It was then added for macOS build and test jobs with python/cpython#122211

New compiler options that will emit warnings for potential security issues are going to be introduced to CPython. This addition to the developers guide is intended to be a reference for developers if the warning tracking tooling fails GitHub Actions CI.

I intend further expand on this documentation with examples based on the warning flags that we introduce to CPython, how developers can attempt to refactor to avoid these warnings, and finer details on how to modify warning ignore files.


📚 Documentation preview 📚: https://cpython-devguide--1364.org.readthedocs.build/

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thanks! Some suggestions :)

Tip: You can apply all desired suggestions with one click by going to the Files changed tab, clicking Add to batch on each suggestion you want, and clicking Commit once you're done.

conf.py Outdated Show resolved Hide resolved
conf.py Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
Comment on lines 60 to 69
1. Unexpected Warnings
a. Attempt to refactor the code to avoid the warning.
b. If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
2. Unexpected Imrpovements (Less Warnings)
a. Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform specific warning
ignore file or remove the file if the count is now zero.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. Unexpected Warnings
a. Attempt to refactor the code to avoid the warning.
b. If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
2. Unexpected Imrpovements (Less Warnings)
a. Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform specific warning
ignore file or remove the file if the count is now zero.
* Unexpected warnings
* Attempt to refactor the code to avoid the warning.
* If it is not possible to avoid the warning, document in the PR why it is
reasonable to ignore and add the warning to the platform-specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of newly introduced warnings.
* Unexpected improvements (less warnings)
* Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform-specific warning
ignore file or remove the file if the count is now zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted this to read more like a decision tree and it looked like the only way for me to create a numbered list in rst was to explicitly create one. I changed this a bulleted list as suggested for now because when we start getting concrete examples of how to address warnings I want to really expand on this section.

Copy link
Member

Choose a reason for hiding this comment

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

I see. I usually follow the Google guidelines on this; use bullets unless it's a sequence of steps to be performed in order: https://developers.google.com/style/lists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably what I want is bullets and then the second level is a sequence of steps, since that is the case here. The top level is a condition: you failed the test because of one of these conditions and then what follows are the steps to address it.

development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
@hugovk hugovk changed the title Add Compiler Warning Tracking Tooling Failure Remediation Guidance Add compiler warning tracking tooling failure remediation guidance Aug 8, 2024
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Here's some suggestions again that were missed. There are still some pending ones from yesterday.

conf.py Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
development-tools/warnings.rst Outdated Show resolved Hide resolved
Comment on lines 60 to 69
1. Unexpected Warnings
a. Attempt to refactor the code to avoid the warning.
b. If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
2. Unexpected Imrpovements (Less Warnings)
a. Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform specific warning
ignore file or remove the file if the count is now zero.
Copy link
Member

Choose a reason for hiding this comment

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

I see. I usually follow the Google guidelines on this; use bullets unless it's a sequence of steps to be performed in order: https://developers.google.com/style/lists

development-tools/warnings.rst Outdated Show resolved Hide resolved
Copy link
Member

@ezio-melotti ezio-melotti left a comment

Choose a reason for hiding this comment

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

I left several comments, many of which either include or supersede @hugovk's comments. In those cases, committing my comments should be enough (committing Hugo's first might create conflicts).

Tools for tracking compiler warnings
====================================

The compiler warning tracking tooling is intended to alert developers to new
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The compiler warning tracking tooling is intended to alert developers to new
The compiler warning tracking tooling is intended to alert developers about new

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to about

Comment on lines 11 to 12
- Ubuntu/Build and Test
- macOS/Build and Test
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Ubuntu/Build and Test
- macOS/Build and Test
* Ubuntu/build and test (:cpy-file:`.github/workflows/reusable-ubuntu.yml`)
* macOS/build and test (:cpy-file:`.github/workflows/reusable-macos.yml`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included links to the configuration files

Comment on lines 7 to 9
compiler warnings introduced by their contributions. The tooling consists of
Python script which is ran by a few GitHub Actions workflows. These
GitHub Actions jobs run the warning checking tooling:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
compiler warnings introduced by their contributions. The tooling consists of
Python script which is ran by a few GitHub Actions workflows. These
GitHub Actions jobs run the warning checking tooling:
compiler warnings introduced by their contributions. The tooling consists of
a Python script which is ran by the following GitHub workflows:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied suggestion to make this more concise.

Comment on lines 4 to 6
====================================

The compiler warning tracking tooling is intended to alert developers to new
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
====================================
The compiler warning tracking tooling is intended to alert developers to new
====================================
.. highlight:: bash
The compiler warning tracking tooling is intended to alert developers to new

We can use this to set the default highlight of the file.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, though we only two code-blocks with different highlights :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the default anyway!

Comment on lines 14 to 33
The help text for the :cpy-file:`Tools/build/check_warnings.py` is as follows:

.. code-block:: text

usage: check_warnings.py [-h]
-c COMPILER_OUTPUT_FILE_PATH
[-i WARNING_IGNORE_FILE_PATH] [-x] [-X] -t {json,clang}

options:
-h, --help show this help message and exit
-c COMPILER_OUTPUT_FILE_PATH, --compiler-output-file-path COMPILER_OUTPUT_FILE_PATH
Path to the compiler output file
-i WARNING_IGNORE_FILE_PATH, --warning-ignore-file-path WARNING_IGNORE_FILE_PATH
Path to the warning ignore file
-x, --fail-on-regression
Flag to fail if new warnings are found
-X, --fail-on-improvement
Flag to fail if files that were expected to have warnings have no warnings
-t {json,clang}, --compiler-output-type {json,clang}
Type of compiler output file (json or clang)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The help text for the :cpy-file:`Tools/build/check_warnings.py` is as follows:
.. code-block:: text
usage: check_warnings.py [-h]
-c COMPILER_OUTPUT_FILE_PATH
[-i WARNING_IGNORE_FILE_PATH] [-x] [-X] -t {json,clang}
options:
-h, --help show this help message and exit
-c COMPILER_OUTPUT_FILE_PATH, --compiler-output-file-path COMPILER_OUTPUT_FILE_PATH
Path to the compiler output file
-i WARNING_IGNORE_FILE_PATH, --warning-ignore-file-path WARNING_IGNORE_FILE_PATH
Path to the warning ignore file
-x, --fail-on-regression
Flag to fail if new warnings are found
-X, --fail-on-improvement
Flag to fail if files that were expected to have warnings have no warnings
-t {json,clang}, --compiler-output-type {json,clang}
Type of compiler output file (json or clang)
You can check the documentation for the :cpy-file:`Tools/build/check_warnings.py` tool
by running::
python Tools/build/check_warnings.py --help

I'm not sure it's a good idea duplicating the help text here, since it might become obsolete if new options are added. If people are going to use the tool, they might as well just use --help directly to see the latest version of the help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably a good idea. I figured this was a quick way for the reader to get an intuition of what inputs are going to the script if their only exposure to the tooling is that a CI failure has sent them here. I removed it to future-proof this guide.

Comment on lines 52 to 56
The warning check tooling will fail if the compiler generates more or less
warnings than expected for a given source file as defined in the
platform-specific warning ignore file. The warning ignore file is either
:cpy-file:`Tools/build/.warningignore_ubuntu` or :cpy-file:`Tools/build/.warningignore_macos`
depending on the platform.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The warning check tooling will fail if the compiler generates more or less
warnings than expected for a given source file as defined in the
platform-specific warning ignore file. The warning ignore file is either
:cpy-file:`Tools/build/.warningignore_ubuntu` or :cpy-file:`Tools/build/.warningignore_macos`
depending on the platform.
The :cpy-file:`!check_warnings.py` tool will fail if the compiler generates
more or less warnings than expected for a given source file as defined in the
platform-specific warning ignore file. The warning ignore file is either
:cpy-file:`Tools/build/.warningignore_ubuntu` or
:cpy-file:`Tools/build/.warningignore_macos` depending on the platform.

Copy link
Contributor Author

@nohlson nohlson Aug 8, 2024

Choose a reason for hiding this comment

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

Is

:cpy-fil:`!check_warnings.py`

supposed to be shorthand to link to a file with the same basename already referenced in the document? When build the dev guide with the suggestion it would take me to cpython/check_warnings.py.

I put in the full path for now.

Copy link
Member

Choose a reason for hiding this comment

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

The ! tells Sphinx not to generate a link, since for brevity I only used the filename and not the full path, a link can't be generated. By still using :cpy-file: the filename is semantically marked and has the same style as the other filenames marked with the same role. The file is already linked above, so there is no need to repeat the link.

Note that an alternative would have been :cpy-file:`check_warnings.py <Tools/build/check_warnings.py>`, which would have linked to the correct path while only showing the filename, but that doesn't seem to be supported by the :cpy-file: role.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:cpy-file:`!check_warnings.py`

Renders as

Screenshot 2024-08-10 at 7 34 43 PM

And actually links to cpython/check_warnings. Is that what you are suggesting?


If a warning check fails with:

* Unexpected Warnings
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Unexpected Warnings
* More warnings than expected:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept the language the same but fixed the capitalization.

The reason being that the script actually labels warnings as "Unexpected improvements" and "Unexpected warnings"

Comment on lines 62 to 65
* If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
* If it is not possible to avoid the warning document in the PR why it is
reasonable to ignore and add the warning to the platform-specific warning
ignore file. If the file already exists in the warning ignore file
increment the count by the number of newly introduced warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed spacing

reasonable to ignore and add the warning to the platform specific
warning ignore file. If the file exists in the warning ignore file
increment the count by the number of new introduced warnings.
* Unexpected Imrpovements (Less Warnings)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Unexpected Imrpovements (Less Warnings)
* Less warnings than expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept the language the way it was but fixed the capitalization, same reason as above the script actually labels specific warnings as such.

Comment on lines 67 to 69
* Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform specific warning
ignore file or remove the file if the count is now zero.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform specific warning
ignore file or remove the file if the count is now zero.
* Document in the PR that the change reduces the number of compiler
warnings. Decrement the count in the platform-specific warning
ignore file or remove the file if the count is now zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed spacing

@sethmlarson
Copy link
Contributor

I believe all of the review comments have been responded to (except for a clarification, if needed, from @ezio-melotti on this point). If we are happy with this I believe this is blocking being able to link to this devguide from an error in the tooling to make it more clear to core developers what to do.

Thanks all for the reviews, it is much appreciated! 💜

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

I applied @ezio-melotti's suggestions. Let's merge, thanks!

@hugovk hugovk merged commit 94d4d60 into python:main Aug 24, 2024
4 checks passed
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.

5 participants