Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 940642 - dev-python/google-api-core is missing a dependency
Summary: dev-python/google-api-core is missing a dependency
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Patrick McLean
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-02 12:04 UTC by Roman
Modified: 2024-10-23 15:02 UTC (History)
3 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 Roman 2024-10-02 12:04:35 UTC
Hello!
I noticed that when I run one program that depends on this library, an error is generated:
-----------
    from google.api_core.gapic_v1 import config
  File "/usr/lib/python3.12/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
    import grpc
-----------

While figuring it out I noticed that the grpcio ebuild was missing. I tried adding this ebuild and after the build it started working as it should.


dev-python/grpcio-1.66.2.ebuild:

-----------
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{11..12} )
DISTUTILS_USE_PEP517=setuptools
inherit distutils-r1 multiprocessing prefix pypi

DESCRIPTION="High-performance RPC framework (python libraries)"
HOMEPAGE="https://grpc.io"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64 arm arm64 x86"

RDEPEND="
        dev-libs/openssl[-bindist(-)]
        dev-libs/re2
        dev-python/protobuf-python[${PYTHON_USEDEP}]
        dev-python/six[${PYTHON_USEDEP}]
        net-dns/c-ares
        sys-libs/zlib
"

BDEPEND="${RDEPEND}
        dev-python/cython[${PYTHON_USEDEP}]"

distutils_enable_tests pytest
-----------

At the moment it turns out that the python-api-core library does not work without the grpcio package. This issue applies to all versions of this package in gentoo.
Comment 1 Roman 2024-10-03 10:58:37 UTC
Reproducing the problem:
----
>>> from google.api_core import gapic_v1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/usr/lib/python3.12/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
    import grpc
ModuleNotFoundError: No module named 'grpc'
----

This is used in packages such as google-ai-generativelanguage and google-generativeai. These packages are not included with Gentoo, but would be useful as they provide access to Gemini AI.
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-03 11:27:48 UTC
Does grpcio actually pass tests?  We have removed it before because it was unmaintained (in Gentoo).
Comment 3 Roman 2024-10-03 12:02:11 UTC
(In reply to Michał Górny from comment #2)
> Does grpcio actually pass tests?  We have removed it before because it was
> unmaintained (in Gentoo).

Yes, examples at this address https://lisafc.github.io/grpc.github.io/docs/quickstart/python.html work. Google-generativeai also works fine with Gemini AI. You can check using ebuilds from this commit: https://github.com/ormorph/sleepy-tree/commit/36656169335c2d92379390f90122b3631460e09c .
A simple example of getting a list of models:
----
import google.generativeai as genai

####Use proxy######
#os.environ['ALL_PROXY'] = 'YOUR HTTP PROXY'
#genai.configure(api_key="YOUR KEY",  transport="rest")

genai.configure(api_key="YOUR KEY")

for x in genai.list_models():
    print(x)
----

I don't see any problems with adding this package. Maybe someone can point out another reason why this package should not be added.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-03 12:04:39 UTC
I'm asking about src_test().  The one you've added to the ebuild via distutils_enable_tests.
Comment 5 Roman 2024-10-03 12:18:46 UTC
(In reply to Michał Górny from comment #4)
> I'm asking about src_test().  The one you've added to the ebuild via
> distutils_enable_tests.

Now I'll try to rebuild the cyclic dependencies, then I'll run the build. I will let you know the result.
Comment 6 Roman 2024-10-03 12:39:24 UTC
With the test flag the build goes fine, now I'll check this command:
----
ebuild grpcio-1.66.2.ebuild test
----
This will take time.
Comment 7 Roman 2024-10-03 13:11:28 UTC
The test command does not pass, there are still not enough packages for the test flag. Out: https://bpa.st/TLH34
Apparently, this is also needed for the test:
https://github.com/google/googletest
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-03 13:13:16 UTC
Looks like it's collecting files that aren't the package's tests.
Comment 9 Roman 2024-10-03 13:19:53 UTC
I'll try adding this package later and run the test again.
Comment 10 Roman 2024-10-03 16:10:51 UTC
Hmm I looked through the code a bit. It is not correct to check it with pytest here, since it is a cut from the project https://github.com/grpc/grpc, i.e. it is not complete. The grpcio source code only includes the part needed for python. This is the same source code as for net-libs/grpc, but it has the part needed to build for python selected. I think the best solution is to remove test from the assembly.
Comment 11 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-03 17:57:57 UTC
I'm sorry, but we're not going to reintroduce a previously removed package without working tests.  The dependency in google-api-* is "runtime optional", and as such doesn't have to be provided by Gentoo.
Comment 12 Roman 2024-10-04 07:52:08 UTC
I looked at this source code, there are no tests for grpcio at all, so there is no point in adding a test. We can add files not related to grpcio checking to ignore, but then there will be no test files left and the checking process will end with the message "no tests ran in **s". Accordingly, this will be perceived as an error, since pytest will return a value>0.

example:
-------------
python_test() {
        local EPYTEST_IGNORE=(
                third_party/boringssl-with-bazel/src/third_party/googletest/googletest/test/gtest_xml_outfiles_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googletest/test/gtest_skip_check_output_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googletest/test/gtest_skip_environment_check_output_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googletest/test/gtest_help_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googletest/test/gtest_testbridge_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googlemock/test/gmock_leak_test.py
                third_party/boringssl-with-bazel/src/third_party/googletest/googlemock/test/gmock_output_test.py
                third_party/upb/upb/cmake/staleness_test.py
        )
        epytest
}
-------------
In other words, there is no test for this package at all
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-04 07:53:46 UTC
https://github.com/grpc/grpc/tree/master/src/python/grpcio_tests

Looks like they keep it in a separate package?
Comment 14 Roman 2024-10-04 08:12:41 UTC
Here I compiled it from git, adding the target to the ebuild. 
------
EGIT_REPO_URI="https://github.com/grpc/grpc"
EGIT_BRANCH="v1.66.x"
------
This is what the test shows: https://bpa.st/HO4UA
At the moment I see an error in pytest itself, since no tests have been performed, and the test has already failed. If you just run this module, it runs normally, but for some reason the module does not run in pytest. At the moment this is a problem with pytest itself.
Comment 15 Roman 2024-10-04 09:30:13 UTC
I looked at the module launch, yes, there are problems.
-----test.py------
import grpc
------------------
python -m trace --count test.py
------------------
There it complains about missing files with the .cover extension. Moreover, this problem concerns not only the version of the gentoo build, but also the version installed via pip. Because of this, it is better not to run this module in the try block.
Comment 16 Roman 2024-10-04 09:50:48 UTC
I made a mistake, there was simply no directory specified in the command for cover. Just the wrong trace command.
Comment 17 Roman 2024-10-04 10:29:46 UTC
I looked again and the test itself was incorrect.
----
import sys

try:
    import grpc
except ImportError:
    pass
else:
    sys.exit("Unexpectedly able to import grpc")
----
Here else: needs to be replaced with except:. Well, there are a lot of unnecessary tests that are not related to the drafting of the project. I think if you clean the project, the test will pass normally.
Comment 18 Roman 2024-10-04 11:47:38 UTC
I looked at the source code, for a normal test you need to install additional packages:
----------------
grpcio_admin
grpcio_channelz
grpcio_csds
grpcio_csm_observability
grpcio_health_checking
grpcio_observability
grpcio_reflection
grpcio_status
grpcio_testing
----------------

There is no test just for grpcio. The tests are located in this directory: https://github.com/grpc/grpc/tree/master/src/python/grpcio_tests
Comment 19 Roman 2024-10-04 18:53:43 UTC
I also looked at the google-api-core test, removed the comments, to check grpcio.
--------------------------- Out --------------------------------------------
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
===================================== short test summary info =====================================
SKIPPED [1] tests/unit/test_exceptions.py:159: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:171: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:183: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:198: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:206: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:224: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:240: No grpc
SKIPPED [1] tests/unit/test_exceptions.py:346: gRPC not importable
SKIPPED [1] tests/unit/test_exceptions.py:375: gRPC not importable
SKIPPED [1] tests/unit/test_grpc_helpers.py:796: grpc_gcp module not available
========================== 966 passed, 10 skipped, 10 warnings in 21.42s ==========================
>>> Completed testing dev-python/google-api-core-2.19.2-r1
----------------------------------------------------------------------------

These errors are not related to grpcio, they indicate missing package:
grpc_status

The lack of grpc_gcp is not entirely clear, as it is used in the call to the google-api-core package. 
This output does not mean that the grpcio package in Gentoo is broken. First, you need to add the grpcio_status package, and then look at the output. Everything here suggests that grpcio is working.
Comment 20 Roman 2024-10-04 20:03:27 UTC
As I said, I added the grpcio-status ebuild and the output became much better.
grpcio-status-1.66.2.ebuild:
------------------
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{11..13} )
DISTUTILS_USE_PEP517=setuptools
inherit distutils-r1 multiprocessing prefix pypi

DESCRIPTION="Reference package for GRPC Python status proto mapping"
HOMEPAGE="https://grpc.io"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64 arm arm64 x86"

RDEPEND="
        dev-python/protobuf-python[${PYTHON_USEDEP}]
        dev-python/grpcio[${PYTHON_USEDEP}]
        dev-python/googleapis-common-protos[${PYTHON_USEDEP}]
"
----------------------

--------out google-api-core test ----------------------------
===================================== short test summary info =====================================
SKIPPED [1] tests/unit/test_grpc_helpers.py:796: grpc_gcp module not available
================================= 975 passed, 1 skipped in 22.16s =================================
-------------------------------------------------------------

As I already said, all test errors were not related to the grpcio package and it works fine. It turns out that there was no point in removing the grpcio package from google-api-core, since the test errors were not related to it. The reason was completely different.
Comment 21 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-05 03:48:50 UTC
The package had no tests at the time.  If you were successful, please submit a pull request with the new packages and I'll review them.
Comment 22 Roman 2024-10-05 04:36:38 UTC
Everything went well except this test:
---------------
SKIPPED [1] tests/unit/test_grpc_helpers.py:796: grpc_gcp module not availabl
---------------
As far as I understand, this module does not work, even if you install it via pip. It seems that it is very outdated, so this test can be ignored in ebuild. This error is not related to grpcio, it seems the grpc_gcp module is deprecated and has been removed from the grpc project.
With these changes and the grpcio package installed, the test in dev-python/google-api-core now completes fine.
-----
EPYTEST_IGNORE=(
        tests/unit/test_grpc_helpers.py
)
-----

Also for the dev-python/google-api-core-2.20.0-r1 ebuild, this line should be like this:
>=dev-python/google-auth-2.35.0[${PYTHON_USEDEP}]
Comment 23 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-05 05:02:42 UTC
Skipped tests are fine.  You don't have to add extra packages just to avoid having them skipped.
Comment 24 Roman 2024-10-05 05:13:12 UTC
Only for Gentoo I have never added PR, so I don't know how the check goes. As far as I understand, changes can be added here: https://github.com/gentoo/gentoo
Of course, this is done through a fork.
Comment 25 Roman 2024-10-05 05:22:24 UTC
And here is where I found grpc_gcp, it hasn't been updated for 5 years: https://github.com/GoogleCloudPlatform/grpc-gcp-python
Comment 26 Roman 2024-10-05 11:17:04 UTC
Created: https://github.com/gentoo/gentoo/pull/38884
You can check it. I fixed some errors there for pkgcheck.
Comment 27 Larry the Git Cow gentoo-dev 2024-10-23 15:02:03 UTC
The bug has been closed via the following commit(s):

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

commit 4b92f1d79fc37c655677c6947e188154e9e14463
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2024-10-23 14:58:06 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2024-10-23 15:01:48 +0000

    dev-python/google-api-core: Add optional gRPC dependencies
    
    Closes: https://bugs.gentoo.org/940642
    Co-authored-by: Roman Popov <roma251078@mail.ru>
    Signed-off-by: Roman Popov <roma251078@mail.ru>
    Closes: https://github.com/gentoo/gentoo/pull/38884
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 .../google-api-core-2.21.0-r1.ebuild               | 63 ++++++++++++++++++++++
 dev-python/google-api-core/metadata.xml            |  6 +++
 2 files changed, 69 insertions(+)