Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 835462 - python-r1.eclass: examples of python_check_deps() should use has_version -b
Summary: python-r1.eclass: examples of python_check_deps() should use has_version -b
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Python Gentoo Team
URL: https://github.com/gentoo/gentoo/pull...
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2022-03-17 05:24 UTC by Matt Whitlock
Modified: 2023-08-19 18:28 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Whitlock 2022-03-17 05:24:16 UTC
The python_check_deps() examples given in the python-r1.eclass documentation of the python_gen_any_dep and python_setup functions are incorrect. The default behavior of has_version is to check the *runtime* system (RDEPEND), but python_check_deps() is meant to check that the *build* system (BDEPEND) has a suitable Python environment. Therefore, python_check_deps() should be calling has_version with the -b option. The examples fail to do this and thus likely are leading developers to write incorrect python_check_deps() functions in their ebuilds.

----------------

Incorrect:

BDEPEND="$(python_gen_any_dep '
dev-python/foo[${PYTHON_SINGLE_USEDEP}]
|| ( dev-python/bar[${PYTHON_USEDEP}]
        dev-python/baz[${PYTHON_USEDEP}] )' -2)"

python_check_deps() {
has_version "dev-python/foo[${PYTHON_SINGLE_USEDEP}]" \
        && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
                || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
}

Correct:

BDEPEND="$(python_gen_any_dep '
dev-python/foo[${PYTHON_SINGLE_USEDEP}]
|| ( dev-python/bar[${PYTHON_USEDEP}]
        dev-python/baz[${PYTHON_USEDEP}] )' -2)"

python_check_deps() {
has_version -b "dev-python/foo[${PYTHON_SINGLE_USEDEP}]" \
        && { has_version -b "dev-python/bar[${PYTHON_USEDEP}]" \
                || has_version -b "dev-python/baz[${PYTHON_USEDEP}]"; }
}

----------------

Incorrect:

BDEPEND="doc? (
$(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )"

python_check_deps() {
has_version "dev-python/epydoc[${PYTHON_USEDEP}]"
}

Correct:

BDEPEND="doc? (
$(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )"

python_check_deps() {
has_version -b "dev-python/epydoc[${PYTHON_USEDEP}]"
}
Comment 1 Matt Whitlock 2022-03-17 05:33:03 UTC
Same problem in python-any-r1.eclass.
Comment 2 Matt Whitlock 2022-03-18 01:20:50 UTC
Looking at this again, that second example is still incorrect even after the addition of -b because its python_check_deps() function doesn't check the "doc" USE flag.

----------------

Incorrect:

BDEPEND="doc? (
$(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )"

python_check_deps() {
has_version "dev-python/epydoc[${PYTHON_USEDEP}]"
}

Correct:

BDEPEND="doc? (
$(python_gen_any_dep 'dev-python/epydoc[${PYTHON_USEDEP}]' 'python2*') )"

python_check_deps() {
use !doc || has_version -b "dev-python/epydoc[${PYTHON_USEDEP}]"
}
Comment 3 Matt Whitlock 2022-03-18 01:53:08 UTC
Note, I'm not reporting a problem with the code. I'm reporting a problem with the documentation. That's why I filed this under Documentation, Devmanual. I apologize if that was the incorrect classification.
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-03-18 02:17:33 UTC
(In reply to Matt Whitlock from comment #3)
> Note, I'm not reporting a problem with the code. I'm reporting a problem
> with the documentation. That's why I filed this under Documentation,
> Devmanual. I apologize if that was the incorrect classification.

Sorry, I should've commented: it's that eclassdocs are actually within eclasses => assign to eclass maintainers.

The reference eclass documentation appears within the devmanual but it's generated from elsewhere (the eclasses themselves).
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-03-18 08:20:29 UTC
Care to submit a PR?  I suppose you can use python_has_version instead which defaults to -b.
Comment 6 Matt Whitlock 2022-03-18 23:30:44 UTC
(In reply to Michał Górny from comment #5)
> I suppose you can use python_has_version instead which defaults to -b.

python_has_version is nice. Thanks for the tip.

> Care to submit a PR?

Done. https://github.com/gentoo/gentoo/pull/24647
Comment 7 Larry the Git Cow gentoo-dev 2023-08-19 18:28:17 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f80b0acf7f78971b601aabb913e067a0dde70268

commit f80b0acf7f78971b601aabb913e067a0dde70268
Author:     Matt Whitlock <gentoo@mattwhitlock.name>
AuthorDate: 2022-03-18 21:44:05 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2023-08-19 18:28:11 +0000

    python{,-any}-r1.eclass: use python_has_version in examples
    
    The python_check_deps() examples given in the documentation of several
    functions and variables in python-r1.eclass and python-any-r1.eclass are
    incorrect. The default behavior of has_version() is to check the
    *runtime* system (RDEPEND), but python_check_deps() is meant to check
    that the *build* system (BDEPEND) has a suitable Python environment. The
    examples fail to do this and thus likely are leading developers to write
    incorrect python_check_deps() functions in their ebuilds. Thankfully,
    python-utils-r1.eclass supplies a python_has_version() function that
    defaults to checking the build system and implements some other
    enhancements that make it nicer for use in python_check_deps(). Change
    the examples to use python_has_version.
    
    Closes: https://bugs.gentoo.org/835462
    Signed-off-by: Matt Whitlock <gentoo@mattwhitlock.name>
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 eclass/python-any-r1.eclass |  6 +++---
 eclass/python-r1.eclass     | 10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)