Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Tue, 01 Jun 2021 22:22:59
Message-Id: 1622586148.61d0775971ad1f0a1a4a6cfbff6fb1f3eed95fff.mgorny@gentoo
1 commit: 61d0775971ad1f0a1a4a6cfbff6fb1f3eed95fff
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 21 13:15:11 2021 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Tue Jun 1 22:22:28 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=61d07759
7
8 distutils-r1.eclass: Introduce dift --via-venv install mode
9
10 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
11
12 eclass/distutils-r1.eclass | 96 ++++++++++++++++++++++++++++++----------------
13 1 file changed, 62 insertions(+), 34 deletions(-)
14
15 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
16 index a02b6d059bd..53eee173a26 100644
17 --- a/eclass/distutils-r1.eclass
18 +++ b/eclass/distutils-r1.eclass
19 @@ -481,7 +481,7 @@ esetup.py() {
20 }
21
22 # @FUNCTION: distutils_install_for_testing
23 -# @USAGE: [--via-root|--via-home] [<args>...]
24 +# @USAGE: [--via-root|--via-home|--via-venv] [<args>...]
25 # @DESCRIPTION:
26 # Install the package into a temporary location for running tests.
27 # Update PYTHONPATH appropriately and set TEST_DIR to the test
28 @@ -493,32 +493,36 @@ esetup.py() {
29 # PYTHONPATH) or tests rely on the results of install command.
30 # For most of the packages, tests built in BUILD_DIR are good enough.
31 #
32 -# The function supports two install modes. The current default is
33 -# --via-root mode. Previously, the function defaulted to --via-home
34 -# mode but it has been broken by new versions of setuptools (50.3.0+).
35 -# If you find that --via-root does not work but --via-home does, please
36 -# file a bug to let us know. Please note that proper testing sometimes
37 -# requires unmerging the package first.
38 +# The function supports three install modes. These are:
39 +#
40 +# --via-root (the default) that uses 'setup.py install --root=...'
41 +# combined with PYTHONPATH and is recommended for the majority
42 +# of packages.
43 +#
44 +# --via-venv that creates a (non-isolated) venv and installs the package
45 +# into it via 'setup.py install'. This mode does not use PYTHONPATH
46 +# but requires python to be called via PATH. It may solve a few corner
47 +# cases that --via-root do not support.
48 +#
49 +# --via-home that uses 'setup.py install --home=...'. This is
50 +# a historical mode that was mostly broken by setuptools 50.3.0+.
51 +# If your package does not work with the other two modes but works with
52 +# this one, please report a bug.
53 +#
54 +# Please note that in order to test the solution properly you need
55 +# to unmerge the package first.
56 distutils_install_for_testing() {
57 debug-print-function ${FUNCNAME} "${@}"
58
59 - # A few notes:
60 - # 1) because of namespaces, we can't use 'install --root'
61 - # (NB: this is probably no longer true with py3),
62 - # 2) 'install --home' is terribly broken on pypy, so we need
63 + # A few notes about --via-home mode:
64 + # 1) 'install --home' is terribly broken on pypy, so we need
65 # to override --install-lib and --install-scripts,
66 - # 3) non-root 'install' complains about PYTHONPATH and missing dirs,
67 + # 2) non-root 'install' complains about PYTHONPATH and missing dirs,
68 # so we need to set it properly and mkdir them,
69 - # 4) it runs a bunch of commands which write random files to cwd,
70 + # 3) it runs a bunch of commands which write random files to cwd,
71 # in order to avoid that, we add the necessary path overrides
72 # in _distutils-r1_create_setup_cfg.
73
74 - TEST_DIR=${BUILD_DIR}/test
75 - local bindir=${TEST_DIR}/scripts
76 - local libdir=${TEST_DIR}/lib
77 - PATH=${bindir}:${PATH}
78 - PYTHONPATH=${libdir}:${PYTHONPATH}
79 -
80 local install_method=root
81 case ${1} in
82 --via-home)
83 @@ -529,30 +533,50 @@ distutils_install_for_testing() {
84 install_method=root
85 shift
86 ;;
87 + --via-venv)
88 + install_method=venv
89 + shift
90 + ;;
91 esac
92
93 - local -a add_args
94 - case ${install_method} in
95 - home)
96 - add_args=(
97 - install
98 + TEST_DIR=${BUILD_DIR}/test
99 + local add_args=()
100 +
101 + if [[ ${install_method} == venv ]]; then
102 + "${EPYTHON}" -m venv --system-site-packages --without-pip \
103 + "${TEST_DIR}" || die
104 +
105 + # we only do the minimal necessary subset of activate script
106 + PATH=${TEST_DIR}/bin:${PATH}
107 + # unset PYTHONPATH in order to prevent BUILD_DIR from overriding
108 + # venv packages
109 + unset PYTHONPATH
110 + else
111 + local bindir=${TEST_DIR}/scripts
112 + local libdir=${TEST_DIR}/lib
113 + PATH=${bindir}:${PATH}
114 + PYTHONPATH=${libdir}:${PYTHONPATH}
115 +
116 + case ${install_method} in
117 + home)
118 + add_args=(
119 --home="${TEST_DIR}"
120 --install-lib="${libdir}"
121 --install-scripts="${bindir}"
122 - )
123 - mkdir -p "${libdir}" || die
124 - ;;
125 - root)
126 - add_args=(
127 - install
128 + )
129 + mkdir -p "${libdir}" || die
130 + ;;
131 + root)
132 + add_args=(
133 --root="${TEST_DIR}"
134 --install-lib=lib
135 --install-scripts=scripts
136 - )
137 - ;;
138 - esac
139 + )
140 + ;;
141 + esac
142 + fi
143
144 - esetup.py "${add_args[@]}" "${@}"
145 + esetup.py install "${add_args[@]}" "${@}"
146 }
147
148 # @FUNCTION: _distutils-r1_disable_ez_setup
149 @@ -646,6 +670,10 @@ _distutils-r1_create_setup_cfg() {
150 # setuptools like to create .egg files for install --home.
151 [bdist_egg]
152 dist_dir = ${BUILD_DIR}/dist
153 +
154 + # avoid packing up eggs in a zip as it often breaks test suites
155 + [options]
156 + zip_safe = False
157 _EOF_
158
159 # we can't refer to ${D} before src_install()