Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hooks: add hook for googleapiclient.model #82

Merged
merged 4 commits into from
Jan 2, 2021

Conversation

rokm
Copy link
Member

@rokm rokm commented Jan 2, 2021

The googleapiclient.model module uses pkg_resources and its get_distribution() function to query the version of google-api-python-client package, therefore we need to collect its metadata.

Fixes pyinstaller/pyinstaller#5332.
Fixes #14.

Reproduces the error from pyinstaller/pyinstaller#5332 and pyinstaller#14,
which is caused by missing metadata.
The googleapiclient.model module uses pkg_resources and its
get_distribution() function to query the version of
"google-api-python-client" package, therefore we need to collect
its metadata.

Fixes pyinstaller/pyinstaller#5332.
Fixes pyinstaller#14.
@rokm rokm requested review from a team and bwoodsend and removed request for a team January 2, 2021 15:54
@rokm
Copy link
Member Author

rokm commented Jan 2, 2021

@bwoodsend bwoodsend merged commit a76e3ca into pyinstaller:master Jan 2, 2021
@sirdeniel
Copy link
Contributor

Hi, I really appreciate this hook. I'm using Blogger API on my project but raises error due to NoneType when calling build().
Example code is:

from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

CLIENT_CONFIG = {
    "installed": {
        "client_id": "xxxxx-xxxxxxx.apps.googleusercontent.com",
        "project_id": "xxxxxxxxx",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "xxxxxxxxxxxxxxxx",
        "redirect_uris": [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
}
SCOPES = ['https://www.googleapis.com/auth/blogger']
try:
    flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES) # this opens default browser to login
    auth_credentials = flow.run_local_server(success_message="You can close this window now") # if not accepted... what happens?
    blogger_service = build('blogger', 'v3', credentials=auth_credentials) # here happens the error
except Exception as e:
    print("Some error happened")
    print(e) # prints -> name: blogger version: v3

Looking at the code for the build() method, it happens there is a None value returned and it's only on the Pyinstaller project.
After some clues on SO and my own findings, these two lines are needed

# adding googleapiclient.discovery correctly
from PyInstaller.utils.hooks import collect_data_files
datas += collect_data_files('googleapiclient.discovery', include_py_files=True, excludes=['*.txt', '**/__pycache__'])

Now it works as I needed for blogger, I guess it'll work for other services than Blogger. Hope this helps.
I'm thinking to make a PR but I'm a noob on this stuff.

@bwoodsend
Copy link
Member

Eek @Legorooj we haven't done a release since Novermber...

@rokm rokm deleted the hooks-googleapiclient branch March 11, 2021 09:51
@Legorooj
Copy link
Member

Actually I manually released it a day or 2 ago. Forgot to tag it in the repo though 😬.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg_resources.DistributionNotFound: Error after creating build
4 participants