Skip to content

Commit cbe7c28

Browse files
pmrowlaefiop
authored andcommitted
pyinstaller: add package hooks
1 parent 6117cac commit cbe7c28

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

pydrive2/__pyinstaller/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
4+
def get_hook_dirs():
5+
return [os.path.dirname(__file__)]
6+
7+
8+
def get_PyInstaller_tests():
9+
return [os.path.dirname(__file__)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from PyInstaller.utils.hooks import ( # pylint: disable=import-error
2+
copy_metadata,
3+
collect_data_files,
4+
)
5+
6+
datas = copy_metadata("google-api-python-client")
7+
datas += collect_data_files(
8+
"googleapiclient", excludes=["*.txt", "**/__pycache__"]
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import subprocess
2+
3+
from PyInstaller import __main__ as pyi_main
4+
5+
6+
_APP_SOURCE = """import importlib.resources
7+
8+
import pydrive2.files
9+
10+
11+
cache_files = importlib.resources.contents(
12+
"googleapiclient.discovery_cache.documents"
13+
)
14+
assert len(cache_files) > 0
15+
"""
16+
17+
18+
def test_pyi_hook_google_api_client(tmp_path):
19+
app_name = "userapp"
20+
workpath = tmp_path / "build"
21+
distpath = tmp_path / "dist"
22+
app = tmp_path / f"{app_name}.py"
23+
app.write_text(_APP_SOURCE)
24+
pyi_main.run(
25+
[
26+
"--workpath",
27+
str(workpath),
28+
"--distpath",
29+
str(distpath),
30+
"--specpath",
31+
str(tmp_path),
32+
str(app),
33+
],
34+
)
35+
subprocess.run([str(distpath / app_name / app_name)], check=True)

setup.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"flake8",
99
"flake8-docstrings",
1010
"pytest-mock",
11+
"pyinstaller",
1112
]
1213

1314
tests_requirements.append("black==22.10.0")
@@ -18,7 +19,12 @@
1819
author_email="[email protected]",
1920
maintainer="DVC team",
2021
maintainer_email="[email protected]",
21-
packages=["pydrive2", "pydrive2.test", "pydrive2.fs"],
22+
packages=[
23+
"pydrive2",
24+
"pydrive2.test",
25+
"pydrive2.fs",
26+
"pydrive2.__pyinstaller",
27+
],
2228
url="https://github.com/iterative/PyDrive2",
2329
project_urls={
2430
"Documentation": "https://docs.iterative.ai/PyDrive2",
@@ -52,4 +58,10 @@
5258
"Programming Language :: Python :: 3.9",
5359
"Programming Language :: Python :: 3.10",
5460
],
61+
entry_points={
62+
"pyinstaller40": [
63+
"hook-dirs = pydrive2.__pyinstaller:get_hook_dirs",
64+
"tests = pydrive2.__pyinstaller:get_PyInstaller_tests",
65+
]
66+
},
5567
)

0 commit comments

Comments
 (0)