.github: Ensure python3 -m pip is used in GitHub Actions#30657
.github: Ensure python3 -m pip is used in GitHub Actions#30657cclauss wants to merge 2 commits intoArduPilot:masterfrom
Conversation
|
Errr... does this introduce a top-level "test" directory? That doesn't seem right |
b6596d9 to
89e9101
Compare
|
why not a simple grep script like : And register is as part of pre-commit : |
|
I like the idea of adding pytests to the ardupilot codebase. :) |
|
I moved this script from I distrust bash scripts (especially with regex) as I find it difficult to see bugs in them and write tests. This is particularly true when scripts must run across multiple operating systems. Would the script above only process GitHub Actions, and would it pass the four tests of The idea of adding to |
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
Like: * ArduPilot/ardupilot#30657 Ensure that "python3 -m pip install " is used consistently in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found. ### How was this tested? 1. localhost testing 2. This is a test that contains tests.
89e9101 to
57baed8
Compare
Ensure that "python3 -m pip install " is used consistantly in GitHub Actions. Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ". If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found.
57baed8 to
bf018dd
Compare
peterbarker
left a comment
There was a problem hiding this comment.
Again, not really comfortable using the top-level tests directory for this content.
As covered on the DevCall, we were a bit surprised it existed, and its current use is for the gtest suite which is a rather different animal to these python tests.
Consider Tools/scripts/python_tests instead.
| line number, and the line. Raise an error if any non-compliant files are found. | ||
| """ | ||
|
|
||
| from __future__ import annotations |
There was a problem hiding this comment.
What versions of Python will this work back to?
There was a problem hiding this comment.
... actually, it would be nice to have a linting step which picked up any use of Python features not available in whatever our minimum version of Python is
There was a problem hiding this comment.
https://docs.python.org/3/library/__future__.html#module-contents says Python 3.7b1
ruff check uses target-python to apply or relax lint rules.
| "python3 -m pip install ". | ||
| """ | ||
| with file_path.open() as in_file: | ||
| for line_number, line in enumerate(in_file, start=1): |
There was a problem hiding this comment.
Why skip the first line?
There was a problem hiding this comment.
start=1 does not skip line 1. It starts line_number at 1 so that the line_number of the first line is 1, not 0.
|
|
||
|
|
||
| def test_pip_install_without_python3_minus_m_prefix() -> None: | ||
| workflows_dir = Path(".github/workflows") |
There was a problem hiding this comment.
I'd like to apply this across the entire codebase, actually... don't want them slipping into environment install files, for example.
There was a problem hiding this comment.
I am becoming less and less interested in this rule because it actively encourages people to be lazy about using virtual environments and to pollute their system Pythons with dependencies that might span multiple projects. This can lead to dependency conflicts that are difficult to debug and crashes that cannot be replicated.
Applying this rule inside GHAs bugs me less because they are already virtual (Docker) environments, but doing this on developers' machines seems irresponsible because it will make system modifications that will be extremely difficult for them to undo.
| errors.extend( | ||
| f"{yml_file}:{line_number}: {line}" | ||
| for line_number, line in process_file(yml_file) | ||
| ) |
There was a problem hiding this comment.
Let's simplify this - just because you can doesn't mean you should. The indenting here makes this particularly bad as a construct!
| errors.extend( | |
| f"{yml_file}:{line_number}: {line}" | |
| for line_number, line in process_file(yml_file) | |
| ) | |
| for line_number, line in process_file(yml_file): | |
| errors.append(f"{yml_file}:{line_number}: {line}") |
There was a problem hiding this comment.
The proposed solution reduces function call overhead from once per failing line to once per failing file.
Runtime performance is an important consideration for code that we may choose to add as a pre-commit hook.
The indenting is done automatically, not manually.
% ruff rule FURB113 # repeated-append
[ ... ]
Why is this bad?
Consecutive calls to append can be less efficient than batching them into a single extend. Each append resizes the list individually, whereas an extend can resize the list once for all elements.
[ ... ]
Co-authored-by: Peter Barker <pb-gh@barker.dropbear.id.au>
|
Closing in favor of the bash script approach recommended at #30657 (comment) |
Ensure that "python3 -m pip install " is used consistantly in GitHub Actions.
Find all .yml files in the .github/workflows directory and find all lines that contain " pip install " and ensure that they also contain "python3 -m pip install ".
If there is any line that has the first but not the second, then print the file name, line number, and the line. Raise an error if any non-compliant files are found.
%
pytest# Improved formatHow was this tested?
This will run automatically once one of these pull requests has been merged.