Gentoo Archives: gentoo-dev

From: Mart Raudsepp <leio@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Enable hardlinking of identical pyc files for py3.9+
Date: Wed, 23 Jun 2021 09:36:20
Message-Id: e5e7cb64d12a86f6c8166c68181d083c42ab8ec0.camel@gentoo.org
1 Python 3.9 includes a new feature for compileall to automatically hardlink
2 different optimization level cache files if they are identical. Make use of it
3 for python_optimize for some space savings.
4 This however does not cover distutils use cases and python itself.
5 ---
6  eclass/python-utils-r1.eclass | 5 ++++-
7  1 file changed, 4 insertions(+), 1 deletion(-)
8
9 Note that I haven't actually tested this on py3.9, as I'm skipping that version.
10 It appears to do what it's meant to with py3.10
11
12 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
13 index 3dbf221eac5..e2f05606993 100644
14 --- a/eclass/python-utils-r1.eclass
15 +++ b/eclass/python-utils-r1.eclass
16 @@ -626,12 +626,15 @@ python_optimize() {
17                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
18                                 "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
19                                 ;;
20 -                       python*|pypy3)
21 +                       python3.[5678]|pypy3)
22                                 # both levels of optimization are separate since 3.5
23                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
24                                 "${PYTHON}" -O -m compileall -q -f -d "${instpath}" "${d}"
25                                 "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
26                                 ;;
27 +                       python*)
28 +                               "${PYTHON}" -m compileall -o 0 -o 1 -o 2 --hardlink-dupes -q -f -d "${instpath}" "${d}"
29 +                               ;;
30                         *)
31                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
32                                 ;;

Replies