Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] Writing an ebuild to install a python package
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Sat Apr 15, 2017 1:28 pm    Post subject: [solved] Writing an ebuild to install a python package Reply with quote

Hello,

I just modified an ebuild ("cxxtest-4.4.ebuild") such that it installs an additional python package. The python package (including setup.py) is located in a subfolder named "python", so the ebuild makes a "cd" to the python directory:

Code:
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=6

PYTHON_COMPAT=(python{3_4,3_5})
inherit distutils-r1

DESCRIPTION="CxxTest is a JUnit/CppUnit/xUnit-like unit testing framework for C++"
HOMEPAGE="http://cxxtest.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~arm ~x86"
IUSE="examples doc python"

RDEPEND="dev-lang/perl"

DEPEND="${RDEPEND}
        dev-python/setuptools[${PYTHON_USEDEP}]
"

src_install() {
        dobin bin/cxxtestgen

        insinto /usr/include/cxxtest
        doins cxxtest/*

        dodoc README Versions COPYING

        use doc && dodoc -r doc
        use examples && dodoc -r sample

        if use python; then
                cd python
                distutils-r1_python_install
                cd ..
        fi
}


However, portage still fails, saying that it cannot find the setup.py and it is not in the python subdirectory:

Code:

/usr/bin/python3.4 setup.py build
/usr/bin/python3.4: can't open file 'setup.py': [Errno 2] No such file or directory
 * ERROR: dev-util/cxxtest-4.4::localaudio failed (compile phase):
 *   (no error message)
 *
 * Call stack:
 *     ebuild.sh, line  115:  Called src_compile
 *   environment, line 2627:  Called distutils-r1_src_compile
 *   environment, line  774:  Called _distutils-r1_run_foreach_impl 'distutils-r1_python_compile'
 *   environment, line  316:  Called python_foreach_impl 'distutils-r1_run_phase' 'distutils-r1_python_compile'
 *   environment, line 2166:  Called multibuild_foreach_variant '_python_multibuild_wrapper' 'distutils-r1_run_phase' 'distutils-r1_python_compile'
 *   environment, line 1474:  Called _multibuild_run '_python_multibuild_wrapper' 'distutils-r1_run_phase' 'distutils-r1_python_compile'
 *   environment, line 1472:  Called _python_multibuild_wrapper 'distutils-r1_run_phase' 'distutils-r1_python_compile'
 *   environment, line  507:  Called distutils-r1_run_phase 'distutils-r1_python_compile'
 *   environment, line  765:  Called distutils-r1_python_compile
 *   environment, line  640:  Called esetup.py 'build'
 *   environment, line 1019:  Called die
 * The specific snippet of code:
 *       "${@}" || die "${die_args[@]}";
 *
 * If you need support, post the output of `emerge --info '=dev-util/cxxtest-4.4::localaudio'`,
 * the complete build log and the output of `emerge -pqv '=dev-util/cxxtest-4.4::localaudio'`.
 * The complete build log is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/build.log'.
 * The ebuild environment file is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/environment'.
 * Working directory: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4'
 * S: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4'


Can someone please explain why portage is in the wrong directory and what I can do to fix this issue?

Thanks + Regards,
Johannes


Last edited by CPUFan on Fri Apr 21, 2017 3:24 pm; edited 1 time in total
Back to top
View user's profile Send private message
Juippisi
Developer
Developer


Joined: 30 Sep 2005
Posts: 724
Location: /home

PostPosted: Sun Apr 16, 2017 10:10 am    Post subject: Reply with quote

Try putting

Code:

cd ${S}


before that. Also might be a good idea to call python_compile in src_compile....?
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Sun Apr 16, 2017 12:01 pm    Post subject: Reply with quote

Juippisi wrote:
Try putting

Code:

cd ${S}


before that.


I did, but it did not change anything.

Quote:
Also might be a good idea to call python_compile in src_compile....?


Actually, I thought this would be useless due to the line
Code:
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install

in the distutils-r1 eclass, somehow, it changed the error. Now, with

Code:
src_compile() {
       distutils-r1_python_compile
}


it is complaining about a mkdir call.

Code:
mkdir: cannot create directory ‘’: No such file or directory
 * ERROR: dev-util/cxxtest-4.4::localaudio failed (compile phase):
 *   (no error message)
 *
 * Call stack:
 *     ebuild.sh, line  115:  Called src_compile
 *   environment, line 2628:  Called distutils-r1_python_compile
 *   environment, line  640:  Called _distutils-r1_copy_egg_info
 *   environment, line  227:  Called die
 * The specific snippet of code:
 *       mkdir -p "${BUILD_DIR}" || die;
 *
 * If you need support, post the output of `emerge --info '=dev-util/cxxtest-4.4::localaudio'`,
 * the complete build log and the output of `emerge -pqv '=dev-util/cxxtest-4.4::localaudio'`.
 * The complete build log is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/build.log'.
 * The ebuild environment file is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/environment'.
 * Working directory: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4'
 * S: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4'


Why does this error occur? Also, why does src_compile not call distutils-r1_python_compile by default?
Back to top
View user's profile Send private message
Juippisi
Developer
Developer


Joined: 30 Sep 2005
Posts: 724
Location: /home

PostPosted: Sun Apr 16, 2017 1:41 pm    Post subject: Reply with quote

CPUFan wrote:

Code:
src_compile() {
       distutils-r1_python_compile
}




What if you try something following:

Code:

src_compile() {

   cd python
   esetup.py install --root="${D}"/usr

}

root or prefix, you might have to copy the files manually in src_install.
python and ebuilds... :(
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21631

PostPosted: Sun Apr 16, 2017 3:50 pm    Post subject: Reply with quote

$D should not be used during src_compile. Upstream should take the --root= argument in src_compile as the path at which the files will be placed when they are installed in the live system. That path is not under $D.
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Tue Apr 18, 2017 6:07 pm    Post subject: Reply with quote

I don't even have an idea how to start. Everything I do either fails with insufficient rights, no setup.py or any python errors I don't understand.

Should I call esetup.py or "distutils-r1-..." in src_build and src_install? Also, can someone explain why I should use which? Finally, what arguments must I pass?
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9527
Location: beyond the rim

PostPosted: Wed Apr 19, 2017 10:45 am    Post subject: Reply with quote

Well, lets go this step by step:
- the original error message comes from src_compile actually calling distutils_src_compile in the wrong directory, as your "cd python" is only present in src_install
- in your second post the error likely comes because you override the default src_compile implementation, so neither are you in the python subdirectory nor is the non-python part of the package built

Assuming that the package actually compiles some non-python sources you probably want to have your src_compile look like this:

Code:

src_compile() {
    default_src_compile
    if use python; then
        cd python
        distutils-r1_python_compile_all
        cd ..
    fi
}
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Wed Apr 19, 2017 6:45 pm    Post subject: Reply with quote

Genone wrote:
in your second post the error likely comes because you override the default src_compile implementation, so neither are you in the python subdirectory nor is the non-python part of the package built

Actually the project does not require compiling, it's just a bunch of headers that needs to be installed, so this should be fine.

Genone wrote:
the original error message comes from src_compile actually calling distutils_src_compile in the wrong directory, as your "cd python" is only present in src_install

Thanks, that makes sense, but now I'm getting a different error (it's complaining about a missing BUILD_DIR). However, neither the eclass sets it, nor do other packages (like e.g. youtube-dl) set it. Who should set BUILD_DIR?

Code:
>>> Preparing source in /crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4 ...
>>> Source prepared.
>>> Configuring source in /crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4 ...
>>> Source configured.
>>> Compiling source in /crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4 ...
mkdir: cannot create directory ‘’: No such file or directory
 * ERROR: dev-util/cxxtest-4.4::localaudio failed (compile phase):
 *   (no error message)
 *
 * Call stack:
 *     ebuild.sh, line  115:  Called src_compile
 *   environment, line 2630:  Called distutils-r1_python_compile
 *   environment, line  640:  Called _distutils-r1_copy_egg_info
 *   environment, line  227:  Called die
 * The specific snippet of code:
 *       mkdir -p "${BUILD_DIR}" || die;
 *
 * If you need support, post the output of `emerge --info '=dev-util/cxxtest-4.4::localaudio'`,
 * the complete build log and the output of `emerge -pqv '=dev-util/cxxtest-4.4::localaudio'`.
 * The complete build log is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/build.log'.
 * The ebuild environment file is located at '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/temp/environment'.
 * Working directory: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4/python'
 * S: '/crap/tmp/portage/portage/dev-util/cxxtest-4.4/work/cxxtest-4.4'


Code:
# everything above like in 1st post

src_prepare() {
    cd python
        distutils-r1_src_prepare
    cd ..
}

src_configure() {
    cd python
        distutils-r1_src_configure
    cd ..
}

src_compile() {

    if use python; then
        cd python
            distutils-r1_python_compile
        cd ..
    fi

}

src_install() {
    dobin bin/cxxtestgen

    insinto /usr/include/cxxtest
    doins cxxtest/*

    dodoc README Versions COPYING

    use doc && dodoc -r doc
    use examples && dodoc -r sample

    if use python; then
        cd python
            distutils-r1_python_install_all
        cd -
    fi
}
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9527
Location: beyond the rim

PostPosted: Fri Apr 21, 2017 1:04 pm    Post subject: Reply with quote

Seems BUILD_DIR comes from python-r1.eclass, which is used by distutils-r1.eclass:

Quote:
# @ECLASS-VARIABLE: BUILD_DIR
# @DESCRIPTION:
# The current build directory. In global scope, it is supposed to
# contain an initial build directory; if unset, it defaults to ${S}.
#
# In functions run by python_foreach_impl(), the BUILD_DIR is locally
# set to an implementation-specific build directory. That path is
# created through appending a hyphen and the implementation name
# to the final component of the initial BUILD_DIR.
#
# Example value:
# @CODE
# ${WORKDIR}/foo-1.3-python2_7
# @CODE


Not quite certain if you have to set it to your python subdir or what as I'm not really familiar with all the python multi-abi stuff.
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Fri Apr 21, 2017 3:24 pm    Post subject: Reply with quote

Genone wrote:
Seems BUILD_DIR comes from python-r1.eclass, which is used by distutils-r1.eclass:


Ah, I did not see this. Great, it works now! Many thanks!

Just if someone is curious, this is the whole ebuild now:

Code:
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=6

PYTHON_COMPAT=(python{3_4,3_5})
inherit distutils-r1

DESCRIPTION="CxxTest is a JUnit/CppUnit/xUnit-like unit testing framework for C++"
HOMEPAGE="http://cxxtest.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~arm ~x86"
IUSE="examples doc python"

RDEPEND="dev-lang/perl"

DEPEND="${RDEPEND}
        dev-python/setuptools[${PYTHON_USEDEP}]
"

# python-r1 requires this to know that we are building in the python subdir
BUILD_DIR=${S}/python

src_prepare()
{
        if use python
        then
                cd python
                distutils-r1_src_prepare
                cd ..
        fi
}

src_configure()
{
        if use python
        then
                cd python
                        distutils-r1_src_configure
                cd ..
        fi
}

src_compile()
{
        if use python
        then
                cd python
                        distutils-r1_python_compile
                cd ..
        fi
}

src_install()
{
        dobin bin/cxxtestgen

        insinto /usr/include/cxxtest
        doins cxxtest/*

        dodoc README Versions COPYING

        use doc && dodoc -r doc
        use examples && dodoc -r sample

        if use python
        then
                cd python
                        distutils-r1_python_install_all
                cd ..
        fi
}
Back to top
View user's profile Send private message
Petross404
n00b
n00b


Joined: 27 Sep 2016
Posts: 55

PostPosted: Sat Apr 22, 2017 9:58 pm    Post subject: Reply with quote

@CPUFan do you mind if I use your ebuild and/or show it to some devs in the #gentoo-proxy-maint?
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Sat Apr 22, 2017 10:52 pm    Post subject: Reply with quote

Petross404 wrote:
@CPUFan do you mind if I use your ebuild and/or show it to some devs in the #gentoo-proxy-maint?


That would be nice.

However, I just found out that the ebuild does an installation under the portage tempdir (which is being removed). There must be an error in the ebuild's installation, and I haven't yet found out what it is.
Back to top
View user's profile Send private message
Petross404
n00b
n00b


Joined: 27 Sep 2016
Posts: 55

PostPosted: Sat Apr 22, 2017 11:00 pm    Post subject: Reply with quote

CPUFan wrote:
Petross404 wrote:
@CPUFan do you mind if I use your ebuild and/or show it to some devs in the #gentoo-proxy-maint?


That would be nice.

However, I just found out that the ebuild does an installation under the portage tempdir (which is being removed). There must be an error in the ebuild's installation, and I haven't yet found out what it is.


I will check this the next days :) Thank you.
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Thu Apr 27, 2017 3:48 pm    Post subject: Reply with quote

Thanks to one of the devs (grknight from #gentoo-dev-help) it all seems to work now. Below is the whole ebuild.

Code:
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

PYTHON_COMPAT=( python{3_4,3_5} )
inherit distutils-r1

DESCRIPTION="CxxTest is a JUnit/CppUnit/xUnit-like unit testing framework for C++"
HOMEPAGE="http://cxxtest.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~arm ~x86"
IUSE="examples doc"

DEPEND="dev-python/setuptools[${PYTHON_USEDEP}]"

# python-r1 requires this to know that we are building in the python subdir
BUILD_DIR="${S}/python"

src_prepare()
{
   pushd python > /dev/null || die
   distutils-r1_src_prepare
   popd > /dev/null || die
}

src_configure()
{
   pushd python > /dev/null || die
   distutils-r1_src_configure
   popd > /dev/null || die
}

src_compile()
{
   pushd python > /dev/null || die
   distutils-r1_src_compile
   popd > /dev/null || die
}

src_install()
{
   insinto /usr/include/cxxtest
   doins cxxtest/*

   dodoc README Versions COPYING

   use doc && dodoc -r doc
   use examples && dodoc -r sample

   pushd python > /dev/null || die
   distutils-r1_src_install
   popd > /dev/null || die
}
Back to top
View user's profile Send private message
CPUFan
n00b
n00b


Joined: 21 May 2015
Posts: 58

PostPosted: Thu Apr 27, 2017 5:35 pm    Post subject: Reply with quote

grknight just proposed a shorter version, which should be equivalent, I haven't had time to test it though:
Code:
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

PYTHON_COMPAT=( python{3_4,3_5} )
inherit distutils-r1

DESCRIPTION="CxxTest is a JUnit/CppUnit/xUnit-like unit testing framework for C++"
HOMEPAGE="http://cxxtest.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~arm ~x86"
IUSE="examples doc"

DEPEND="dev-python/setuptools[${PYTHON_USEDEP}]"
S="${S}/python"

src_install()
{
   distutils-r1_src_install
   cd "${WORKDIR}/${P}" || die
   insinto /usr/include/cxxtest
   doins cxxtest/*

   dodoc README Versions

   use doc && dodoc -r doc
   use examples && dodoc -r sample
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum