diff --git a/compileall.py b/compileall.py new file mode 100644 index 00000000..b2e17001 --- /dev/null +++ b/compileall.py @@ -0,0 +1,28 @@ +import sys +import os + +if len(sys.argv) != 4: + print('Usage: python compileall.py ') + exit(1) + +pkpy_exe = sys.argv[1] +source_dir = sys.argv[2] +output_dir = sys.argv[3] + +def do_compile(src_path, dst_path): + cmd = f'{pkpy_exe} --compile "{src_path}" "{dst_path}"' + print(src_path) + assert os.system(cmd) == 0 + +for root, _, files in os.walk(source_dir): + for file in files: + if not file.endswith('.py'): + continue + src_path = os.path.join(root, file) + dst_path = os.path.join( + output_dir, + os.path.relpath(root, source_dir), + file + 'c' + ) + os.makedirs(os.path.dirname(dst_path), exist_ok=True) + do_compile(src_path, dst_path) diff --git a/src/public/GlobalSetup.c b/src/public/GlobalSetup.c index a6913348..d4d044fc 100644 --- a/src/public/GlobalSetup.c +++ b/src/public/GlobalSetup.c @@ -121,7 +121,7 @@ void py_sys_setargv(int argc, char** argv) { py_GlobalRef sys = py_getmodule("sys"); py_Ref argv_list = py_getdict(sys, py_name("argv")); py_list_clear(argv_list); - for(int i = 0; i < argc; i++) { + for(int i = 1; i < argc; i++) { py_newstr(py_list_emplace(argv_list), argv[i]); } } diff --git a/src2/main.c b/src2/main.c index 76daaaa9..683b3bf4 100644 --- a/src2/main.c +++ b/src2/main.c @@ -77,6 +77,7 @@ int main(int argc, char** argv) { if(compile) { bool ok = py_compilefile(arg1, arg2); + if(!ok) py_printexc(); py_finalize(); return ok ? 0 : 1; } diff --git a/tests/801_sys.py b/tests/801_sys.py index 2a91949a..9b0912b1 100644 --- a/tests/801_sys.py +++ b/tests/801_sys.py @@ -1,4 +1,5 @@ import sys -assert len(sys.argv) == 2 -assert (sys.argv[1] == 'tests/801_sys.py'), sys.argv +filename = 'tests/801_sys.py' +assert (sys.argv == [filename]), sys.argv +