From f5c113e51a216b93507f27f8576932fa77927a36 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 15 Mar 2025 16:20:19 -0400 Subject: [PATCH 1/5] feat: add pyinstaller hook --- .github/workflows/ci.yml | 17 +++++++++++++++++ pyproject.toml | 7 +++++++ src/cmap/__pyinstaller/__init__.py | 11 +++++++++++ src/cmap/__pyinstaller/hook-cmap.py | 22 ++++++++++++++++++++++ src/cmap/__pyinstaller/test_cmap.py | 9 +++++++++ src/cmap/_color.py | 5 ----- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 src/cmap/__pyinstaller/__init__.py create mode 100644 src/cmap/__pyinstaller/hook-cmap.py create mode 100644 src/cmap/__pyinstaller/test_cmap.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de6ad2fde..fb1adddaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,23 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} + test-pyinstaller-build: + name: Test pyinstaller + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Install package and dev dependencies + run: | + python -m pip install --upgrade pip + pip install . + pip install pytest pyinstaller + - name: Unit tests + run: pytest -v --pyargs pygfx.__pyinstaller + deploy: name: Deploy needs: test diff --git a/pyproject.toml b/pyproject.toml index 1d41029f0..0b231908d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,6 +75,10 @@ dev = [ "pyqt6", ] +[project.entry-points."pyinstaller40"] +hook-dirs = "cmap.__pyinstaller:get_hook_dirs" +tests = "cmap.__pyinstaller:get_test_dirs" + [project.urls] Homepage = "https://github.com/pyapp-kit/cmap" Repository = "https://github.com/pyapp-kit/cmap" @@ -139,6 +143,9 @@ filterwarnings = [ "ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning", "ignore::DeprecationWarning:docstring_parser", "ignore:Pyarrow will become a required dependency of pandas", + "ignore::DeprecationWarning:Pyinstaller", + "ignore::DeprecationWarning:pkg_resources", + "ignore::DeprecationWarning:altgraph", ] # https://mypy.readthedocs.io/en/stable/config_file.html diff --git a/src/cmap/__pyinstaller/__init__.py b/src/cmap/__pyinstaller/__init__.py new file mode 100644 index 000000000..cb647dbc1 --- /dev/null +++ b/src/cmap/__pyinstaller/__init__.py @@ -0,0 +1,11 @@ +from os.path import dirname + +HERE = dirname(__file__) + + +def get_hook_dirs() -> list[str]: + return [HERE] + + +def get_test_dirs() -> list[str]: + return [HERE] diff --git a/src/cmap/__pyinstaller/hook-cmap.py b/src/cmap/__pyinstaller/hook-cmap.py new file mode 100644 index 000000000..805d7287a --- /dev/null +++ b/src/cmap/__pyinstaller/hook-cmap.py @@ -0,0 +1,22 @@ +from PyInstaller.utils.hooks import collect_all + +datas, binaries, hiddenimports = collect_all( + "cmap", + include_datas=["data/"], + exclude_datas=["**/__pycache__/"], + filter_submodules=lambda x: x.startswith("cmap.data"), +) +excludedimports = [ + "bokeh", + "colorspacious", + "matplotlib", + "napari", + "numpy.typing", + "pydantic_core", + "pydantic", + "pygfx", + "pyqtgraph", + "typing_extensions", + "viscm", + "vispy", +] diff --git a/src/cmap/__pyinstaller/test_cmap.py b/src/cmap/__pyinstaller/test_cmap.py new file mode 100644 index 000000000..751ca29fc --- /dev/null +++ b/src/cmap/__pyinstaller/test_cmap.py @@ -0,0 +1,9 @@ +from typing import Any + + +def test_pyi_cmap_data(pyi_builder: Any) -> None: + pyi_builder.test_source(""" + import cmap + assert isisnstance(cmap.Colormap('viridis'), cmap.Colormap) + assert isisnstance(cmap.Colormap('crameri:acton'), cmap.Colormap) + """) diff --git a/src/cmap/_color.py b/src/cmap/_color.py index 1c69e5e44..db57f085d 100644 --- a/src/cmap/_color.py +++ b/src/cmap/_color.py @@ -21,11 +21,6 @@ import numpy as np -try: - from pydantic import model_serializer -except ImportError: - model_serializer = lambda x: x # noqa: E731 - from . import _external if TYPE_CHECKING: From 519d88ac2094ffc9902d444c1bd11f789ef9d852 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 15 Mar 2025 16:21:00 -0400 Subject: [PATCH 2/5] fix test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb1adddaf..a6463b7ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: pip install . pip install pytest pyinstaller - name: Unit tests - run: pytest -v --pyargs pygfx.__pyinstaller + run: pytest -v --pyargs cmap.__pyinstaller deploy: name: Deploy From f3e5ad3e24411f3922f4e7216928191ff09a5a59 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 15 Mar 2025 16:23:27 -0400 Subject: [PATCH 3/5] retain import --- src/cmap/__pyinstaller/test_cmap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmap/__pyinstaller/test_cmap.py b/src/cmap/__pyinstaller/test_cmap.py index 751ca29fc..cdf5e9df3 100644 --- a/src/cmap/__pyinstaller/test_cmap.py +++ b/src/cmap/__pyinstaller/test_cmap.py @@ -1,3 +1,4 @@ +from PyInstaller.utils.conftest import * # noqa from typing import Any From 582efbe829c47a5703fba0b9fdb3fe675051c12b Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 15 Mar 2025 16:30:12 -0400 Subject: [PATCH 4/5] fix tests --- src/cmap/__pyinstaller/hook-cmap.py | 6 ++++-- src/cmap/__pyinstaller/test_cmap.py | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmap/__pyinstaller/hook-cmap.py b/src/cmap/__pyinstaller/hook-cmap.py index 805d7287a..6d444a662 100644 --- a/src/cmap/__pyinstaller/hook-cmap.py +++ b/src/cmap/__pyinstaller/hook-cmap.py @@ -2,9 +2,9 @@ datas, binaries, hiddenimports = collect_all( "cmap", - include_datas=["data/"], + # include_datas=["data/"], exclude_datas=["**/__pycache__/"], - filter_submodules=lambda x: x.startswith("cmap.data"), + # filter_submodules=lambda x: x.startswith("cmap.data"), ) excludedimports = [ "bokeh", @@ -14,8 +14,10 @@ "numpy.typing", "pydantic_core", "pydantic", + "numba", "pygfx", "pyqtgraph", + "tkinter", "typing_extensions", "viscm", "vispy", diff --git a/src/cmap/__pyinstaller/test_cmap.py b/src/cmap/__pyinstaller/test_cmap.py index cdf5e9df3..17020c926 100644 --- a/src/cmap/__pyinstaller/test_cmap.py +++ b/src/cmap/__pyinstaller/test_cmap.py @@ -1,10 +1,10 @@ -from PyInstaller.utils.conftest import * # noqa +from PyInstaller.utils.conftest import pyi_builder, pyi_modgraph # noqa from typing import Any -def test_pyi_cmap_data(pyi_builder: Any) -> None: +def test_pyi_cmap_data(pyi_builder: Any) -> None: # noqa: F811 pyi_builder.test_source(""" import cmap - assert isisnstance(cmap.Colormap('viridis'), cmap.Colormap) - assert isisnstance(cmap.Colormap('crameri:acton'), cmap.Colormap) + assert isinstance(cmap.Colormap('viridis'), cmap.Colormap) + assert isinstance(cmap.Colormap('crameri:acton'), cmap.Colormap) """) From ff861558824b4cf1e79b82ba1747556233fa8124 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 15 Mar 2025 16:49:42 -0400 Subject: [PATCH 5/5] try fix test --- src/cmap/__pyinstaller/conftest.py | 4 ++++ src/cmap/__pyinstaller/test_cmap.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 src/cmap/__pyinstaller/conftest.py diff --git a/src/cmap/__pyinstaller/conftest.py b/src/cmap/__pyinstaller/conftest.py new file mode 100644 index 000000000..67f89ed8a --- /dev/null +++ b/src/cmap/__pyinstaller/conftest.py @@ -0,0 +1,4 @@ +import os + +os.environ["PYI_BUILDER_CLEANUP"] = "0" +from PyInstaller.utils.conftest import * # noqa diff --git a/src/cmap/__pyinstaller/test_cmap.py b/src/cmap/__pyinstaller/test_cmap.py index 17020c926..1419086b2 100644 --- a/src/cmap/__pyinstaller/test_cmap.py +++ b/src/cmap/__pyinstaller/test_cmap.py @@ -1,8 +1,7 @@ -from PyInstaller.utils.conftest import pyi_builder, pyi_modgraph # noqa from typing import Any -def test_pyi_cmap_data(pyi_builder: Any) -> None: # noqa: F811 +def test_pyi_cmap_data(pyi_builder: Any) -> None: pyi_builder.test_source(""" import cmap assert isinstance(cmap.Colormap('viridis'), cmap.Colormap)