Re: [gentoo-dev] [PATCH] distutils-r1: set install paths via setup.cfg rather than argv.

2014-08-21 Thread Gilles Dartiguelongue
Le 21 août 2014 à 15:20, Michał Górny  a écrit :

> Use generated setup.cfg file to propagate install paths rather than
> passing them via command-line arguments whenever possible, making it
> possible to call special install commands without forcing the main
> 'install' command.
> 
> For example, if setup.py defines install_doc command that reuses prefix
> from install, to use it you'd have to call either:
> 
>  esetup.py install --root="${D}" install_doc
> 
> or:
> 
>  distutils-r1_python_install install_doc
> 
> both of them forcing (re-)install of the whole package implicitly.
> 
> Instead, we can reuse the setup.cfg file that was added specifically to
> solve a similar issue with build paths. Put the default root, byte-
> compilation options and script path (if applicable) there.
> distutils-r1_python_install still carries --root override for
> intermediate root install though.
> 
> Thanks to this, you can run the fore-mentioned command like this:
> 
>  esetup.py install_doc
> ---

Looks great.

-- 
Gilles Dartiguelongue 




[gentoo-dev] [PATCH] distutils-r1: set install paths via setup.cfg rather than argv.

2014-08-21 Thread Michał Górny
Use generated setup.cfg file to propagate install paths rather than
passing them via command-line arguments whenever possible, making it
possible to call special install commands without forcing the main
'install' command.

For example, if setup.py defines install_doc command that reuses prefix
from install, to use it you'd have to call either:

  esetup.py install --root="${D}" install_doc

or:

  distutils-r1_python_install install_doc

both of them forcing (re-)install of the whole package implicitly.

Instead, we can reuse the setup.cfg file that was added specifically to
solve a similar issue with build paths. Put the default root, byte-
compilation options and script path (if applicable) there.
distutils-r1_python_install still carries --root override for
intermediate root install though.

Thanks to this, you can run the fore-mentioned command like this:

  esetup.py install_doc
---
 eclass/distutils-r1.eclass | 68 +-
 1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 19d51b7..0d43513 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -217,6 +217,10 @@ fi
 # 1. ${mydistutilsargs[@]}
 # 2. additional arguments passed to the esetup.py function.
 #
+# Please note that setup.py will respect defaults (unless overriden
+# via command-line options) from setup.cfg that is created
+# in distutils-r1_python_compile and in distutils-r1_python_install.
+#
 # This command dies on failure.
 esetup.py() {
debug-print-function ${FUNCNAME} "${@}"
@@ -338,7 +342,7 @@ distutils-r1_python_configure() {
 # @INTERNAL
 # @DESCRIPTION:
 # Create implementation-specific configuration file for distutils,
-# setting proper build-dir paths.
+# setting proper build-dir (and install-dir) paths.
 _distutils-r1_create_setup_cfg() {
cat > "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
[build]
@@ -365,6 +369,25 @@ _distutils-r1_create_setup_cfg() {
[bdist_egg]
dist-dir = ${BUILD_DIR}/dist
_EOF_
+
+   # we can't refer to ${D} before src_install()
+   if [[ ${EBUILD_PHASE} == install ]]; then
+   cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
+
+   # installation paths -- allow calling extra install 
targets
+   # without the default 'install'
+   [install]
+   compile = True
+   optimize = 2
+   root = ${D}
+   _EOF_
+
+   if [[ ! ${DISTUTILS_SINGLE_IMPL} ]] && 
_python_want_python_exec2; then
+   cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
+   install-scripts = $(python_get_scriptdir)
+   _EOF_
+   fi
+   fi
 }
 
 # @FUNCTION: _distutils-r1_copy_egg_info
@@ -385,6 +408,9 @@ _distutils-r1_copy_egg_info() {
 # The default python_compile(). Runs 'esetup.py build'. Any parameters
 # passed to this function will be appended to setup.py invocation,
 # i.e. passed as options to the 'build' command.
+#
+# This phase also sets up initial setup.cfg with build directories
+# and copies upstream egg-info files if supplied.
 distutils-r1_python_compile() {
debug-print-function ${FUNCNAME} "${@}"
 
@@ -406,8 +432,11 @@ _distutils-r1_wrap_scripts() {
local path=${1}
local bindir=${2}
 
-   if ! _python_want_python_exec2; then
-   local PYTHON_SCRIPTDIR=${bindir}
+   local PYTHON_SCRIPTDIR
+   if _python_want_python_exec2; then
+   python_export PYTHON_SCRIPTDIR
+   else
+   PYTHON_SCRIPTDIR=${bindir}
fi
 
local f python_files=() non_python_files=()
@@ -457,37 +486,29 @@ _distutils-r1_wrap_scripts() {
 # @FUNCTION: distutils-r1_python_install
 # @USAGE: [additional-args...]
 # @DESCRIPTION:
-# The default python_install(). Runs 'esetup.py install', appending
-# the optimization flags. Then renames the installed scripts.
+# The default python_install(). Runs 'esetup.py install', doing
+# intermediate root install and handling script wrapping afterwards.
 # Any parameters passed to this function will be appended
 # to the setup.py invocation (i.e. as options to the 'install' command).
+#
+# This phase updates the setup.cfg file with install directories.
 distutils-r1_python_install() {
debug-print-function ${FUNCNAME} "${@}"
 
local args=( "${@}" )
-   local flags
-
-   case "${EPYTHON}" in
-   jython*)
-   flags=(--compile);;
-   *)
-   flags=(--compile -O2);;
-   esac
-   debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
 
# enable compilation for the install phase.
local -x PYTHONDONTWRITEBYTECODE=
 
+   # re-create setup.cfg with install paths
+   _distutils-r1_create_setu