From b8c741dbe83d0b783dac09c7621dcb27963eccfe Mon Sep 17 00:00:00 2001 From: ArthurKlausHoff <57872111+ArthurKlausHoff@users.noreply.github.com> Date: Mon, 12 Jun 2023 16:34:07 -0300 Subject: [PATCH] hooks: Fix googleapiclient.model missing docs and improve test (#596) The hook googleapiclient.model was raising this warning when running Pyinstaller: WARNING: collect_data_files - skipping data collection for module 'googleapiclient.discovery' as it is not a package. Needing workarounds to run the api client, see googleapis/google-api-python-client#876. But this can be fixed by pointing it to the correct package googleapiclient.discovery_cache. The test also received an improvement. The current test only run from googleapiclient.discovery import build which is not sufficient because the error happens when calling the build function. Calling this function doesn't require a valid API key. --- news/596.update.rst | 1 + requirements-test-libraries.txt | 1 + .../hooks/stdhooks/hook-googleapiclient.model.py | 2 +- .../tests/test_libraries.py | 15 +++++++++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 news/596.update.rst diff --git a/news/596.update.rst b/news/596.update.rst new file mode 100644 index 00000000..6eb7d514 --- /dev/null +++ b/news/596.update.rst @@ -0,0 +1 @@ +Update hook for ``googleapiclient.model``, fixing missing discovery docs and improving test. diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index 3db27535..b6965d83 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -33,6 +33,7 @@ fiona==1.9.4.post1; sys_platform != 'win32' folium==0.14.0 ffpyplayer==4.5.0 geopandas==0.13.1; python_version >= '3.8' and sys_platform != 'win32' +google-api-python-client==2.88.0; python_version >= '3.7' graphql-query==1.1.1 python-gitlab==3.14.0 h5py==3.8.0; python_version >= '3.7' diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py index e147790a..ce03a697 100644 --- a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py @@ -17,4 +17,4 @@ # pkg_resources.get_distribution("google-api-python-client").version, # so we need to collect that package's metadata datas = copy_metadata('google_api_python_client') -datas += collect_data_files('googleapiclient.discovery', excludes=['*.txt', '**/__pycache__']) +datas += collect_data_files('googleapiclient.discovery_cache', excludes=['*.txt', '**/__pycache__']) diff --git a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py index f1b06f1d..61a34ced 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -605,10 +605,21 @@ def test_torchvision_nms(pyi_builder): """) -@importorskip('googleapiclient') +@requires('google-api-python-client >= 2.0.0') def test_googleapiclient(pyi_builder): pyi_builder.test_source(""" - from googleapiclient.discovery import build + from googleapiclient import discovery, discovery_cache + + API_NAME = "youtube" + API_VERSION = "v3" + + for file in os.listdir(discovery_cache.DISCOVERY_DOC_DIR): # Always up to date + if file.startswith("youtube.v") and file.endswith(".json"): + API_NAME, API_VERSION = file.split(".")[:2] + break + + # developerKey can be any non-empty string + yt = discovery.build(API_NAME, API_VERSION, developerKey=":)", static_discovery=True) """)