python

Elan Ruusamäe glen at delfi.ee
Mon Feb 14 20:50:55 CET 2005


hi

i don't know why there's need to package both pyc and pyo,
but i made macro that will hardlink them if they are identical.
the identical state is detected with md5sum

%py_hardlink()  \
for d in %{py_sitescriptdir} %{py_sitedir}; do \
    [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.pyc' | while read a; do \
        b=$(dirname "$a")/$(basename "$a" .pyc).pyo; \
  if [ $(md5sum -b "$a" | awk '{print $1}') = $(md5sum -b "$b" | awk '{print $1}') ]; then \
            ln -f "$a" "$b"; \
        fi; \
    done \
done \
%{nil}

just put it somewhere last in %install

some file sizes to compare

without .pyo files
- 200k veebr 14 21:27 trac-0.8-0.3.noarch.rpm

with .pyo and .pyc
- 229k veebr 14 21:32 trac-0.8-0.5.noarch.rpm

with hardlinked .pyo if identical to .pyc
- 214k veebr 14 21:48 trac-0.8-0.7.noarch.rpm







also another macro, which could go to rpm-macros
if the directory list properly filled (i don't know (yet) all of the python dirs)

# remove python sources, so that check-files won't complain
%py_postclean() \
for d in %{py_sitescriptdir} %{py_sitedir}; do \
 [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0 -r rm; \
done \
%{nil}




-- 
glen




More information about the pld-devel-en mailing list