Skip to content

Commit

Permalink
add script for generating a standalone zipapp
Browse files Browse the repository at this point in the history
  • Loading branch information
gvalkov committed Mar 29, 2015
1 parent fff5418 commit 71eed32
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
etc/_rsstail:
compgen.py zsh > $@

etc/rsstail.sh:
compgen.py bash > $@

compgen: etc/_rsstail etc/rsstail.sh

rsstail.pyz:
./pyzgen.sh $@

PHONY: standalone compgen
46 changes: 46 additions & 0 deletions pyzgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
set -xeu

# Bundles feedparser and rsstail into a stand-alone, executable zip file.
# Usage: pyzgen.sh [<destination.pyz>]

DESTFILE="${1:-./rsstail.pyz}"
DESTFILE=$(readlink -f "$DESTFILE")
PYZEXCLUDE="\*__pycache__ \*.pyo \*.pyc feedparser-\*"
FEEDPARSER_URL="https://warehouse.python.org/packages/source/f/feedparser/feedparser-5.1.3.tar.gz"

#-----------------------------------------------------------------------------
BUILDDIR=$(mktemp -d)
trap "rm -rf $BUILDDIR" EXIT

#-----------------------------------------------------------------------------
curl "$FEEDPARSER_URL" | tar -xz -C "$BUILDDIR"
cp -r ./rsstail "$BUILDDIR"
cp "$BUILDDIR"/feedparser-*/feedparser/feedparser.py "$BUILDDIR/rsstail/feedparser2.py"
cp "$BUILDDIR"/feedparser-*/feedparser/feedparser.py "$BUILDDIR/rsstail/feedparser3.py"
2to3 "$BUILDDIR/rsstail/feedparser3.py"

#-----------------------------------------------------------------------------
cat > "$BUILDDIR/__main__.py" <<EOF
#!/usr/bin/env python
# -*- coding: utf-8; -*-
import sys
if sys.version_info < (3,0):
import rsstail.feedparser2
sys.modules['feedparser'] = rsstail.feedparser2
else:
import rsstailfeedparser3
sys.modules['feedparser'] = rsstail.feedparser3
from rsstail.main import main
if __name__ == '__main__':
main()
EOF


#-----------------------------------------------------------------------------
[ -e "$DESTFILE" ] && rm -f "$DESTFILE"
(cd "$BUILDDIR" && eval zip -9 -r "$DESTFILE" . -x "$PYZEXCLUDE" )
sed -i '1i#!/usr/bin/env python' "$DESTFILE"
chmod +x "$DESTFILE"

0 comments on commit 71eed32

Please sign in to comment.