Page MenuHome

Replace os.system() with subprocess.check_call()
ClosedPublic

Authored by Lawrence D'Oliveiro (ldo) on Dec 17 2017, 4:39 AM.

Details

Summary

Change all instances of os.system() that do not need to go through the shell to use subprocess.check_call() instead. Not only does this save a process creation, it is also safer, with less chance of being tripped up by filenames with odd characters in them.

Diff Detail

Event Timeline

Yes, I could do subprocess.run(check = True) instead of subprocess.check_call(); does it really matter either way?

Campbell Barton (campbellbarton) requested changes to this revision.EditedJan 26 2018, 2:58 AM

Applied all except for build_files/buildbot,

Note that in some cases I had to replace check_call with call, pep8.py exists on the first file which has any warnings for example.

buildbot changes seem OK, but they should be checked first.

This revision now requires changes to proceed.Jan 26 2018, 2:58 AM
This revision is now accepted and ready to land.Jan 26 2018, 3:01 AM

Is there some action that somebody needs to take?

Campbell Barton (campbellbarton) requested changes to this revision.Apr 9 2018, 6:58 PM

@Lawrence D'Oliveiro (ldo), could you update the patch? some of these have been applied.
For the parts of the code that weren't - these were ares I couldn't test easily.

This revision now requires changes to proceed.Apr 9 2018, 6:58 PM

Rebase for upstream changes as requested.

Updated patch that should apply cleanly against the current source tree.

Updated patch that should apply cleanly against the current source tree.

This revision is now accepted and ready to land.Dec 23 2018, 1:00 AM

Accepted, did you double check this works for the build-bot?

Updated patch that should apply cleanly against the current source tree.

Checked this patch and the build-bot changes no longer apply, there are issues in the pep8.py too.

Closing.

tests/python/pep8.py
124

This fails with an error early if there are any warnings:

-----------------------------------
Your code has been rated at 9.04/10

Traceback (most recent call last):
  File "/src/blender/./tests/python/pep8.py", line 208, in <module>
    main()
  File "/src/blender/./tests/python/pep8.py", line 202, in main
    check_files_pylint(files)
  File "/src/blender/./tests/python/pep8.py", line 124, in check_files_pylint
    subprocess.check_call((
  File "/usr/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '('pylint', '--disable=C0111,C0103,C0413,W0613,W0232,W0142,R0902,R0903,R0911,R0912,R0913,R0914,R0915,', '--output-format=parseable', '--reports=n', '--max-line-length=1000', '/src/blender/tests/check_deprecated.py')' returned non-zero exit status 28.