golf the sfx-gz by ~27.6 kB;

* 11 kB webdeps: brotli easymde+prism instead of zopfli
* 8 kB jinja2
* 5 kB ftp
* 3 kB improve uncommenter
This commit is contained in:
ed 2023-09-13 23:21:22 +00:00
parent 4fbd6853f4
commit a75a992951
5 changed files with 47 additions and 25 deletions

View file

@ -142,10 +142,11 @@ RUN ./genprism.sh $ver_prism
# compress # compress
COPY zopfli.makefile /z/dist/Makefile COPY brotli.makefile zopfli.makefile /z/dist/
RUN cd /z/dist \ RUN cd /z/dist \
&& make -j$(nproc) \ && make -j$(nproc) -f brotli.makefile \
&& rm Makefile \ && make -j$(nproc) -f zopfli.makefile \
&& rm *.makefile \
&& mv no-pk/* . \ && mv no-pk/* . \
&& rmdir no-pk && rmdir no-pk

View file

@ -0,0 +1,4 @@
all: $(addsuffix .br, $(wildcard prism* easymde*))
%.br: %
brotli -jZ $<

View file

@ -1,10 +1,6 @@
all: $(addsuffix .gz, $(wildcard *.*)) all: $(addsuffix .gz, $(wildcard *.js *.css))
%.gz: % %.gz: %
#brotli -q 11 $<
pigz -11 -I 573 $< pigz -11 -I 573 $<
# pigz -11 -J 34 -I 100 -F < $< > $@.first # pigz -11 -J 34 -I 100 -F < $< > $@.first
# disabling brotli after all since the gain is meh
# and it bloats sfx and wheels by like 70%

View file

@ -134,6 +134,14 @@ tmv() {
touch -r "$1" t touch -r "$1" t
mv t "$1" mv t "$1"
} }
iawk() {
awk "$1" <"$2" >t
tmv "$2"
}
ised() {
sed -r "$1" <"$2" >t
tmv "$2"
}
stamp=$( stamp=$(
for d in copyparty scripts; do for d in copyparty scripts; do
@ -229,9 +237,7 @@ necho() {
mv python-magic-*/magic . mv python-magic-*/magic .
rm -rf python-magic-* rm -rf python-magic-*
rm magic/compat.py rm magic/compat.py
f=magic/__init__.py iawk '/^def _add_compat/{o=1} !o; /^_add_compat/{o=0}' magic/__init__.py
awk '/^def _add_compat/{o=1} !o; /^_add_compat/{o=0}' <$f >t
tmv "$f"
mv magic ftp/ # doesn't provide a version label anyways mv magic ftp/ # doesn't provide a version label anyways
# enable this to dynamically remove type hints at startup, # enable this to dynamically remove type hints at startup,
@ -398,7 +404,7 @@ find -type f -name ._\* | while IFS= read -r f; do cmp <(printf '\x00\x05\x16')
rm -f copyparty/web/deps/*.full.* copyparty/web/dbg-* copyparty/web/Makefile rm -f copyparty/web/deps/*.full.* copyparty/web/dbg-* copyparty/web/Makefile
find copyparty | LC_ALL=C sort | sed 's/\.gz$//;s/$/,/' > have find copyparty | LC_ALL=C sort | sed -r 's/\.(gz|br)$//;s/$/,/' > have
cat have | while IFS= read -r x; do cat have | while IFS= read -r x; do
grep -qF -- "$x" ../scripts/sfx.ls || { grep -qF -- "$x" ../scripts/sfx.ls || {
echo "unexpected file: $x" echo "unexpected file: $x"
@ -407,6 +413,11 @@ cat have | while IFS= read -r x; do
done done
rm have rm have
ised /fork_process/d ftp/pyftpdlib/servers.py
iawk '/^class _Base/{s=1}!s' ftp/pyftpdlib/authorizers.py
iawk '/^ {0,4}[^ ]/{s=0}/^ {4}def (serve_forever|_loop)/{s=1}!s' ftp/pyftpdlib/servers.py
rm -f ftp/pyftpdlib/{__main__,prefork}.py
[ $no_ftp ] && [ $no_ftp ] &&
rm -rf copyparty/ftpd.py ftp asyncore.py asynchat.py && rm -rf copyparty/ftpd.py ftp asyncore.py asynchat.py &&
sed -ri '/add_argument\("--ftp/d' copyparty/__main__.py && sed -ri '/add_argument\("--ftp/d' copyparty/__main__.py &&
@ -423,9 +434,7 @@ rm have
[ $no_cm ] && { [ $no_cm ] && {
rm -rf copyparty/web/mde.* copyparty/web/deps/easymde* rm -rf copyparty/web/mde.* copyparty/web/deps/easymde*
echo h > copyparty/web/mde.html echo h > copyparty/web/mde.html
f=copyparty/web/md.html ised '/edit2">edit \(fancy/d' copyparty/web/md.html
sed -r '/edit2">edit \(fancy/d' <$f >t
tmv "$f"
} }
[ $no_hl ] && [ $no_hl ] &&
@ -435,23 +444,20 @@ rm have
rm -f copyparty/web/deps/scp.woff2 rm -f copyparty/web/deps/scp.woff2
f=copyparty/web/ui.css f=copyparty/web/ui.css
gzip -d "$f.gz" || true gzip -d "$f.gz" || true
sed -r "s/src:.*scp.*\)/src:local('Consolas')/" <$f >t ised "s/src:.*scp.*\)/src:local('Consolas')/" $f
tmv "$f"
} }
[ $no_dd ] && { [ $no_dd ] && {
rm -rf copyparty/web/dd rm -rf copyparty/web/dd
f=copyparty/web/browser.css f=copyparty/web/browser.css
gzip -d "$f.gz" || true gzip -d "$f.gz" || true
sed -r 's/(cursor: ?)url\([^)]+\), ?(pointer)/\1\2/; s/[0-9]+% \{cursor:[^}]+\}//; s/animation: ?cursor[^};]+//' <$f >t ised 's/(cursor: ?)url\([^)]+\), ?(pointer)/\1\2/; s/[0-9]+% \{cursor:[^}]+\}//; s/animation: ?cursor[^};]+//' $f
tmv "$f"
} }
[ $langs ] && [ $langs ] &&
for f in copyparty/web/{browser.js,splash.js}; do for f in copyparty/web/{browser.js,splash.js}; do
gzip -d "$f.gz" || true gzip -d "$f.gz" || true
awk '/^\}/{l=0} !l; /^var Ls =/{l=1;next} o; /^\t["}]/{o=0} /^\t"'"$langs"'"/{o=1;print}' <$f >t iawk '/^\}/{l=0} !l; /^var Ls =/{l=1;next} o; /^\t["}]/{o=0} /^\t"'"$langs"'"/{o=1;print}' $f
tmv "$f"
done done
[ ! $repack ] && [ ! $use_ox ] && { [ ! $repack ] && [ ! $use_ox ] && {
@ -466,10 +472,20 @@ rm have
# sed -ri '/: TypeAlias = /d' "$x"; done # sed -ri '/: TypeAlias = /d' "$x"; done
} }
f=j2/jinja2/constants.py rm -f j2/jinja2/constants.py
awk '/^LOREM_IPSUM_WORDS/{o=1;print "LOREM_IPSUM_WORDS = u\"a\"";next} !o; /"""/{o=0}' <$f >t iawk '/^ {4}def /{s=0}/^ {4}def compile_templates\(/{s=1}!s' j2/jinja2/environment.py
tmv "$f" ised '/generate_lorem_ipsum/d' j2/jinja2/defaults.py
rm -f j2/jinja2/async* iawk '/^def /{s=0}/^def generate_lorem_ipsum/{s=1}!s' j2/jinja2/utils.py
iawk '/^(class|def) /{s=0}/^(class InternationalizationExtension|def _make_new_n?gettext)/{s=1}!s' j2/jinja2/ext.py
iawk '/^[^ ]/{s=0}/^def babel_extract/{s=1}!s' j2/jinja2/ext.py
ised '/InternationalizationExtension/d' j2/jinja2/ext.py
iawk '/^class/{s=0}/^class (Package|Dict|Function|Prefix|Choice|Module)Loader/{s=1}!s' j2/jinja2/loaders.py
sed -ri '/^from .bccache | (Package|Dict|Function|Prefix|Choice|Module)Loader$/d' j2/jinja2/__init__.py
rm -f j2/jinja2/async* j2/jinja2/bccache.py
cat > j2/jinja2/_identifier.py <<'EOF'
import re
pattern = re.compile(r"\w+")
EOF
grep -rLE '^#[^a-z]*coding: utf-8' j2 | grep -rLE '^#[^a-z]*coding: utf-8' j2 |
while IFS= read -r f; do while IFS= read -r f; do

View file

@ -55,6 +55,11 @@ def uncomment(fpath):
out += '"a"' out += '"a"'
elif token_type != tokenize.COMMENT or is_legalese: elif token_type != tokenize.COMMENT or is_legalese:
out += token_string out += token_string
else:
if out.rstrip(" ").endswith("\n"):
out = out.rstrip() + "\n"
else:
out = out.rstrip()
prev_toktype = token_type prev_toktype = token_type
last_lineno = end_line last_lineno = end_line