Gentoo Archives: gentoo-dev

From: Mart Raudsepp <leio@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH 2/2] python-utils-r1.eclass: Enable parallel bytecompile compilation
Date: Wed, 23 Jun 2021 09:36:44
Message-Id: 6e2af38b108ca1dbc166b7638c041bf57994e0a8.camel@gentoo.org
1 Python 3.5 added support for compileall to run parallel workers for
2 performing bytecode compilation. Make use of it to the extent
3 possible without refactoring the code too much to get different
4 paths into the same call for best possible parallelization.
5 ---
6  eclass/python-utils-r1.eclass | 16 +++++++++++-----
7  1 file changed, 11 insertions(+), 5 deletions(-)
8
9 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
10 index e2f05606993..f7a38f8c4e0 100644
11 --- a/eclass/python-utils-r1.eclass
12 +++ b/eclass/python-utils-r1.eclass
13 @@ -34,7 +34,7 @@ fi
14  
15  if [[ ! ${_PYTHON_UTILS_R1} ]]; then
16  
17 -inherit toolchain-funcs
18 +inherit multiprocessing toolchain-funcs
19  
20  # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
21  # @INTERNAL
22 @@ -615,6 +615,12 @@ python_optimize() {
23                 debug-print "${FUNCNAME}: using sys.path: ${*/%/;}"
24         fi
25  
26 +       local jobs=$(makeopts_jobs "${MAKEOPTS}" INF)
27 +       if [[ ${jobs} == INF ]]; then
28 +               local nproc=$(get_nproc)
29 +               jobs=$(( nproc + 1 ))
30 +       fi
31 +
32         local d
33         for d; do
34                 # make sure to get a nice path without //
35 @@ -628,12 +634,12 @@ python_optimize() {
36                                 ;;
37                         python3.[5678]|pypy3)
38                                 # both levels of optimization are separate since 3.5
39 -                               "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
40 -                               "${PYTHON}" -O -m compileall -q -f -d "${instpath}" "${d}"
41 -                               "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
42 +                               "${PYTHON}" -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}"
43 +                               "${PYTHON}" -O -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}"
44 +                               "${PYTHON}" -OO -m compileall -j "${jobs}" -q -f -d "${instpath}" "${d}"
45                                 ;;
46                         python*)
47 -                               "${PYTHON}" -m compileall -o 0 -o 1 -o 2 --hardlink-dupes -q -f -d "${instpath}" "${d}"
48 +                               "${PYTHON}" -m compileall -j "${jobs}" -o 0 -o 1 -o 2 --hardlink-dupes -q -f -d "${instpath}" "${d}"
49                                 ;;
50                         *)
51                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"

Replies