I have a Python script:
import subprocess
subprocess.run(['black', 'src'])
I would like to tell if the command run by subprocess
modified any file in the folder src
- so, I'd like my script to look like this:
import subprocess
subprocess.run(['black', 'src'])
mutated = <???>
How can I detect whether any file in the directory src
changed after the subprocess.run
command, and if so assign True
to mutated
?
EDIT
Using os.path.getmtime
isn't working for me:
(Pdb) os.path.getmtime(str(arg))
1596263725.3222768
(Pdb) subprocess.run(['black', str(arg), '--line-length=5'])
reformatted /tmp/tmp7e7suv4e/tests/data/clean_notebook .py
reformatted /tmp/tmp7e7suv4e/tests/data/notebook_for_testing .py
reformatted /tmp/tmp7e7suv4e/tests/data/notebook_for_testing_copy .py
reformatted /tmp/tmp7e7suv4e/tests/data/notebook_starting_with_md .py
All done! ✨ ✨
4 files reformatted, 2 files left unchanged.
CompletedProcess(args=['black', '/tmp/tmp7e7suv4e/tests', '--line-length=5'], returncode=0)
(Pdb) os.path.getmtime(str(arg))
1596263725.3222768