Re: Hardlinking *.pyc and *.pyo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 03 April 2007, Ville Skyttä wrote:
> Hello,
>
> Related to recent space saving discussions, I came across PLD's
> rpm-build-macros package recently, and found that they hardlink
> identical *.pyc and *.pyo.
[...]
> The PLD implementation looks like this:
[...]
> The use of "cmp" would require diffutils installed.  Or the above
> could be converted to use hardlink instead (which would have to be made
> sure to be around) or maybe sha1sum (in coreutils, pretty much always
> around in buildroots).
>
> I suppose something like the above could be easily added to
> redhat-rpm-config or rpm, eg. embedded in brp-python-bytecompile
> or run after it in %__os_install_post.

Jeremy pinged me about resurrecting this thread, so here goes, the original 
threads starts at 
http://www.redhat.com/archives/fedora-packaging/2007-April/msg00003.html for 
those who missed it.

Anyway, attached is a patch against rpm.org hg for discussion - seems somewhat 
clumsy to use sha1sum for this but I guess it could be acceptable.  Tested on 
just a few python packages on F-7.  Better implementations certainly exist, 
and are welcome :)
diff -r 7db24f0e47a5 scripts/brp-python-bytecompile
--- a/scripts/brp-python-bytecompile	Tue Jun 12 11:22:49 2007 +0300
+++ b/scripts/brp-python-bytecompile	Tue Apr 17 00:06:12 2007 +0300
@@ -24,3 +24,16 @@ fi
 
 # Generate optimized (.pyo) byte-compiled files.
 $python -O -c 'import compileall; compileall.compile_dir("'"$RPM_BUILD_ROOT"'", '"$depth"', "/", 1)' > /dev/null
+
+# Hardlink identical *.pyc and *.pyo, originally from PLD's rpm-build-macros
+# Modified to use sha1sum instead of cmp to avoid a diffutils dependency.
+find "$RPM_BUILD_ROOT" -type f -name "*.pyc" | while read pyc ; do
+	pyo="$(echo $pyc | sed -e 's/.pyc$/.pyo/')"
+	if [ -f "$pyo" ] ; then
+		csha="$(sha1sum -b $pyc | cut -d' ' -f 1)" && \
+		osha="$(sha1sum -b $pyo | cut -d' ' -f 1)" && \
+		if [ "$csha" = "$osha" ] ; then
+			ln -f "$pyc" "$pyo"
+		fi
+	fi
+done
--
Fedora-packaging mailing list
Fedora-packaging@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-packaging

[Index of Archives]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Forum]     [KDE Users]

  Powered by Linux