Skip to content

Commit

Permalink
Fix Python build check script.
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Nov 2, 2023
1 parent 459697a commit 482e394
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions codes/python/build.py
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")

0 comments on commit 482e394

Please sign in to comment.