From ee8b9b52ed3c7ecc45c33ff9ddba556fea1233d7 Mon Sep 17 00:00:00 2001 From: Ali Shariat Date: Tue, 14 Dec 2021 14:50:28 -0800 Subject: [PATCH] add console_script to the wheel also used `os.execl` to replace the script instead of creating a child process. --- make_wheels.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/make_wheels.py b/make_wheels.py index f575ae0..48268c0 100644 --- a/make_wheels.py +++ b/make_wheels.py @@ -46,6 +46,10 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents) dist_info = f'{name}-{version}.dist-info' return write_wheel_file(os.path.join(out_dir, wheel_name), { **contents, + f'{dist_info}/entry_points.txt': f'''\ +[console_scripts] +zig=ziglang.__main__:main +'''.encode('ascii'), f'{dist_info}/METADATA': make_message({ 'Metadata-Version': '2.1', 'Name': name, @@ -77,11 +81,15 @@ def write_ziglang_wheel(out_dir, *, version, platform, archive): if entry_name.startswith('zig'): contents['ziglang/__main__.py'] = f'''\ -import os, sys, subprocess -sys.exit(subprocess.call([ - os.path.join(os.path.dirname(__file__), "{entry_name}"), - *sys.argv[1:] -])) +import os, sys +def main(): + os.execl( + os.path.join(os.path.dirname(__file__), "{entry_name}"), + "zig", + *sys.argv[1:] + ) +if __name__ == "__main__": + main() '''.encode('ascii') with open('README.pypi.md') as f: