Skip to content

Commit

Permalink
Add script to create a zipapp.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eli-schwartz authored and jpakkane committed Nov 27, 2020
1 parent df50123 commit 0fa808f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
20 changes: 0 additions & 20 deletions __main__.py

This file was deleted.

22 changes: 22 additions & 0 deletions packaging/create_zipapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

import argparse
from pathlib import Path
import shutil
import sys
import tempfile
import zipapp

parser = argparse.ArgumentParser()
parser.add_argument('source', nargs='?', default='.', help='Source directory')
parser.add_argument('--outfile', default='meson.pyz', help='Output file for the zipapp')
parser.add_argument('--interpreter', default='/usr/bin/env python3', help='The name of the Python interpreter to use')

options = parser.parse_args(sys.argv[1:])

source = Path(options.source).resolve()

with tempfile.TemporaryDirectory() as d:
shutil.copy2(source / 'meson.py', Path(d, '__main__.py'))
shutil.copytree(source / 'mesonbuild', Path(d, 'mesonbuild'))
zipapp.create_archive(d, interpreter=options.interpreter, target=options.outfile)
5 changes: 3 additions & 2 deletions run_meson_command_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ def test_meson_exe_windows(self):
def test_meson_zipapp(self):
if is_windows():
raise unittest.SkipTest('NOT IMPLEMENTED')
source = Path(__file__).resolve().parent.as_posix()
source = Path(__file__).resolve().parent
target = self.tmpdir / 'meson.pyz'
zipapp.create_archive(source=source, target=target, interpreter=python_command[0], main=None)
script = source / 'packaging' / 'create_zipapp.py'
self._run([script.as_posix(), source, '--outfile', target, '--interpreter', python_command[0]])
self._run([target.as_posix(), '--help'])


Expand Down

0 comments on commit 0fa808f

Please sign in to comment.