From 07d1f3ada3e16c66f171f34d1ada71820f5155b2 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 24 Oct 2022 19:49:52 +0200 Subject: [PATCH] fix packaging with pyinstaller --- .github/workflows/branchbuild.yml | 6 +++- CHANGELOG.md | 4 ++- pyproject.toml | 1 - setup.py | 8 ++++- src/rapidfuzz/__pyinstaller/__init__.py | 9 +++++ src/rapidfuzz/__pyinstaller/hook-rapidfuzz.py | 33 ++++++++++++++++++ .../__pyinstaller/test_rapidfuzz_packaging.py | 34 +++++++++++++++++++ 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/rapidfuzz/__pyinstaller/__init__.py create mode 100644 src/rapidfuzz/__pyinstaller/hook-rapidfuzz.py create mode 100644 src/rapidfuzz/__pyinstaller/test_rapidfuzz_packaging.py diff --git a/.github/workflows/branchbuild.yml b/.github/workflows/branchbuild.yml index 4431752..d96b970 100644 --- a/.github/workflows/branchbuild.yml +++ b/.github/workflows/branchbuild.yml @@ -108,7 +108,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest hypothesis pandas mypy + pip install pytest hypothesis pandas mypy pyinstaller[hook_testing] - name: build run: | @@ -126,3 +126,7 @@ jobs: if: runner.os != 'Linux' run: | pytest tests + + - name: test pyinstaller packaging + run: | + python -m PyInstaller.utils.run_tests --include_only rapidfuzz. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce8a04..006956c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ ## Changelog -### [2.12.0] - 2022-10-22 +### [2.12.0] - 2022-10-24 #### Changed - drop support for Python 3.6 #### Added - added `Prefix`/`Suffix` similarity +#### Fixed +- fixed packaging with pyinstaller ### [2.11.1] - 2022-10-05 #### Fixed diff --git a/pyproject.toml b/pyproject.toml index d2571a6..0971c44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ warn_unreachable = true minversion = "6.0" addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] xfail_strict = true -filterwarnings = ["error"] log_cli_level = "info" testpaths = ["tests"] diff --git a/setup.py b/setup.py index 8c9f9ba..0ca672c 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,13 @@ setup_args = { "Programming Language :: Python :: 3.11", "License :: OSI Approved :: MIT License", ], - "packages": ["rapidfuzz", "rapidfuzz.distance"], + "packages": ["rapidfuzz", "rapidfuzz.distance", "rapidfuzz.__pyinstaller"], + "entry_points": { + "pyinstaller40": [ + "hook-dirs = rapidfuzz.__pyinstaller:get_hook_dirs", + "tests = rapidfuzz.__pyinstaller:get_PyInstaller_tests", + ], + }, "package_dir": { "": "src", }, diff --git a/src/rapidfuzz/__pyinstaller/__init__.py b/src/rapidfuzz/__pyinstaller/__init__.py new file mode 100644 index 0000000..205b085 --- /dev/null +++ b/src/rapidfuzz/__pyinstaller/__init__.py @@ -0,0 +1,9 @@ +import os + + +def get_hook_dirs(): + return [os.path.dirname(__file__)] + + +def get_PyInstaller_tests(): + return [os.path.dirname(__file__)] diff --git a/src/rapidfuzz/__pyinstaller/hook-rapidfuzz.py b/src/rapidfuzz/__pyinstaller/hook-rapidfuzz.py new file mode 100644 index 0000000..ecc7821 --- /dev/null +++ b/src/rapidfuzz/__pyinstaller/hook-rapidfuzz.py @@ -0,0 +1,33 @@ +# Pyinstaller hook to successfully freeze: https://pyinstaller.readthedocs.io/en/stable/hooks.html +hiddenimports = [ + "array.array", + "rapidfuzz.fuzz_py", + "rapidfuzz.fuzz_cpp", + "rapidfuzz.utils_py", + "rapidfuzz.utils_cpp", + "rapidfuzz.process_py", + "rapidfuzz.process_cpp", + # distances + "rapidfuzz.distance._initialize_py", + "rapidfuzz.distance._initialize_cpp", + "rapidfuzz.distance.DamerauLevenshtein_py", + "rapidfuzz.distance.DamerauLevenshtein_cpp", + "rapidfuzz.distance.Hamming_py", + "rapidfuzz.distance.Hamming_cpp", + "rapidfuzz.distance.Indel_py", + "rapidfuzz.distance.Indel_cpp", + "rapidfuzz.distance.Jaro_py", + "rapidfuzz.distance.Jaro_cpp", + "rapidfuzz.distance.JaroWinkler_py", + "rapidfuzz.distance.JaroWinkler_cpp", + "rapidfuzz.distance.LCSseq_py", + "rapidfuzz.distance.LCSseq_cpp", + "rapidfuzz.distance.Levenshtein_py", + "rapidfuzz.distance.Levenshtein_cpp", + "rapidfuzz.distance.OSA_py", + "rapidfuzz.distance.OSA_cpp", + "rapidfuzz.distance.Prefix_py", + "rapidfuzz.distance.Prefix_cpp", + "rapidfuzz.distance.Postfix_py", + "rapidfuzz.distance.Postfix_cpp", +] diff --git a/src/rapidfuzz/__pyinstaller/test_rapidfuzz_packaging.py b/src/rapidfuzz/__pyinstaller/test_rapidfuzz_packaging.py new file mode 100644 index 0000000..859e41e --- /dev/null +++ b/src/rapidfuzz/__pyinstaller/test_rapidfuzz_packaging.py @@ -0,0 +1,34 @@ +import subprocess + +from PyInstaller import __main__ as pyi_main + +# Test out the package by importing it, then running functions from it. +def test_pyi_hooksample(tmp_path): + app_name = "userapp" + workpath = tmp_path / "build" + distpath = tmp_path / "dist" + app = tmp_path / (app_name + ".py") + app.write_text( + "\n".join( + [ + "import rapidfuzz", + "from rapidfuzz.distance import Levenshtein_py", + "from rapidfuzz.distance import Levenshtein_cpp", + "rapidfuzz.distance.Levenshtein.distance('test', 'teste')", + "Levenshtein_py.distance('test', 'teste')", + "Levenshtein_cpp.distance('test', 'teste')", + ] + ) + ) + args = [ + # Place all generated files in ``tmp_path``. + "--workpath", + str(workpath), + "--distpath", + str(distpath), + "--specpath", + str(tmp_path), + str(app), + ] + pyi_main.run(args) + subprocess.run([str(distpath / app_name / app_name)], check=True)