-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import glob | ||
import py_compile as pyc | ||
import subprocess | ||
|
||
if __name__ == "__main__": | ||
# find source code files | ||
src_paths = sorted(glob.glob("codes/python/**/*.py")) | ||
num_src = len(src_paths) | ||
num_src_error = 0 | ||
src_paths = sorted(glob.glob("codes/python/chapter_*/*.py")) | ||
errors = [] | ||
error_count = 0 | ||
|
||
# compile python code | ||
# run python code | ||
for src_path in src_paths: | ||
try: | ||
pyc.compile(src_path, doraise=True) | ||
except pyc.PyCompileError as e: | ||
num_src_error += 1 | ||
print(e) | ||
process = subprocess.Popen( | ||
["python", src_path], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True, | ||
) | ||
# Wait for the process to complete, and get the output and error messages | ||
stdout, stderr = process.communicate() | ||
# Check the exit status | ||
exit_status = process.returncode | ||
if exit_status != 0: | ||
errors.append(stderr) | ||
error_count += 1 | ||
|
||
print(f"===== Build Complete =====") | ||
print(f"Total: {num_src}") | ||
print(f"Error: {num_src_error}") | ||
print(f"===== Found exception in {error_count} files =====") | ||
for error in errors: | ||
print(error + "\n") |