Skip to content

Commit bb1ea25

Browse files
authored
feat: add pyinstaller hook (#95)
* feat: add pyinstaller hook * fix test * retain import * fix tests * try fix test
1 parent 21c8fc5 commit bb1ea25

File tree

7 files changed

+72
-5
lines changed

7 files changed

+72
-5
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ jobs:
7474
with:
7575
token: ${{ secrets.CODECOV_TOKEN }}
7676

77+
test-pyinstaller-build:
78+
name: Test pyinstaller
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v4
82+
- name: Set up Python
83+
uses: actions/setup-python@v5
84+
with:
85+
python-version: 3.12
86+
- name: Install package and dev dependencies
87+
run: |
88+
python -m pip install --upgrade pip
89+
pip install .
90+
pip install pytest pyinstaller
91+
- name: Unit tests
92+
run: pytest -v --pyargs cmap.__pyinstaller
93+
7794
deploy:
7895
name: Deploy
7996
needs: test

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ dev = [
7575
"pyqt6",
7676
]
7777

78+
[project.entry-points."pyinstaller40"]
79+
hook-dirs = "cmap.__pyinstaller:get_hook_dirs"
80+
tests = "cmap.__pyinstaller:get_test_dirs"
81+
7882
[project.urls]
7983
Homepage = "https://github.com/pyapp-kit/cmap"
8084
Repository = "https://github.com/pyapp-kit/cmap"
@@ -139,6 +143,9 @@ filterwarnings = [
139143
"ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning",
140144
"ignore::DeprecationWarning:docstring_parser",
141145
"ignore:Pyarrow will become a required dependency of pandas",
146+
"ignore::DeprecationWarning:Pyinstaller",
147+
"ignore::DeprecationWarning:pkg_resources",
148+
"ignore::DeprecationWarning:altgraph",
142149
]
143150

144151
# https://mypy.readthedocs.io/en/stable/config_file.html

src/cmap/__pyinstaller/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from os.path import dirname
2+
3+
HERE = dirname(__file__)
4+
5+
6+
def get_hook_dirs() -> list[str]:
7+
return [HERE]
8+
9+
10+
def get_test_dirs() -> list[str]:
11+
return [HERE]

src/cmap/__pyinstaller/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
os.environ["PYI_BUILDER_CLEANUP"] = "0"
4+
from PyInstaller.utils.conftest import * # noqa

src/cmap/__pyinstaller/hook-cmap.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from PyInstaller.utils.hooks import collect_all
2+
3+
datas, binaries, hiddenimports = collect_all(
4+
"cmap",
5+
# include_datas=["data/"],
6+
exclude_datas=["**/__pycache__/"],
7+
# filter_submodules=lambda x: x.startswith("cmap.data"),
8+
)
9+
excludedimports = [
10+
"bokeh",
11+
"colorspacious",
12+
"matplotlib",
13+
"napari",
14+
"numpy.typing",
15+
"pydantic_core",
16+
"pydantic",
17+
"numba",
18+
"pygfx",
19+
"pyqtgraph",
20+
"tkinter",
21+
"typing_extensions",
22+
"viscm",
23+
"vispy",
24+
]

src/cmap/__pyinstaller/test_cmap.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Any
2+
3+
4+
def test_pyi_cmap_data(pyi_builder: Any) -> None:
5+
pyi_builder.test_source("""
6+
import cmap
7+
assert isinstance(cmap.Colormap('viridis'), cmap.Colormap)
8+
assert isinstance(cmap.Colormap('crameri:acton'), cmap.Colormap)
9+
""")

src/cmap/_color.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121

2222
import numpy as np
2323

24-
try:
25-
from pydantic import model_serializer
26-
except ImportError:
27-
model_serializer = lambda x: x # noqa: E731
28-
2924
from . import _external
3025

3126
if TYPE_CHECKING:

0 commit comments

Comments
 (0)