Skip to content

Commit 0fa808f

Browse files
eli-schwartzjpakkane
authored andcommitted
Add script to create a zipapp.
Invoke create_zipapp.py from the root of the repository and it will create a minimal zipapp with only the mesonbuild module code and a __main__.py directly copied from meson.py The meson.py launcher already tracks the desired entry point, and its only other effect is to add the mesonbuild directory to the path if it exists, which it won't in the zipapp. So there's no need to duplicate this into another __main__.py
1 parent df50123 commit 0fa808f

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

__main__.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

packaging/create_zipapp.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
from pathlib import Path
5+
import shutil
6+
import sys
7+
import tempfile
8+
import zipapp
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('source', nargs='?', default='.', help='Source directory')
12+
parser.add_argument('--outfile', default='meson.pyz', help='Output file for the zipapp')
13+
parser.add_argument('--interpreter', default='/usr/bin/env python3', help='The name of the Python interpreter to use')
14+
15+
options = parser.parse_args(sys.argv[1:])
16+
17+
source = Path(options.source).resolve()
18+
19+
with tempfile.TemporaryDirectory() as d:
20+
shutil.copy2(source / 'meson.py', Path(d, '__main__.py'))
21+
shutil.copytree(source / 'mesonbuild', Path(d, 'mesonbuild'))
22+
zipapp.create_archive(d, interpreter=options.interpreter, target=options.outfile)

run_meson_command_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ def test_meson_exe_windows(self):
193193
def test_meson_zipapp(self):
194194
if is_windows():
195195
raise unittest.SkipTest('NOT IMPLEMENTED')
196-
source = Path(__file__).resolve().parent.as_posix()
196+
source = Path(__file__).resolve().parent
197197
target = self.tmpdir / 'meson.pyz'
198-
zipapp.create_archive(source=source, target=target, interpreter=python_command[0], main=None)
198+
script = source / 'packaging' / 'create_zipapp.py'
199+
self._run([script.as_posix(), source, '--outfile', target, '--interpreter', python_command[0]])
199200
self._run([target.as_posix(), '--help'])
200201

201202

0 commit comments

Comments
 (0)