Skip to content

Commit dd16185

Browse files
committed
Replace some subprocess.run() calls with subprocess.check_output()
wpiformat calls "git diff --name-only master" in a subprocess to get a list of files which have been modified from master. In GitHub Actions, there is no master branch by default. When wpiformat is run in GitHub Actions, this causes the git subprocess to fail. subprocess.run() doesn't check the return code, so wpiformat was reporting success when the program had actually failed with an error. subprocess.check_output() does check the return code by default. A return code check was also added to "git check-ignore".
1 parent d389b56 commit dd16185

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

wpiformat/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Provides linters and formatters for ensuring WPILib's C++, Java, and Python code
66
Dependencies
77
************
88

9-
- `Python 3.5 or newer <https://www.python.org/downloads/>`_
9+
- `Python 3.6 or newer <https://www.python.org/downloads/>`_
1010
- clang-format (included with `LLVM <http://llvm.org/releases/download.html>`_)
1111

1212
To obtain newer versions of clang-format on older Debian and Ubuntu releases, either upgrade to one that does or add the appropriate ``deb ... main`` line from `apt.llvm.org <http://apt.llvm.org/>`_ to ``/etc/apt/sources.list``. Then install ``clang-format-#`` where ``#`` is the version number.

wpiformat/wpiformat/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ def filter_ignored_files(names):
3636
# Windows, so os.linesep isn't used here.
3737
encoded_names = "\n".join(names).encode()
3838

39-
output_list = subprocess.run(
39+
proc = subprocess.run(
4040
["git", "check-ignore", "--no-index", "-n", "-v", "--stdin"],
4141
input=encoded_names,
42-
stdout=subprocess.PIPE).stdout.decode().split("\n")
42+
stdout=subprocess.PIPE)
43+
if proc.returncode == 128:
44+
raise subprocess.CalledProcessError
45+
46+
output_list = proc.stdout.decode().split("\n")
4347

4448
# "git check-ignore" prefixes the names of non-ignored files with "::",
4549
# wraps names in quotes on Windows, and outputs "\n" line separators on all
@@ -303,13 +307,11 @@ def main():
303307
files = filter_ignored_files(files)
304308

305309
# Create list of all changed files
306-
changed_file_list = []
307-
308-
output_list = subprocess.run(["git", "diff", "--name-only", "master"],
309-
stdout=subprocess.PIPE).stdout.split()
310-
for line in output_list:
311-
changed_file_list.append(root_path + os.sep +
312-
line.strip().decode("ascii"))
310+
output_list = subprocess.check_output(
311+
["git", "diff", "--name-only", "master"], encoding="ascii").split()
312+
changed_file_list = [
313+
root_path + os.sep + line.strip() for line in output_list
314+
]
313315

314316
# Don't run tasks on modifiable or generated files
315317
work = []

wpiformat/wpiformat/licenseupdate.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,12 @@ def run_pipeline(self, config_file, name, lines):
137137
# log" because the year the file was last modified in the history should
138138
# be used. Author dates can be older than this or even out of order in
139139
# the log.
140-
cmd = ["git", "log", "-n", "1", "--format=%ci", "--", name]
141-
last_year = subprocess.run(cmd,
142-
stdout=subprocess.PIPE).stdout.decode()[:4]
140+
last_year = subprocess.check_output(
141+
["git", "log", "-n", "1", "--format=%ci", "--", name]).decode()[:4]
143142

144143
# Check if file has uncomitted changes in the working directory
145-
cmd = ["git", "diff-index", "--quiet", "HEAD", "--", name]
146-
has_uncommitted_changes = subprocess.run(cmd).returncode
144+
has_uncommitted_changes = subprocess.run(
145+
["git", "diff-index", "--quiet", "HEAD", "--", name]).returncode
147146

148147
# If file hasn't been committed yet or has changes in the working
149148
# directory, use current calendar year as end of copyright year range

0 commit comments

Comments
 (0)