Skip to content

pyinstaller: add package hooks #243

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

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ repos:
- hooks:
- id: flake8
language_version: python3
repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
repo: https://github.com/PyCQA/flake8
rev: 5.0.4
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously unrelated to pyinstaller, but we should be using the github repo for flake8 (the old gitlab URL now requires auth and breaks pre-commit in CI)

9 changes: 9 additions & 0 deletions pydrive2/__pyinstaller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os


def get_hook_dirs():
return [os.path.dirname(__file__)]


def get_PyInstaller_tests():
return [os.path.dirname(__file__)]
9 changes: 9 additions & 0 deletions pydrive2/__pyinstaller/hook-googleapiclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from PyInstaller.utils.hooks import ( # pylint: disable=import-error
copy_metadata,
collect_data_files,
)

datas = copy_metadata("google-api-python-client")
datas += collect_data_files(
"googleapiclient", excludes=["*.txt", "**/__pycache__"]
)
35 changes: 35 additions & 0 deletions pydrive2/__pyinstaller/test_hook-googleapiclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess

from PyInstaller import __main__ as pyi_main


_APP_SOURCE = """import importlib.resources

import pydrive2.files


cache_files = importlib.resources.contents(
"googleapiclient.discovery_cache.documents"
)
assert len(cache_files) > 0
"""


def test_pyi_hook_google_api_client(tmp_path):
app_name = "userapp"
workpath = tmp_path / "build"
distpath = tmp_path / "dist"
app = tmp_path / f"{app_name}.py"
app.write_text(_APP_SOURCE)
pyi_main.run(
[
"--workpath",
str(workpath),
"--distpath",
str(distpath),
"--specpath",
str(tmp_path),
str(app),
],
)
subprocess.run([str(distpath / app_name / app_name)], check=True)
14 changes: 13 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"flake8",
"flake8-docstrings",
"pytest-mock",
"pyinstaller",
]

tests_requirements.append("black==22.10.0")
Expand All @@ -18,7 +19,12 @@
author_email="jgwak@dreamylab.com",
maintainer="DVC team",
maintainer_email="support@dvc.org",
packages=["pydrive2", "pydrive2.test", "pydrive2.fs"],
packages=[
"pydrive2",
"pydrive2.test",
"pydrive2.fs",
"pydrive2.__pyinstaller",
],
url="https://github.com/iterative/PyDrive2",
project_urls={
"Documentation": "https://docs.iterative.ai/PyDrive2",
Expand Down Expand Up @@ -52,4 +58,10 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
entry_points={
"pyinstaller40": [
"hook-dirs = pydrive2.__pyinstaller:get_hook_dirs",
"tests = pydrive2.__pyinstaller:get_PyInstaller_tests",
]
},
)