Skip to content

Commit b8c741d

Browse files
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.
1 parent 7ccda99 commit b8c741d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

news/596.update.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update hook for ``googleapiclient.model``, fixing missing discovery docs and improving test.

requirements-test-libraries.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fiona==1.9.4.post1; sys_platform != 'win32'
3333
folium==0.14.0
3434
ffpyplayer==4.5.0
3535
geopandas==0.13.1; python_version >= '3.8' and sys_platform != 'win32'
36+
google-api-python-client==2.88.0; python_version >= '3.7'
3637
graphql-query==1.1.1
3738
python-gitlab==3.14.0
3839
h5py==3.8.0; python_version >= '3.7'

src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-googleapiclient.model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
# pkg_resources.get_distribution("google-api-python-client").version,
1818
# so we need to collect that package's metadata
1919
datas = copy_metadata('google_api_python_client')
20-
datas += collect_data_files('googleapiclient.discovery', excludes=['*.txt', '**/__pycache__'])
20+
datas += collect_data_files('googleapiclient.discovery_cache', excludes=['*.txt', '**/__pycache__'])

src/_pyinstaller_hooks_contrib/tests/test_libraries.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,21 @@ def test_torchvision_nms(pyi_builder):
605605
""")
606606

607607

608-
@importorskip('googleapiclient')
608+
@requires('google-api-python-client >= 2.0.0')
609609
def test_googleapiclient(pyi_builder):
610610
pyi_builder.test_source("""
611-
from googleapiclient.discovery import build
611+
from googleapiclient import discovery, discovery_cache
612+
613+
API_NAME = "youtube"
614+
API_VERSION = "v3"
615+
616+
for file in os.listdir(discovery_cache.DISCOVERY_DOC_DIR): # Always up to date
617+
if file.startswith("youtube.v") and file.endswith(".json"):
618+
API_NAME, API_VERSION = file.split(".")[:2]
619+
break
620+
621+
# developerKey can be any non-empty string
622+
yt = discovery.build(API_NAME, API_VERSION, developerKey=":)", static_discovery=True)
612623
""")
613624

614625

0 commit comments

Comments
 (0)