1 |
Use generated setup.cfg file to propagate install paths rather than |
2 |
passing them via command-line arguments whenever possible, making it |
3 |
possible to call special install commands without forcing the main |
4 |
'install' command. |
5 |
|
6 |
For example, if setup.py defines install_doc command that reuses prefix |
7 |
from install, to use it you'd have to call either: |
8 |
|
9 |
esetup.py install --root="${D}" install_doc |
10 |
|
11 |
or: |
12 |
|
13 |
distutils-r1_python_install install_doc |
14 |
|
15 |
both of them forcing (re-)install of the whole package implicitly. |
16 |
|
17 |
Instead, we can reuse the setup.cfg file that was added specifically to |
18 |
solve a similar issue with build paths. Put the default root, byte- |
19 |
compilation options and script path (if applicable) there. |
20 |
distutils-r1_python_install still carries --root override for |
21 |
intermediate root install though. |
22 |
|
23 |
Thanks to this, you can run the fore-mentioned command like this: |
24 |
|
25 |
esetup.py install_doc |
26 |
--- |
27 |
eclass/distutils-r1.eclass | 68 +++++++++++++++++++++++++++++----------------- |
28 |
1 file changed, 43 insertions(+), 25 deletions(-) |
29 |
|
30 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
31 |
index 19d51b7..0d43513 100644 |
32 |
--- a/eclass/distutils-r1.eclass |
33 |
+++ b/eclass/distutils-r1.eclass |
34 |
@@ -217,6 +217,10 @@ fi |
35 |
# 1. ${mydistutilsargs[@]} |
36 |
# 2. additional arguments passed to the esetup.py function. |
37 |
# |
38 |
+# Please note that setup.py will respect defaults (unless overriden |
39 |
+# via command-line options) from setup.cfg that is created |
40 |
+# in distutils-r1_python_compile and in distutils-r1_python_install. |
41 |
+# |
42 |
# This command dies on failure. |
43 |
esetup.py() { |
44 |
debug-print-function ${FUNCNAME} "${@}" |
45 |
@@ -338,7 +342,7 @@ distutils-r1_python_configure() { |
46 |
# @INTERNAL |
47 |
# @DESCRIPTION: |
48 |
# Create implementation-specific configuration file for distutils, |
49 |
-# setting proper build-dir paths. |
50 |
+# setting proper build-dir (and install-dir) paths. |
51 |
_distutils-r1_create_setup_cfg() { |
52 |
cat > "${HOME}"/.pydistutils.cfg <<-_EOF_ || die |
53 |
[build] |
54 |
@@ -365,6 +369,25 @@ _distutils-r1_create_setup_cfg() { |
55 |
[bdist_egg] |
56 |
dist-dir = ${BUILD_DIR}/dist |
57 |
_EOF_ |
58 |
+ |
59 |
+ # we can't refer to ${D} before src_install() |
60 |
+ if [[ ${EBUILD_PHASE} == install ]]; then |
61 |
+ cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die |
62 |
+ |
63 |
+ # installation paths -- allow calling extra install targets |
64 |
+ # without the default 'install' |
65 |
+ [install] |
66 |
+ compile = True |
67 |
+ optimize = 2 |
68 |
+ root = ${D} |
69 |
+ _EOF_ |
70 |
+ |
71 |
+ if [[ ! ${DISTUTILS_SINGLE_IMPL} ]] && _python_want_python_exec2; then |
72 |
+ cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die |
73 |
+ install-scripts = $(python_get_scriptdir) |
74 |
+ _EOF_ |
75 |
+ fi |
76 |
+ fi |
77 |
} |
78 |
|
79 |
# @FUNCTION: _distutils-r1_copy_egg_info |
80 |
@@ -385,6 +408,9 @@ _distutils-r1_copy_egg_info() { |
81 |
# The default python_compile(). Runs 'esetup.py build'. Any parameters |
82 |
# passed to this function will be appended to setup.py invocation, |
83 |
# i.e. passed as options to the 'build' command. |
84 |
+# |
85 |
+# This phase also sets up initial setup.cfg with build directories |
86 |
+# and copies upstream egg-info files if supplied. |
87 |
distutils-r1_python_compile() { |
88 |
debug-print-function ${FUNCNAME} "${@}" |
89 |
|
90 |
@@ -406,8 +432,11 @@ _distutils-r1_wrap_scripts() { |
91 |
local path=${1} |
92 |
local bindir=${2} |
93 |
|
94 |
- if ! _python_want_python_exec2; then |
95 |
- local PYTHON_SCRIPTDIR=${bindir} |
96 |
+ local PYTHON_SCRIPTDIR |
97 |
+ if _python_want_python_exec2; then |
98 |
+ python_export PYTHON_SCRIPTDIR |
99 |
+ else |
100 |
+ PYTHON_SCRIPTDIR=${bindir} |
101 |
fi |
102 |
|
103 |
local f python_files=() non_python_files=() |
104 |
@@ -457,37 +486,29 @@ _distutils-r1_wrap_scripts() { |
105 |
# @FUNCTION: distutils-r1_python_install |
106 |
# @USAGE: [additional-args...] |
107 |
# @DESCRIPTION: |
108 |
-# The default python_install(). Runs 'esetup.py install', appending |
109 |
-# the optimization flags. Then renames the installed scripts. |
110 |
+# The default python_install(). Runs 'esetup.py install', doing |
111 |
+# intermediate root install and handling script wrapping afterwards. |
112 |
# Any parameters passed to this function will be appended |
113 |
# to the setup.py invocation (i.e. as options to the 'install' command). |
114 |
+# |
115 |
+# This phase updates the setup.cfg file with install directories. |
116 |
distutils-r1_python_install() { |
117 |
debug-print-function ${FUNCNAME} "${@}" |
118 |
|
119 |
local args=( "${@}" ) |
120 |
- local flags |
121 |
- |
122 |
- case "${EPYTHON}" in |
123 |
- jython*) |
124 |
- flags=(--compile);; |
125 |
- *) |
126 |
- flags=(--compile -O2);; |
127 |
- esac |
128 |
- debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}" |
129 |
|
130 |
# enable compilation for the install phase. |
131 |
local -x PYTHONDONTWRITEBYTECODE= |
132 |
|
133 |
+ # re-create setup.cfg with install paths |
134 |
+ _distutils-r1_create_setup_cfg |
135 |
+ |
136 |
# python likes to compile any module it sees, which triggers sandbox |
137 |
# failures if some packages haven't compiled their modules yet. |
138 |
addpredict "$(python_get_sitedir)" |
139 |
addpredict /usr/lib/portage/pym |
140 |
addpredict /usr/local # bug 498232 |
141 |
|
142 |
- local root=${D}/_${EPYTHON} |
143 |
- [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D} |
144 |
- flags+=( --root="${root}" ) |
145 |
- |
146 |
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then |
147 |
# user may override --install-scripts |
148 |
# note: this is poor but distutils argv parsing is dumb |
149 |
@@ -525,15 +546,12 @@ distutils-r1_python_install() { |
150 |
;; |
151 |
esac |
152 |
done |
153 |
- |
154 |
- if _python_want_python_exec2; then |
155 |
- local PYTHON_SCRIPTDIR |
156 |
- python_export PYTHON_SCRIPTDIR |
157 |
- flags+=( --install-scripts="${PYTHON_SCRIPTDIR}" ) |
158 |
- fi |
159 |
fi |
160 |
|
161 |
- esetup.py install "${flags[@]}" "${args[@]}" |
162 |
+ local root=${D}/_${EPYTHON} |
163 |
+ [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D} |
164 |
+ |
165 |
+ esetup.py install --root="${root}" "${args[@]}" |
166 |
|
167 |
if [[ -d ${root}$(python_get_sitedir)/tests ]]; then |
168 |
die "Package installs 'tests' package, file collisions likely." |
169 |
-- |
170 |
2.0.4 |